diff options
Diffstat (limited to 'StoneIsland/platforms/android/assets/www/js/lib/account')
6 files changed, 616 insertions, 0 deletions
diff --git a/StoneIsland/platforms/android/assets/www/js/lib/account/AccountView.js b/StoneIsland/platforms/android/assets/www/js/lib/account/AccountView.js new file mode 100755 index 00000000..1c5c9f16 --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/js/lib/account/AccountView.js @@ -0,0 +1,129 @@ +var AccountView = View.extend({ + + initialize: function(){ + }, + + connect: function(cb){ + auth.init(this.ready.bind(this, cb)) + }, + + ready: function(cb){ + if (auth.logged_in()) { + this.logged_in(cb) + } + else { + this.logged_out(cb) + } + }, + + addresses: [], + addressLookup: {}, + ccs: [], + ccLookup: {}, + + listAddresses: function(cb){ + sdk.address.list({ + success: function(data){ + this.populateAddresses(data, cb) + }.bind(this) + }) + }, + + populateAddresses: function(data, cb){ + console.log("populate addresses:", data.AddressBook.addressBookItem) + + if (! data.AddressBook) { + console.log("no addresses") + cb && cb() + return + } + + this.addresses = data.AddressBook.addressBookItem + this.addressLookup = {} + data.AddressBook.addressBookItem.forEach(function(item){ + this.addressLookup[ item.Id ] = item + if (item.IsDefault) { + console.log("SHIPPING ADDRESS", item) + app.shipping.populate(item) + } + if (item.IsBillingDefault) { + console.log("BILLING ADDRESS") + app.payment.populate(item) + } + }.bind(this)) + + app.cart.shipping.populate() + + cb && cb() + }, + + listCreditCards: function(cb){ + sdk.payment.list_credit_cards({ + success: function(data){ + this.populateCreditCards(data, cb) + }.bind(this) + }) + }, + + populateCreditCards: function(data, cb){ + console.log("populate ccs:", data.CreditCards) + this.ccs = data.CreditCards + this.ccLookup = {} + if (! data.CreditCards || ! data.CreditCards.length) { + } + else { + data.CreditCards.forEach(function(cc){ + this.ccLookup[cc.Id] = cc + }.bind(this)) + app.payment.populate( data.CreditCards[0] ) + app.cart.payment.populate() + } + cb && cb() + }, + + logged_in: function(cb){ + this.listAddresses() + this.listCreditCards() + $("#nav .login").hide() + $("#nav .account, #nav .logout").show() + if (! auth.deferred_product && app.last_view) { + if (app.last_view != app.login && app.last_view != app.signin && app.last_view != app.logout) { + app.view && app.view.hide && app.view.hide() + app.view = app.last_view + app.view.show() + } + } + else { + cb && cb() + } + if ( ! auth.has_cart() ) { + app.curtain.show("loading") + auth.create_cart(function(){ + auth.add_deferred_product_to_cart(function(){ + app.router.go("cart") + setTimeout(function(){ + app.curtain.hide("loading") + }, 500) + }) + }) + } + else { + if (auth.deferred_product) { + auth.add_deferred_product_to_cart(function(){ + app.router.go("cart") + }) + } + else { + app.cart.load() + } + } + }, + + logged_out: function(cb){ + $("#nav .login").show() + $("#nav .account, #nav .logout").hide() + $("#nav").removeClass("account") + cb && cb() + }, + +}) diff --git a/StoneIsland/platforms/android/assets/www/js/lib/account/OrdersView.js b/StoneIsland/platforms/android/assets/www/js/lib/account/OrdersView.js new file mode 100755 index 00000000..a1b83767 --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/js/lib/account/OrdersView.js @@ -0,0 +1,189 @@ +var OrdersView = ScrollableView.extend({ + + el: "#orders", + + loaded: false, + + list_template: $("#orders .list_template").html(), + item_template: $("#orders .item_template").html(), + + events: { + "click .back": "back", + "click .item": "load_single", + }, + + initialize: function(){ + this.$list = this.$(".list") + this.$empty = this.$(".empty") + this.$single_order = this.$("#single_order") + + this.$rows = this.$(".rows") + this.$subtotal = this.$(".subtotal") + this.$shipping = this.$(".shipping") + this.$tax = this.$(".tax") + this.$total = this.$(".total") + + this.$shipping_address = this.$(".shipping_address") + this.$shipping_method = this.$(".shipping_method") + + this.scroller = new IScroll('#orders', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.header.set_back(false) + app.footer.hide() + document.body.className = "orders" + this.deferScrollToTop() + this.el.className = "" + + if (this.loaded) { + this.populate() + } + else { + this.fetch() + } + }, + + orders: null, + orderLookup: {}, + + fetch: function(){ + this.$list.empty() + this.$empty.hide() + this.loader = new Loader(this.ready.bind(this)) + app.curtain.show("loading") + sdk.account.fetch_orders({ + success: function(data){ + this.loader.register("orders") + this.orders = data.OrderDetails + data.OrderDetails.forEach(function(row){ + this.loader.register(row.OrderNumber) + sdk.account.fetch_single_order({ + id: row.OrderNumber, + success: function(row_data){ + this.orderLookup[ row.OrderNumber ] = row_data.OrderFullDetails + this.loader.ready(row.OrderNumber) + }.bind(this), + error: function(){ + this.orderLookup[ row.OrderNumber ] = null + this.loader.ready(row.OrderNumber) + }.bind(this), + }) + }.bind(this)) + this.loader.ready("orders") + }.bind(this), + error: function(){ + console.log("error fetching orders") + }.bind(this), + }) + }, + + ready: function(){ + this.populate() + app.curtain.hide("loading") + }, + + populate: function(){ + this.$list.empty() + + if (! this.orders.length) { + this.$empty.show() + return + } + else { + this.$empty.hide() + } + this.orders.forEach(function(row){ + var order = this.orderLookup[ row.OrderNumber ] + if (! order) { return } + var t = this.list_template.replace(/{{date}}/g, moment(order['Date']).format("ddd MM/DD/YYYY").toUpperCase()) + .replace(/{{id}}/g, row.OrderNumber) + .replace(/{{total}}/g, as_cash( order.TotalAmount )) + var $t = $(t), $images = $t.find(".images") + order.Items.forEach(function(item){ + var img = new Image () + img.src = sdk.image(item['Code10'], "11_f") + $images.append(img) + }.bind(this)) + this.$list.append($t) + }.bind(this)) + + this.refreshScroller() + }, + + load_single: function(e){ + var id = $(e.currentTarget).data("id") + var order = this.orderLookup[ id ] + if (! order) { return } + + console.log(order) + + this.$rows.empty() + + order.Items.forEach(function(item){ + var $el = $("<div class='item'><img src='img/spinner.gif'></div>") + this.$rows.append($el) + var code_ten = item.Code10 + + var code = code_ten.substr(0, 8) + app.product.find(code, function(data, details){ + var descriptions = app.product.get_descriptions( details ) + + var name_partz = descriptions['ModelNames'].split(' ') + var num = name_partz.shift() + var title = name_partz.join(' ') + var type = title_case( descriptions['MicroCategory'] ) + + var color_name, size_name + + details.Item.ModelColors.some(function(color){ + if (color['Code10'] == code_ten) { + color_name = color['ColorDescription'] + return true + } + return false + }) + size_name = item.DefaultSize + " " + item.DefaultSizeClassFamily + + var t = this.item_template + .replace(/{{image}}/, sdk.image(item['Code10'], '11_f')) + .replace(/{{sku}}/, num) + .replace(/{{title}}/, title) + .replace(/{{type}}/, type) + .replace(/{{size}}/, size_name || "DEFAULT") + .replace(/{{color}}/, color_name || "DEFAULT") + .replace(/{{quantity}}/, 1) + .replace(/{{price}}/, as_cash(details.Item.Price.DiscountedPrice)) + $el.data("price", details.Item.Price.DiscountedPrice) + $el.html(t) + this.refreshScroller() + }.bind(this)) + }.bind(this)) + + var subtotal = order.ItemsTotalAmount + var shipping_cost = order.Delivery.Amount + var tax = order.SalesTaxAmount + var total = order.TotalToPay + + this.$subtotal.html( as_cash(subtotal) ) + this.$shipping.html( as_cash(shipping_cost) ) + this.$tax.html( as_cash(tax) ) + this.$total.html( as_cash(total) ) + + var street = order.Delivery.Address.replace(/\n$/,"").replace("\n","<br>") + var address = order.Delivery.Name + "<br>" + street + "<br>" + order.Delivery.City + " " + order.Delivery.ZipCode + this.$shipping_address.html(address) + this.$shipping_method.html(order.Delivery.Type + " - " + order.Delivery.Time) + + app.header.set_back(true) + this.$el.addClass("single") + }, + + back: function(){ + app.header.set_back(false) + this.el.className = "" + }, + +}) + diff --git a/StoneIsland/platforms/android/assets/www/js/lib/account/PaymentView.js b/StoneIsland/platforms/android/assets/www/js/lib/account/PaymentView.js new file mode 100755 index 00000000..03dc8cbf --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/js/lib/account/PaymentView.js @@ -0,0 +1,115 @@ +var PaymentView = FormView.extend({ + + el: "#payment", + + action: sdk.payment.add_credit_card, + + events: { + }, + + test_data: { + "Name":"Name", + "Surname":"Surname", + "Address1":"address", + "Address2":"address2", + "City":"Ferrara", + "Province":"NY", + "HolderIsoCountry":"IT", + "CreditCardCountry": "US", + "ZipCode":"40200", + "Type":"Visa", + "Number":"4111111111111111", + "ExpirationMonth":"09", + "ExpirationYear":"2017", + "Cvv":"1233", + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.address = new AddressView ({ parent: this, checkPhone: false }) + this.cc = new CreditCardView ({ parent: this }) + this.scroller = new IScroll('#payment', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.show("SAVE", "CANCEL") + document.body.className = "payment" + this.deferScrollToTop() + // this.preload() + }, + + populate: function(data){ + this.data = data || this.data + this.address.populate(data) + this.cc.populate(data) + }, + + finalize: function(data){ + if (this.cc.data && this.cc.data.Guid) { + sdk.payment.delete_credit_card({ + guid: this.cc.data.Guid, + success: function(){}, + error: function(){}, + }) + } + + data.IsDefault = "true" // this.$isDefault.prop("checked") ? "true" : "false" + data.UserId = sdk.auth.user_id + data.HolderIsoCountry = "US" + data.CreditCardNumber = data.Number + data.IsPreferred = "true" + + console.log(data) + return data + }, + + success: function(data){ + app.curtain.show("loading") + app.account.listAddresses(function(){ + app.curtain.hide("loading") + }) + }, + + error: function(data){ + console.log(data) + }, + + cancel: function(){ + app.router.go("intro") + }, + +}) + +/* + var new_card = { + "Name":"Name", + "Surname":"Surname", + "Address":"address", + "City":"Ferrara", + "Province":"FE", + "HolderIsoCountry":"IT", + "ZipCode":"40200", + "Type":"Visa", + "Number":"0000567890124285", + "ExpirationMonth":"02", + "ExpirationYear":"2017", + } + promise(sdk.payment.add_credit_card, { data: new_card }).then(function(data){ + last_guid = data['CreditCard']['Guid'] + assert(data.Header.StatusCode == 201) + assert(!! last_guid) + done() + }) + + promise(sdk.payment.list_credit_cards, { data: {} }).then(function(data){ + assert(data.Header.StatusCode == 201) + console.log(data) + done() + }) + + promise(sdk.payment.delete_credit_card, { guid: last_guid }).then(function(data){ + assert(data.Header.StatusCode == 200) + done() +*/
\ No newline at end of file diff --git a/StoneIsland/platforms/android/assets/www/js/lib/account/ProfileView.js b/StoneIsland/platforms/android/assets/www/js/lib/account/ProfileView.js new file mode 100755 index 00000000..ed2f3536 --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/js/lib/account/ProfileView.js @@ -0,0 +1,82 @@ +var ProfileView = FormView.extend({ + + el: "#profile", + + events: { + }, + + action: sdk.account.update, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.scroller = new IScroll('#profile', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.show("SAVE", "CANCEL") + document.body.className = "profile" + this.preload(auth.user) + this.deferScrollToTop() + }, + + validate_presence: { + "Name": "Please enter your first name.", + "Surname": "Please enter your last name.", + "Email": "Please enter a valid email address.", + }, + + validate_fields: function(data, errors){ + if (! data.Email.match("@")) { errors.push([ "Email", "Email address is not valid." ]) } + if (! data.CurrentPassword && (data.NewPassword || data.Email !== auth.user.Email)) { errors.push([ "CurrentPassword", "Please enter your current password." ]) } + if (data.CurrentPassword && ! data.NewPassword) { errors.push([ "NewPassword", "Please enter your new password." ]) } + if (data.NewPassword && data.NewPassword.length < 7) { errors.push([ "CurrentPassword", "New password must be 7 characters or more." ]) } + // if (data.Gender === "NONE") { errors.push([ "Gender", "Please supply your gender." ]) } + }, + + finalize: function(data){ + if (data.CurrentPassword && (data.NewPassword || data.Email !== auth.user.Email)) { + data.NewPassword = data.NewPassword || data.CurrentPassword + data.NewEmail = data.NewEmail || auth.user.Email + + sdk.account.update_mail_and_password({ + data: { + Password: data.CurrentPassword, + NewPassword: data.NewPassword || data.CurrentPassword, + Email: auth.user, + NewEmail: data.NewEmail || auth.user.Email, + }, + success: function(){ console.log("updated password") }, + error: function(){ console.log("error updating password") }, + }) + } + + var submissible_data = _.pick(data, "Name Surname BirthDay YooxLetter".split(" ")) + submissible_data.Gender = "U" +// submissible_data.idUser = auth.user_id +// submissible_data.AccessToken = auth.access_token +// submissible_data.Premium = "false" +// submissible_data.LanguageId = "" +// submissible_data.SiteCode = "STONEISLAND_US" +// submissible_data.FuriganaName = "" +// submissible_data.FuriganaSurname = "" +// submissible_data.UserPromocode = "" + submissible_data.BirthDay += "T00:00:00Z" + submissible_data.YooxLetter = data.YooxLetter || "false" + submissible_data.DataProfiling = "true" + + return submissible_data + }, + + success: function(data){ + }, + + error: function(data){ + }, + + cancel: function(){ + app.router.go("intro") + }, + +})
\ No newline at end of file diff --git a/StoneIsland/platforms/android/assets/www/js/lib/account/SettingsView.js b/StoneIsland/platforms/android/assets/www/js/lib/account/SettingsView.js new file mode 100755 index 00000000..7f96bb88 --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/js/lib/account/SettingsView.js @@ -0,0 +1,24 @@ +var SettingsView = FormView.extend({ + + el: "#settings", + + events: { + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.scroller = new IScroll('#settings', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.show("SAVE", "CANCEL") + document.body.className = "settings" + this.deferScrollToTop() + }, + + save: function(){ + }, + +})
\ No newline at end of file diff --git a/StoneIsland/platforms/android/assets/www/js/lib/account/ShippingView.js b/StoneIsland/platforms/android/assets/www/js/lib/account/ShippingView.js new file mode 100755 index 00000000..39baf2aa --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/js/lib/account/ShippingView.js @@ -0,0 +1,77 @@ +var ShippingView = FormView.extend({ + + el: "#shipping", + + action: sdk.address.add, + + events: { + }, + + test_data: { + "Name":"name", + "Surname":"surname", + "Address":"address1\naddress2", + "IsDefault":false, + "IsBillingDefault":false, + "IsOwner":false, + "ZipCode":"88040", + "City":"City", + "Province":"NY", + "Phone":"1234567890", + "Mobile":"Mobile", + "Mail":"Mail", + "UserId": sdk.auth.user_id, + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.address = new AddressView ({ parent: this }) + this.scroller = new IScroll('#shipping', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } +// this.preload( this.data || this.test_data ) + app.footer.show("SAVE", "CANCEL") + document.body.className = "shipping" + this.deferScrollToTop() + }, + + populate: function(data){ + this.data = data || this.data + this.address.populate(data) + }, + + finalize: function(data){ + if (this.address.data && this.address.data.Id) { + sdk.address.destroy({ + id: this.address.data.Id, + success: function(){}, + error: function(){}, + }) + } + + data.IsDefault = "true" // this.$isDefault.prop("checked") ? "true" : "false" + data.UserId = sdk.auth.user_id + + console.log(data) + return data + }, + + success: function(data){ + app.curtain.show("loading") + app.account.listAddresses(function(){ + app.curtain.hide("loading") + }) + }, + + error: function(data){ + console.log(data) + }, + + cancel: function(){ + app.router.go("intro") + }, + +})
\ No newline at end of file |
