diff options
| author | Rene Ae <aehtyb@gmail.com> | 2015-11-30 15:24:27 -0600 |
|---|---|---|
| committer | Rene Ae <aehtyb@gmail.com> | 2015-11-30 15:24:27 -0600 |
| commit | 9d0e54228c79d151c30c527ea83efa7479793686 (patch) | |
| tree | 3baf83427cd61cb1994e8551eefba5cd21d1a65b /StoneIsland/www/js/lib/cart/CartPayment.js | |
| parent | b208cb0283c23d68e8013c0dd5ddd4e5e6df8950 (diff) | |
| parent | d26e72aea3b3127c95c5ba7069c95f73cf52a2fd (diff) | |
Merge branch 'master' of https://github.com/okfocus/stone-island
Diffstat (limited to 'StoneIsland/www/js/lib/cart/CartPayment.js')
| -rw-r--r-- | StoneIsland/www/js/lib/cart/CartPayment.js | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/StoneIsland/www/js/lib/cart/CartPayment.js b/StoneIsland/www/js/lib/cart/CartPayment.js index 62dfe32d..fec5e1d1 100644 --- a/StoneIsland/www/js/lib/cart/CartPayment.js +++ b/StoneIsland/www/js/lib/cart/CartPayment.js @@ -11,7 +11,7 @@ var CartPayment = FormView.extend({ cc_list_mode: false, events: { - "change [name=same_as_shipping]": "toggle_shipping", + "change [name=SameAsShipping]": "toggle_shipping", "click .address_dropdown": "toggle_address", "click .cc_dropdown": "toggle_cc", }, @@ -20,10 +20,14 @@ var CartPayment = FormView.extend({ this.parent = opt.parent this.$form = this.$("form") this.$msg = this.$(".msg") + this.$same_as_shipping = this.$("[name=SameAsShipping]") + this.$billing_address_rapper = this.$(".billing_address_rapper") this.$address_list = this.$(".address_list") this.$address_form = this.$(".address") + this.$address_dropdown = this.$(".address_dropdown") this.$cc_list = this.$(".cc_list") this.$cc_form = this.$(".cc") + this.$cc_dropdown = this.$(".cc_dropdown") this.address = new AddressView ({ parent: this, checkPhone: false }) this.cc = new CreditCardView ({ parent: this }) @@ -32,13 +36,6 @@ var CartPayment = FormView.extend({ this.cc.disabled = true }, - // sdk.cart.set_credit_card - // sdk.payment.list_credit_cards - // sdk.payment.add_credit_card - // sdk.payment.delete_credit_card - // sdk.payment.get_payment_types - // sdk.cart.use_stored_credit_card - show: function(){ document.body.className = "cart" app.cart.el.className = "payment" @@ -48,11 +45,20 @@ var CartPayment = FormView.extend({ this.populate() this.deferScrollToTop() }, + + toggle_shipping: function(){ + setTimeout(function(){ + var state = this.$same_as_shipping.prop("checked") + this.$billing_address_rapper.toggle( ! state ) + }.bind(this)) + }, toggle_address: function(state){ if (! app.account.ccs.length) { state = false } + // this.$address_dropdown.toggle( !! app.account.ccs.length ) + this.address_list_mode = typeof state == "boolean" ? state : ! this.list_mode this.address.disabled = this.address_list_mode this.$address_form.toggle(! this.address_list_mode) @@ -63,6 +69,8 @@ var CartPayment = FormView.extend({ if (! app.account.ccs.length) { state = false } + // this.$cc_dropdown.toggle( !! app.account.ccs.length ) + this.cc_list_mode = typeof state == "boolean" ? state : ! this.cc_list_mode this.cc.disabled = this.cc_list_mode this.$cc_form.toggle(! this.cc_list_mode) @@ -70,6 +78,12 @@ var CartPayment = FormView.extend({ }, populate: function(){ + this.$(".save_as_default").show() + this.$address_list.empty() + this.$cc_list.empty() + this.toggle_address( !! app.account.ccs.length ) + this.toggle_cc( !! app.account.ccs.length ) + app.account.ccs.forEach(function(cc){ console.log(cc) @@ -91,6 +105,40 @@ var CartPayment = FormView.extend({ this.$cc_list.append(cc_t) }) }, + + finalize: function(data){ + var shipping_info = {}, address_data, address_id, cc_info = {}, cc_data, cc_id + var shipping_type = $("[name=ShippingType]").filter(function(){ return $(this).prop("checked") }).val() + + if (this.list_mode) { + address_id = $("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val() + address_data = app.account.addressLookup[ address_id ] + } + else { + address_data = data + } + if (this.cc_list_mode) { + cc_id = $("[name=CCId]").filter(function(){ return $(this).prop("checked") }).val() + cc_data = app.account.ccLookup[ cc_id ] + } + else { + cc_data = data + } + + shipping_info.Name = address_data.Name + shipping_info.Surname = address_data.Surname + shipping_info.Email = auth.user.Email + shipping_info.Phone = address_data.Phone + shipping_info.Mobile = address_data.Phone + shipping_info.StreetWithNumber = address_data.Address + shipping_info.PostalCode = address_data.ZipCode + shipping_info.City = address_data.City + shipping_info.Province = address_data.Province + shipping_info.Region = address_data.Province + shipping_info.CountryCode = "US" + + return shipping_info + }, success: function(){ app.router.go('cart/confirm') |
