diff --git a/packages/reaction-shipping/client/templates/shipping.coffee b/packages/reaction-shipping/client/templates/shipping.coffee index ec7f7f35309..7b3945076cc 100644 --- a/packages/reaction-shipping/client/templates/shipping.coffee +++ b/packages/reaction-shipping/client/templates/shipping.coffee @@ -1,62 +1,155 @@ +### +# Template shipping Helpers +### Template.shipping.helpers packageData: -> return ReactionCore.Collections.Packages.findOne({name:"reaction-shipping"}) + shipping: -> ReactionCore.Collections.Shipping.find() + # boolean to display addShippingProvider form + selectedShippingProvider: -> + return Session.equals "selectedShippingProvider", true + +### +# Template Shipping Events +### Template.shipping.events 'click': () -> Alerts.removeSeen() + # add new shipping provider + 'click .add-shipping-provider': (event, template) -> + console.log "click add-shipping-provider" + toggleSession "selectedShippingProvider" + +### +# template addShippingMethod Helpers +### Template.addShippingMethod.helpers # just get the current shipping table shipping: -> return ReactionCore.Collections.Shipping.find() -Template.shippingFlatRateTable.helpers +### +# template addShippingProvider events +### +Template.editShippingMethod.events + # add new shipping provider + 'click .cancel': (event, template) -> + console.log "cancel editShippingMethod" + toggleSession "selectedShippingMethod" + event.preventDefault() + +### +# template addShippingProvider events +### +Template.editShippingProvider.events + # add new shipping provider + 'click .cancel': (event, template) -> + console.log "cancel editShippingProvider" + toggleSession "selectedShippingProvider" + event.preventDefault() + +### +# template addShippingProvider events +### +Template.addShippingProvider.events + # add new shipping provider + 'click .cancel': (event, template) -> + console.log "cancel addShippingProvider" + toggleSession "selectedShippingProvider" + event.preventDefault() + +### +# template addShippingMethods events +### +Template.addShippingMethod.events + # add new shipping provider + 'click .cancel': (event, template) -> + console.log "cancel addShippingMethod" + toggleSession "selectedAddShippingMethod" + event.preventDefault() + +### +# Template shippingProviderTable Helpers +### +Template.shippingProviderTable.helpers # just get the current shipping table shipping: -> return ReactionCore.Collections.Shipping.find() + # toggle selected - selectedMethod: (item) -> + selectedShippingMethod: (item) -> session = Session.get "selectedShippingMethod" if _.isEqual @, session return @ + #toggle addShippingMethodForm - addShippingMethodMode: -> - if Session.equals "addShippingMethod", true - return true - else - return false + selectedAddShippingMethod: -> + session = Session.get "selectedAddShippingMethod" + if _.isEqual @, session + return @ + selectedShippingProvider: -> + session = Session.get "selectedShippingProvider" + if _.isEqual @, session + return @ -Template.shippingFlatRateTable.events - # toggle selected +### +# template shippingProviderTable events +### +Template.shippingProviderTable.events + # toggle selected method 'click .edit-shipping-method': (event, template) -> session = Session.get "selectedShippingMethod" if _.isEqual @, session - #toggleSession "selectedShippingMethod" Session.set "selectedShippingMethod", false else Session.set "selectedShippingMethod", @ + # toggle selected provider + 'click .edit-shipping-provider': (event, template) -> + # session = Session.get "selectedShippingProvider" + console.log "click edit-shipping-provider" + return toggleSession "selectedShippingProvider", @ + + # if _.isEqual @, session + # Session.set "selectedShippingProvider", false + # else + # toggleSessionObj "selectedShippingProvider", @ + # call method to delete shipping method 'click #delete-shipping-method': (event, template) -> - Meteor.call "removeShippingMethod", $(event.currentTarget).data('provider-id'), @ - Alerts.add "Shipping method deleted.", "success", autoHide: true, placement:"shippingPackage" + if confirm("Are you sure you want to delete "+ @.name) + Meteor.call "removeShippingMethod", $(event.currentTarget).data('provider-id'), @ + Alerts.add "Shipping method deleted.", "success", autoHide: true, placement:"shippingPackage" + else + event.preventDefault() + event.stopPropagation() + return # add new shipping method 'click #add-shipping-method': (event, template) -> - toggleSession "addShippingMethod" + console.log "click add-shipping-method" + session = Session.get "selectedAddShippingMethod" + if _.isEqual @, session + Session.set "selectedAddShippingMethod", false + else + Session.set "selectedAddShippingMethod", @ +### +# Autoform hooks +# Because these are some convoluted forms +### AutoForm.hooks "shipping-method-add-form": onSuccess: (operation, result, template) -> + toggleSession "selectedAddShippingMethod" Alerts.add "Shipping method rate added.", "success", autoHide: true, placement:"shippingPackage" - endSubmit: (formId, template) -> - #just here to prevent the default hook from running -AutoForm.hooks "shipping-provider-insert-form": +AutoForm.hooks "shipping-provider-add-form": onSuccess: (operation, result, template) -> Alerts.add "Shipping provider saved.", "success", autoHide: true, placement:"shippingPackage" diff --git a/packages/reaction-shipping/client/templates/shipping.html b/packages/reaction-shipping/client/templates/shipping.html index a0898a137d1..f3b16283fe2 100644 --- a/packages/reaction-shipping/client/templates/shipping.html +++ b/packages/reaction-shipping/client/templates/shipping.html @@ -1,25 +1,44 @@ - -