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