Moving to a switch

This commit is contained in:
Will Marshall
2014-04-10 17:02:43 +10:00
parent acd8d2d8a2
commit 7fc3d4b7cc

View File

@@ -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