diff options
Diffstat (limited to 'StoneIsland/www/js/lib/account')
| -rw-r--r-- | StoneIsland/www/js/lib/account/AccountView.js | 30 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/ProfileView.js | 4 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/ShippingView.js | 49 |
3 files changed, 53 insertions, 30 deletions
diff --git a/StoneIsland/www/js/lib/account/AccountView.js b/StoneIsland/www/js/lib/account/AccountView.js index e1d7ca71..ce976094 100644 --- a/StoneIsland/www/js/lib/account/AccountView.js +++ b/StoneIsland/www/js/lib/account/AccountView.js @@ -16,29 +16,35 @@ var AccountView = View.extend({ } }, - populateAddresses: function(data){ - console.log("populate addresses:", data) + 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") return } - // console.log(data.AddressBook) data.AddressBook.addressBookItem.forEach(function(item){ - if (item.isDefault) { - // populate app.shipping.address - app.shipping.address.populate(item) + if (item.IsDefault) { + console.log("SHIPPING ADDRESS", item) + app.shipping.populate(item) } - else if (item.isBillingDefault) { - // populate app.billing.address - app.payment.address.populate(item) + if (item.IsBillingDefault) { + console.log("BILLING ADDRESS") + app.payment.populate(item) } }) + cb && cb() }, logged_in: function(cb){ - sdk.address.list({ - success: this.populateAddresses.bind(this) - }) + this.listAddresses() $("#nav .login").hide() $("#nav .account, #nav .logout").show() if (! auth.deferred_product && app.last_view) { diff --git a/StoneIsland/www/js/lib/account/ProfileView.js b/StoneIsland/www/js/lib/account/ProfileView.js index d05ef5cd..999e8d65 100644 --- a/StoneIsland/www/js/lib/account/ProfileView.js +++ b/StoneIsland/www/js/lib/account/ProfileView.js @@ -71,5 +71,9 @@ var ProfileView = FormView.extend({ error: function(data){ }, + + cancel: function(){ + app.router.go("intro") + }, })
\ No newline at end of file diff --git a/StoneIsland/www/js/lib/account/ShippingView.js b/StoneIsland/www/js/lib/account/ShippingView.js index e2426d2e..b8b260ab 100644 --- a/StoneIsland/www/js/lib/account/ShippingView.js +++ b/StoneIsland/www/js/lib/account/ShippingView.js @@ -2,8 +2,7 @@ var ShippingView = FormView.extend({ el: "#shipping", - createAction: sdk.address.add, - updateAction: sdk.address.update, + action: sdk.address.add, events: { }, @@ -11,14 +10,14 @@ var ShippingView = FormView.extend({ test_data: { "Name":"name", "Surname":"surname", - "Address":"address", + "Address":"address1\naddress2", "IsDefault":false, "IsBillingDefault":false, "IsOwner":false, "ZipCode":"88040", "City":"City", - "Province":"Province", - "Phone":"Phone", + "Province":"NY", + "Phone":"1234567890", "Mobile":"Mobile", "Mail":"Mail", "UserId": sdk.auth.user_id, @@ -27,37 +26,51 @@ var ShippingView = FormView.extend({ initialize: function(){ this.$form = this.$("form") this.$msg = this.$(".msg") - this.$isDefault = this.$("[name=IsDefault]") this.address = new AddressView ({ parent: this }) this.scroller = new IScroll('#shipping', app.iscroll_options) - this.preload() }, 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" }, + 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(){ console.log("destroyed") }, - error: function(){ console.log("destroyed") }, + success: function(){}, + error: function(){}, }) - this.action = this.updateAction - } - else { - this.action = this.createAction } - data.IsDefault = data.IsDefault ? "true" : "false" - data.Address = data.Address1 + "\n" + data.Address2 - delete data.Address1 - delete data.Address2 + + data.IsDefault = "true" // this.$isDefault.prop("checked") ? "true" : "false" + data.UserId = sdk.auth.user_id + console.log(data) - return 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 |
