From 7fc3d4b7cc38182338e62c0752d9abf62d6bb49d Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 10 Apr 2014 17:02:43 +1000 Subject: [PATCH] Moving to a switch --- .../darkswarm/services/order.js.coffee | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/order.js.coffee b/app/assets/javascripts/darkswarm/services/order.js.coffee index e5ae4d4bb1..61604e3dbb 100644 --- a/app/assets/javascripts/darkswarm/services/order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order.js.coffee @@ -7,31 +7,28 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)-> @order.shipping_method_id ||= parseInt(Object.keys(@order.shipping_methods)[0]) navigate: (path)-> - console.log path window.location.pathname = path submit: -> $http.put('/shop/checkout', {order: @preprocess()}).success (data, status)=> @navigate(data.path) .error (errors, status)=> - console.log "error" @errors = errors - - # Rails wants our Spree::Address data to be provided with _attributes preprocess: -> munged_order = {} for name, value of @order # Clone all data from the order JSON object - if name == "bill_address" - munged_order["bill_address_attributes"] = value - else if name == "ship_address" - munged_order["ship_address_attributes"] = value - else if name == "payment_method_id" - munged_order["payments_attributes"] = [{payment_method_id: value}] - else - munged_order[name] = value - # TODO: this + switch name + when "bill_address" + munged_order["bill_address_attributes"] = value + when "ship_address" + munged_order["ship_address_attributes"] = value + when "payment_method_id" + munged_order["payments_attributes"] = [{payment_method_id: value}] + else + munged_order[name] = value + if munged_order.ship_address_same_as_billing munged_order.ship_address_attributes = munged_order.bill_address_attributes munged_order