Starting a basic implementation of the Cart/CurrentOrder so we know whether it's empty

This commit is contained in:
Will Marshall
2014-05-30 15:52:20 +10:00
parent 7abfb2f936
commit 13c6ce6786
8 changed files with 33 additions and 14 deletions

View File

@@ -0,0 +1,2 @@
Darkswarm.controller "CartCtrl", ($scope, CurrentOrder) ->
$scope.CurrentOrder = CurrentOrder

View File

@@ -1,10 +1,11 @@
Darkswarm.directive "ofnEmptiesCart", (CurrentHub, Navigation) ->
Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation) ->
restrict: "A"
scope:
hub: '=ofnEmptiesCart'
template: "{{action}} <strong>{{hub.name}}</strong>"
link: (scope, elm, attr)->
if CurrentHub.id and CurrentHub.id isnt scope.hub.id
# A hub is selected, we're changing to a different hub, and the cart isn't empty
if CurrentHub.id and CurrentHub.id isnt scope.hub.id and not CurrentOrder.empty()
scope.action = attr.change
elm.bind 'click', (ev)->
ev.preventDefault()
@@ -12,5 +13,3 @@ Darkswarm.directive "ofnEmptiesCart", (CurrentHub, Navigation) ->
Navigation.go scope.hub.path
else
scope.action = attr.shop

View File

@@ -0,0 +1,7 @@
Darkswarm.factory 'CurrentOrder', (currentOrder) ->
new class CurrentOrder
constructor: ->
@[k] = v for k, v of currentOrder
empty: =>
@line_items.length == 0

View File

@@ -0,0 +1,13 @@
object current_order
attributes :id, :item_total
if current_order
child line_items: :line_items do
attributes :id, :variant_id, :quantity, :price
end
node :cart_count do
cart_count
end
end

View File

@@ -16,6 +16,7 @@
%body.off-canvas{"ng-app" => "Darkswarm"}
= inject_json "currentHub", "current_hub"
= inject_json "currentOrder", "current_order"
= inject_json "user", "current_user"
.off-canvas-wrap{offcanvas: true}

View File

@@ -0,0 +1,5 @@
%a.icon{href: cart_url, "ng-controller" => "CartCtrl"}
%i.fi-shopping-cart.nav-branded
%span
{{ CurrentOrder.cart_count }}
items

View File

@@ -43,8 +43,4 @@
%span.nav-primary.nav-branded {{ CurrentHub.name }}
%li.divider
%li.cart
%a.icon{href: cart_url}
%i.fi-shopping-cart.nav-branded
%span
= cart_count
items
= render partial: "shared/menu/cart"

View File

@@ -3,11 +3,7 @@
%a.left-off-canvas-toggle.menu-icon
%span
%section.right
%a.nav-branded.icon{href: cart_url}
%i.fi-shopping-cart
%span
= cart_count
items
= render partial: "shared/menu/cart"
%a{href: main_app.shop_path}
{{ CurrentHub.name }}