diff options
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/cart')
5 files changed, 237 insertions, 20 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js index 687f3a93..aa6ec9e4 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js @@ -14,6 +14,7 @@ var CartConfirm = FormView.extend({ document.body.className = "cart" app.cart.el.className = "confirm" app.footer.show("PLACE ORDER", "CANCEL") + window.location.hash = "#/cart/confirm" this.deferScrollToTop() }, diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js index 19d21ffd..fec5e1d1 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js @@ -2,39 +2,151 @@ var CartPayment = FormView.extend({ el: "#cart_payment", + address_template: $("#cart_payment .address_template").html(), + cc_template: $("#cart_payment .cc_template").html(), + + action: sdk.cart.set_credit_card, + + address_list_mode: false, + cc_list_mode: false, + events: { + "change [name=SameAsShipping]": "toggle_shipping", + "click .address_dropdown": "toggle_address", + "click .cc_dropdown": "toggle_cc", }, initialize: function(opt){ this.parent = opt.parent this.$form = this.$("form") this.$msg = this.$(".msg") - this.address = new AddressView ({ parent: this }) + 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 }) this.scroller = new IScroll('#cart_payment', app.iscroll_options) + this.address.disabled = true + 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" app.footer.show("CONFIRM >", "CANCEL") + window.location.hash = "#/cart/payment" + 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) + this.$address_list.toggle(this.address_list_mode) + }, - sdk.cart.set_payment_type({ data: payment_id }) + toggle_cc: function(state){ + 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) + this.$cc_list.toggle(this.cc_list_mode) + }, + + 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) + + var address_t = this.address_template.replace(/{{id}}/g, cc.Id) + .replace(/{{checked}}/g, cc.IsDefault ? "checked" : "") + .replace(/{{name}}/g, cc.Name + " " + cc.Surname) + .replace(/{{address}}/g, cc.Address.replace(/\n$/,"").replace("\n", "<br>")) + .replace(/{{city}}/g, cc.City) + .replace(/{{state}}/g, cc.Province) + .replace(/{{zip}}/g, cc.ZipCode) + + var cc_t = this.cc_template.replace(/{{id}}/g, cc.Id) + .replace(/{{checked}}/g, cc.IsDefault ? "checked" : "") + .replace(/{{last4}}/g, cc.Last4) + .replace(/{{type}}/g, cc.Type) + .replace(/{{exp}}/g, cc.ExpirationMonth + "/" + cc.ExpirationYear) + + this.$address_list.append(address_t) + 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 }, - save: function(){ + success: function(){ + app.router.go('cart/confirm') }, cancel: function(){ + app.router.go('cart/shipping') }, + })
\ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js index 7d7c8540..1a9653e1 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js @@ -2,32 +2,116 @@ var CartShipping = FormView.extend({ el: "#cart_shipping", + action: sdk.cart.set_shipping_address, + + list_mode: true, + + template: $("#cart_shipping .template").html(), + events: { + "click .dropdown-wrapper": "toggle_dropdown", }, initialize: function(opt){ this.parent = opt.parent this.$form = this.$("form") + this.$dropdown_wrapper = this.$(".dropdown-wrapper") + this.$address_list = this.$(".address_list") + this.$address_form = this.$(".address") this.$msg = this.$(".msg") this.address = new AddressView ({ parent: this }) this.scroller = new IScroll('#cart_shipping', app.iscroll_options) + this.address.disabled = true }, show: function(){ document.body.className = "cart" app.cart.el.className = "shipping" app.footer.show("PAYMENT >", "CANCEL") + window.location.hash = "#/cart/shipping" + this.populate() this.deferScrollToTop() }, + populate: function(){ + // id checked name address city state zip + this.$(".save_as_default").show() + this.$address_list.empty() + if (! app.account.addresses.length) { + this.toggle_dropdown(false) + return + } + app.account.addresses.forEach(function(address){ + var t = this.template.replace(/{{id}}/g, address.Id) + .replace(/{{checked}}/g, address.IsDefault ? "checked" : "") + .replace(/{{name}}/g, address.Name + " " + address.Surname) + .replace(/{{address}}/g, address.Address.replace(/\n$/,"").replace("\n", "<br>")) + .replace(/{{city}}/g, address.City) + .replace(/{{state}}/g, address.Province) + .replace(/{{zip}}/g, address.ZipCode) + this.$address_list.append(t) + }.bind(this)) + }, + + toggle_dropdown: function(state){ + if (! app.account.addresses.length) { + state = false + } + this.list_mode = typeof state == "boolean" ? state : ! this.list_mode + this.$dropdown_wrapper.toggle( !! app.account.addresses.length ) + this.address.disabled = this.list_mode + this.$address_form.toggle(! this.list_mode) + this.$address_list.toggle(this.list_mode) + }, + // sdk.cart.set_shipping_address // sdk.shipping.get_delivery_types // sdk.shipping.set_delivery_type - save: function(){ + shipping_types: { + Standard: 1, + Express: 2, + }, + + finalize: function(data){ + var shipping_info = {}, address_data, address_id + var shipping_type = $("[name=ShippingType]").filter(function(){ return $(this).prop("checked") }).val() + + sdk.shipping.set_delivery_type({ + id: this.shipping_types[shipping_type], + success: function(data){ console.log("set shipping type", data) }, + error: function(data){ console.log("didnt set shipping type", data) }, + }) + + 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 + } + + 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/payment') }, cancel: function(){ + app.router.go('cart/summary') }, })
\ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js index 209e3102..9a24afa5 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js @@ -27,6 +27,7 @@ var CartSummary = ScrollableView.extend({ show: function(){ document.body.className = "cart" app.cart.el.className = "summary" + window.location.hash = "#/cart/summary" if (auth.has_cart()) { this.load() } @@ -110,21 +111,21 @@ var CartSummary = ScrollableView.extend({ .replace(/{{price}}/, as_cash(details.Item.Price.DiscountedPrice)) $el.data("price", details.Item.Price.DiscountedPrice) $el.html(t) - this.deferScrollToTop() + this.refreshScroller() }.bind(this)) }.bind(this)) this.updateTotals() this.el.className = "full" - this.deferScrollToTop() + this.refreshScroller() }, updateCounts: function(){ - app.header.set_cart_count(this.data.Cart.Items.length) - this.parent.$itemcount.html(pluralize(this.data.Cart.Items.length, "ITEM", "S")) + app.header.set_cart_count( this.data.Cart.Items.length ) + this.parent.setHeaderCount( this.data.Cart.Items.length ) }, - + updateTotals: function(){ var subtotal = this.data.Cart.Totals.TotalWithoutPromotions var shipping_cost = this.data.Cart.DeliveryMethod.Selected.Amount.Total @@ -140,6 +141,7 @@ var CartSummary = ScrollableView.extend({ empty: function(){ app.footer.hide() app.header.set_cart_count(0) + this.parent.setHeaderCount( 0 ) this.parent.$itemcount.html("0 ITEMS") this.el.className = "empty" }, @@ -155,9 +157,11 @@ var CartSummary = ScrollableView.extend({ remove_item: function(e){ var $el = $( e.currentTarget ).closest(".cart_item_row") var data = $el.data() - data.Cart.Totals.TotalWithoutPromotions -= data.price - data.Cart.Totals.TotalToPay -= data.price - + + console.log(this.data.Cart) + + this.data.Cart.Totals.TotalWithoutPromotions -= data.price + this.data.Cart.Totals.TotalToPay -= data.price this.data.Cart.Items = this.data.Cart.Items.filter(function(item){ return ( item['Code10'] !== data.code || item['Size'] !== data.size) }) @@ -165,18 +169,20 @@ var CartSummary = ScrollableView.extend({ this.updateTotals() this.updateCounts() $el.remove() + this.refreshScroller() if (this.data.Cart.Items.length == 0) { this.empty() } + app.curtain.show("loading") sdk.cart.delete_item({ data: { Code10: data.code, Size: data.size, }, success: function(){ - console.log("damn") + app.curtain.hide("loading") }, }) }, diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js index 8bea43dc..b57caadd 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js @@ -15,6 +15,8 @@ var CartView = View.extend({ this.confirm = new CartConfirm ({ parent: this }) this.thanks = new CartThanks ({ parent: this }) + this.$full_msg = this.$(".full_msg") + this.$empty_msg = this.$(".empty_msg") this.$itemcount = this.$(".itemcount") }, @@ -47,4 +49,16 @@ var CartView = View.extend({ this.payment.show() }, + setHeaderCount: function(n){ + if (n) { + this.$itemcount.html(pluralize(n, "ITEM", "S")) + this.$full_msg.show() + this.$empty_msg.hide() + } + else { + this.$full_msg.hide() + this.$empty_msg.show() + } + }, + })
\ No newline at end of file |
