mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-24 01:13:21 +00:00
Starting a basic implementation of the Cart/CurrentOrder so we know whether it's empty
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
Darkswarm.controller "CartCtrl", ($scope, CurrentOrder) ->
|
||||
$scope.CurrentOrder = CurrentOrder
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Darkswarm.factory 'CurrentOrder', (currentOrder) ->
|
||||
new class CurrentOrder
|
||||
constructor: ->
|
||||
@[k] = v for k, v of currentOrder
|
||||
|
||||
empty: =>
|
||||
@line_items.length == 0
|
||||
Reference in New Issue
Block a user