mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Decouple ofn-empties-cart directive from hub-choice navigation
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
Darkswarm.directive "ofnEmptiesCart", (CurrentHub, Cart, Navigation, storage) ->
|
||||
Darkswarm.directive "ofnEmptiesCart", (CurrentHub, Cart, storage) ->
|
||||
# Compares scope.hub with CurrentHub. Will trigger an confirmation if they are different,
|
||||
# and Cart isn't empty
|
||||
restrict: "A"
|
||||
scope:
|
||||
hub: "=ofnEmptiesCart"
|
||||
link: (scope, elm, attr)->
|
||||
if CurrentHub.hub?.id and CurrentHub.hub.id isnt scope.hub.id and !Cart.empty()
|
||||
link: (scope, elm, attr)->
|
||||
cart_will_need_emptying = ->
|
||||
CurrentHub.hub?.id and CurrentHub.hub.id isnt scope.hub.id and !Cart.empty()
|
||||
|
||||
clear_cart = ->
|
||||
storage.clearAll() # One day this will have to be moar GRANULAR
|
||||
|
||||
if cart_will_need_emptying()
|
||||
elm.bind 'click', (ev)->
|
||||
ev.preventDefault()
|
||||
if confirm "Are you sure? This will change your selected Hub and remove any items in your shopping cart."
|
||||
storage.clearAll() # One day this will have to be moar GRANULAR
|
||||
Navigation.go scope.hub.path
|
||||
if confirm "Are you sure? This will change your selected hub and remove any items in your shopping cart."
|
||||
clear_cart()
|
||||
else
|
||||
ev.preventDefault()
|
||||
|
||||
Reference in New Issue
Block a user