summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/account
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/account')
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/AccountView.js93
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js93
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js57
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js54
4 files changed, 238 insertions, 59 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
index cbd9a9c6..1c5c9f16 100644
--- a/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
@@ -16,43 +16,102 @@ var AccountView = View.extend({
}
},
- populateAddresses: function(data){
- console.log("populate addresses:", data)
+ 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
}
- // console.log(data.AddressBook)
+
+ this.addresses = data.AddressBook.addressBookItem
+ this.addressLookup = {}
data.AddressBook.addressBookItem.forEach(function(item){
- if (item.isDefault) {
- // populate app.shipping.address
+ this.addressLookup[ item.Id ] = item
+ if (item.IsDefault) {
+ console.log("SHIPPING ADDRESS", item)
+ app.shipping.populate(item)
}
- else if (item.isBillingDefault) {
- // populate app.billing.address
+ 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){
- sdk.address.list({
- success: this.populateAddresses.bind(this)
- })
+ this.listAddresses()
+ this.listCreditCards()
$("#nav .login").hide()
$("#nav .account, #nav .logout").show()
- if (app.last_view && 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()
+ 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() ) {
- auth.create_cart(auth.add_deferred_product_to_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()
+ auth.add_deferred_product_to_cart(function(){
+ app.router.go("cart")
+ })
}
else {
app.cart.load()
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js b/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js
index d61ab5ab..9410fa42 100644
--- a/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js
@@ -1,14 +1,33 @@
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 })
+ this.address = new AddressView ({ parent: this, checkPhone: false })
this.cc = new CreditCardView ({ parent: this })
this.scroller = new IScroll('#payment', app.iscroll_options)
},
@@ -17,9 +36,79 @@ var PaymentView = FormView.extend({
if (! auth.logged_in()) { return app.router.go("intro") }
app.footer.show("SAVE", "CANCEL")
document.body.className = "payment"
+ // 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)
},
- save: function(){
+ 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/ios/www/js/lib/account/ProfileView.js b/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js
index 9150f874..999e8d65 100644
--- a/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js
@@ -31,24 +31,9 @@ var ProfileView = FormView.extend({
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." ]) }
-
- data.BirthDay += "T00:00:00Z"
- data.YooxLetter = data.YooxLetter || "false"
},
- save: function(e){
- e && e.preventDefault()
-
- var valid = this.validate()
- if (valid.errors.length) {
- this.show_errors(valid.errors)
- return
- }
- else {
- this.hide_errors()
- }
-
- var data = valid.data
+ 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
@@ -65,30 +50,20 @@ var ProfileView = FormView.extend({
})
}
- var submissible_data = _.pick(valid.data, "Name Surname BirthDay Gender YooxLetter".split(" "))
-
- 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 = ""
+ var submissible_data = _.pick(data, "Name Surname BirthDay Gender YooxLetter".split(" "))
+// 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"
-
- app.curtain.show("loading")
- sdk.account.update({
- data: submissible_data,
- success: function(data){
- app.curtain.hide("loading")
- this.success(data)
- }.bind(this),
- error: function(data){
- app.curtain.hide("loading")
- this.error(data)
- }.bind(this),
- })
+
+ return submissible_data
},
success: function(data){
@@ -96,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/platforms/ios/www/js/lib/account/ShippingView.js b/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js
index f5bf1661..b8b260ab 100644
--- a/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js
@@ -2,8 +2,26 @@ 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")
@@ -14,11 +32,45 @@ var ShippingView = FormView.extend({
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"
},
- save: function(){
+ 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