diff --git a/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee b/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee index 51e960867b..7ae1971db3 100644 --- a/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee @@ -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()