Prompt for clear cart when order cycle changes

This commit is contained in:
Rohan Mitchell
2015-07-30 15:04:43 +10:00
parent eb6dcba396
commit 679531fe2a
2 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
Darkswarm.directive "ofnChangeOrderCycle", (OrderCycle, Cart, storage) ->
# Compares chosen order cycle with pre-set OrderCycle. Will trigger
# a confirmation if they are different, and Cart isn't empty
restrict: "A"
scope: true
link: (scope, elm, attr)->
order_cycle_id = ->
parseInt elm.val()
cart_needs_emptying = ->
OrderCycle.order_cycle?.order_cycle_id && OrderCycle.order_cycle.order_cycle_id != order_cycle_id() && !Cart.empty()
elm.bind 'change', (ev)->
if cart_needs_emptying()
if confirm "Are you sure? This will change your selected order cycle and remove any items in your shopping cart."
Cart.clear()
scope.changeOrderCycle()
else
scope.changeOrderCycle()

View File

@@ -16,7 +16,7 @@
/ Will this label should be a variable to reflect 'Ready for pickup / delivery' as appropriate
%select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
"ng-change" => "changeOrderCycle()",
"ofn-change-order-cycle" => true,
"ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}",
"popover-placement" => "left", "popover" => "Choose when you want your order:", "popover-trigger" => "openTrigger"}