summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/www/js')
-rw-r--r--StoneIsland/platforms/ios/www/js/index.js2
-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
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js3
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js5
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js36
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js1
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js132
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js86
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js24
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartView.js14
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js236
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js36
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js6
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js1
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js2
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/products/ProductView.js36
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/view/Router.js (renamed from StoneIsland/platforms/ios/www/js/vendor/view/router.js)0
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/view/Scrollable.js (renamed from StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js)0
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/view/Serializable.js (renamed from StoneIsland/platforms/ios/www/js/vendor/view/serializable.js)33
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/view/View.js (renamed from StoneIsland/platforms/ios/www/js/vendor/view/view.js)0
-rw-r--r--StoneIsland/platforms/ios/www/js/sdk/_sdk.js2
-rw-r--r--StoneIsland/platforms/ios/www/js/sdk/address.js44
-rw-r--r--StoneIsland/platforms/ios/www/js/sdk/auth.js14
-rw-r--r--StoneIsland/platforms/ios/www/js/sdk/cart.js48
-rw-r--r--StoneIsland/platforms/ios/www/js/sdk/payment.js4
-rw-r--r--StoneIsland/platforms/ios/www/js/sdk/shipping.js3
-rw-r--r--StoneIsland/platforms/ios/www/js/vendor/jquery.creditCardValidator.js208
30 files changed, 1106 insertions, 167 deletions
diff --git a/StoneIsland/platforms/ios/www/js/index.js b/StoneIsland/platforms/ios/www/js/index.js
index ed8d9e5a..546bd637 100644
--- a/StoneIsland/platforms/ios/www/js/index.js
+++ b/StoneIsland/platforms/ios/www/js/index.js
@@ -69,6 +69,8 @@ var app = (function(){
app.view = null
app.router = new SiteRouter ()
app.account.connect( app.router.route.bind(app.router) )
+
+ $("body").removeClass("loading")
}
return app
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
diff --git a/StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js b/StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js
index 735c0242..481dcb8d 100644
--- a/StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js
@@ -7,9 +7,10 @@ var LogoutView = View.extend({
show: function(){
document.body.className = "logout"
+ app.header.set_cart_count(0)
app.footer.hide()
+ auth.log_out()
app.account.logged_out()
- auth.clear_user()
},
}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js b/StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js
index 7f894c3c..7e6fc04d 100644
--- a/StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js
@@ -61,7 +61,9 @@ var SignupView = FormView.extend({
if (data.DataProfiling !== "true") { errors.push([ "DataProfiling", "You must consent to use this service." ]) }
if (data.DataProfiling2 !== "true") { errors.push([ "DataProfiling2", "You must consent to use this service." ]) }
if (! data.YooxLetter) { data.YooxLetter = false }
-
+ },
+
+ finalize: function(data){
delete data.DataProfiling2
delete data.ConfirmEmail
@@ -69,6 +71,7 @@ var SignupView = FormView.extend({
this.last_data = data
console.log(data)
+ return data
},
privacy_link: function(){
diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js
index 051ef0c9..3db5c8da 100644
--- a/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js
@@ -1,20 +1,34 @@
var ArchiveView = ScrollableView.extend({
el: "#archive",
- template: $("#archive .template").html(),
+ menu_template: $("#archive .menu .template").html(),
+ row_template: $("#archive .scroll .template").html(),
events: {
+ "click .item": "pick",
},
initialize: function(){
+ this.$menu_items = this.$(".menu .items")
this.$content = this.$(".content")
this.$loader = this.$(".loader")
- this.scroller = new IScroll('#archive', app.iscroll_options)
+ this.scroller = new IScroll('#archive .scroll', app.iscroll_options)
},
+ back: function(){
+ this.$el.addClass("menu")
+ app.header.set_back(false)
+ },
+
+ pick: function(){
+ this.$el.removeClass("menu")
+ app.header.set_back(true)
+ },
+
show: function(){
this.deferScrollToTop()
app.footer.hide()
+ this.back()
document.body.className = "archive"
},
@@ -24,12 +38,22 @@ var ArchiveView = ScrollableView.extend({
this.$content.empty()
// id title images[ uri label code caption ]
- this.data.forEach(function(row){
- var t = this.template.replace(/{{image}}/, row.images[0].uri)
- .replace(/{{code}}/, row.code)
- .replace(/{{title}}/, row.title)
+ this.data.forEach(function(row, index){
+ var t = this.row_template.replace(/{{image}}/, row.images[0].uri)
+ .replace(/{{label}}/, row.images[0].label)
+ .replace(/{{code}}/, row.images[0].code)
+ .replace(/{{caption}}/, row.images[0].caption)
this.$content.append(t)
+
+ var t = this.menu_template.replace(/{{title}}/, row.title)
+ var $t = $(t)
+ $t.data("title", row.title)
+ $t.data("index", index)
+ this.$menu_items.append($t)
}.bind(this))
+
+ this.back()
+ this.deferScrollToTop()
},
}) \ No newline at end of file
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 &gt;", "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 &gt;", "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
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js b/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js
index 15a5784d..31e9d802 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js
@@ -3,24 +3,25 @@ var AddressView = SerializableView.extend({
template: $("#address_template").html(),
+ disabled: false,
+
events: {
},
initialize: function(opt){
this.parent = opt.parent
- this.$el = this.parent.$(".address")
- this.el = this.$el[0]
+ this.checkPhone = 'checkPhone' in opt ? opt.checkPhone : true
+ this.setElement( this.parent.$(".address") )
this.$el.html(this.template)
},
populate: function(data){
- this.parent.$(".address input").val("")
- Object.keys(data).forEach(function(key){
- this.parent$(".address [name=" + key + "]").val(data[key])
- }.bind(this))
- },
-
- deserialize: function(){
+ this.data = data
+ var address = data.Address.split("\n")
+ data.Address1 = address[0]
+ data.Address2 = address[1]
+ this.$(".address input").val("")
+ this.load_data(data)
},
validate_presence: {
@@ -28,12 +29,223 @@ var AddressView = SerializableView.extend({
"Surname": "Please enter your last name.",
"Address1": "Please enter your street address.",
"City": "Please enter your city.",
- "State": "Please choose your state.",
- "Phone": "Please enter your phone number.",
+ "ZipCode": "Please enter your zip code.",
},
validate_fields: function(data, errors){
- if (data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) }
+ if (this.disabled) { return }
+ if (this.checkPhone && ! data.Phone) { errors.push([ "Phone", "Please enter your phone number." ]) }
+ if (this.checkPhone && data.Phone && data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) }
+ if (! data.Province || data.Province == "NONE") { errors.push([ "Province", "Please choose your state." ]) }
+ data.Address = data.Address1 + "\n" + data.Address2
+ data.UserId = auth.user_id
+ delete data.Address1
+ delete data.Address2
},
})
+
+
+var COUNTRIES = [
+ ['Country Name', 'NONE'],
+ ['United States', 'US'],
+ ['Abkhazia', 'GE'],
+ ['Afghanistan', 'AF'],
+ ['Albania', 'AL'],
+ ['Algeria', 'DZ'],
+ ['Andorra', 'AD'],
+ ['Angola', 'AO'],
+ ['Antigua and Barbuda', 'AG'],
+ ['Argentina', 'AR'],
+ ['Armenia', 'AM'],
+ ['Australia', 'AU'],
+ ['Austria', 'AT'],
+ ['Azerbaijan', 'AZ'],
+ ['Bahamas', 'BS'],
+ ['Bahrain', 'BH'],
+ ['Bangladesh', 'BD'],
+ ['Barbados', 'BB'],
+ ['Belarus', 'BY'],
+ ['Belgium', 'BE'],
+ ['Belize', 'BZ'],
+ ['Benin', 'BJ'],
+ ['Bhutan', 'BT'],
+ ['Bolivia', 'BO'],
+ ['Bosnia and Herzegovina', 'BA'],
+ ['Botswana', 'BW'],
+ ['Brazil', 'BR'],
+ ['Brunei', 'BN'],
+ ['Bulgaria', 'BG'],
+ ['Burkina Faso', 'BF'],
+ ['Burundi', 'BI'],
+ ['Cambodia', 'KH'],
+ ['Cameroon', 'CM'],
+ ['Canada', 'CA'],
+ ['Cape Verde', 'CV'],
+ ['Central African Republic', 'CF'],
+ ['Chad', 'TD'],
+ ['Chile', 'CL'],
+ ['China', 'CN'],
+ ['Colombia', 'CO'],
+ ['Comoros', 'KM'],
+ ['Congo', 'CD'],
+ ['Congo-Brazzaville', 'CG'],
+ ['Costa Rica', 'CR'],
+ ['Cote d\'Ivoire (Ivory Coast)', 'CI'],
+ ['Croatia', 'HR'],
+ ['Cuba', 'CU'],
+ ['Cyprus', 'CY'],
+ ['Czech Republic', 'CZ'],
+ ['Denmark', 'DK'],
+ ['Djibouti', 'DJ'],
+ ['Dominica', 'DM'],
+ ['Dominican Republic', 'DO'],
+ ['Ecuador', 'EC'],
+ ['Egypt', 'EG'],
+ ['El Salvador', 'SV'],
+ ['Equatorial Guinea', 'GQ'],
+ ['Eritrea', 'ER'],
+ ['Estonia', 'EE'],
+ ['Ethiopia', 'ET'],
+ ['Fiji', 'FJ'],
+ ['Finland', 'FI'],
+ ['France', 'FR'],
+ ['Gabon', 'GA'],
+ ['Gambia', '220'],
+ ['Georgia', 'GE'],
+ ['Germany', 'DE'],
+ ['Ghana', 'GH'],
+ ['Greece', 'GR'],
+ ['Grenada', 'GD'],
+ ['Guatemala', 'GT'],
+ ['Guinea', 'GN'],
+ ['Guinea-Bissau', 'GW'],
+ ['Guyana', 'GY'],
+ ['Haiti', 'HT'],
+ ['Honduras', 'HN'],
+ ['Hungary', 'HU'],
+ ['Iceland', 'IS'],
+ ['India', 'IN'],
+ ['Indonesia', 'ID'],
+ ['Iran', 'IR'],
+ ['Iraq', 'IQ'],
+ ['Ireland', 'IE'],
+ ['Israel', 'IL'],
+ ['Italy', 'IT'],
+ ['Jamaica', 'JM'],
+ ['Japan', 'JP'],
+ ['Jordan', 'JO'],
+ ['Kazakhstan', 'KZ'],
+ ['Kenya', 'KE'],
+ ['Kiribati', 'KI'],
+ ['Kuwait', 'KW'],
+ ['Kyrgyzstan', 'KG'],
+ ['Laos', 'LA'],
+ ['Latvia', 'LV'],
+ ['Lebanon', 'LB'],
+ ['Lesotho', 'LS'],
+ ['Liberia', 'LR'],
+ ['Libya', 'LY'],
+ ['Liechtenstein', 'LI'],
+ ['Lithuania', 'LT'],
+ ['Luxembourg', 'LU'],
+ ['Macedonia', 'MK'],
+ ['Madagascar', 'MG'],
+ ['Malawi', 'MW'],
+ ['Malaysia', 'MY'],
+ ['Maldives', 'MV'],
+ ['Mali', 'ML'],
+ ['Malta', 'MT'],
+ ['Marshall Islands', 'MH'],
+ ['Mauritania', 'MR'],
+ ['Mauritius', 'MU'],
+ ['Mexico', 'MX'],
+ ['Micronesia', 'FM'],
+ ['Moldova', 'MD'],
+ ['Monaco', 'MC'],
+ ['Mongolia', 'MN'],
+ ['Montenegro', 'ME'],
+ ['Morocco', 'MA'],
+ ['Mozambique', 'MZ'],
+ ['Myanmar', 'MM'],
+ ['Nagorno-Karabakh', 'AZ'],
+ ['Namibia', 'NA'],
+ ['Nauru', 'NR'],
+ ['Nepal', 'NP'],
+ ['Netherlands', 'NL'],
+ ['New Zealand', 'NZ'],
+ ['Nicaragua', 'NI'],
+ ['Niger', 'NE'],
+ ['Nigeria', 'NG'],
+ ['North Korea', 'KP'],
+ ['Northern Cyprus', 'CY'],
+ ['Norway', 'NO'],
+ ['Oman', 'OM'],
+ ['Pakistan', 'PK'],
+ ['Palau', 'PW'],
+ ['Panama', 'PA'],
+ ['Papua New Guinea', 'PG'],
+ ['Paraguay', 'PY'],
+ ['Peru', 'PE'],
+ ['Philippines', 'PH'],
+ ['Poland', 'PL'],
+ ['Portugal', 'PT'],
+ ['Qatar', 'QA'],
+ ['Romania', 'RO'],
+ ['Russia', 'RU'],
+ ['Rwanda', 'RW'],
+ ['Saint Kitts and Nevis', 'KN'],
+ ['Saint Lucia', 'LC'],
+ ['Saint Vincent and the Grenadines', 'VC'],
+ ['Samoa', 'WS'],
+ ['San Marino', 'SM'],
+ ['Sao Tome and Principe', 'ST'],
+ ['Saudi Arabia', 'SA'],
+ ['Senegal', 'SN'],
+ ['Serbia', 'RS'],
+ ['Seychelles', 'SC'],
+ ['Sierra Leone', 'SL'],
+ ['Singapore', 'SG'],
+ ['Slovakia', 'SK'],
+ ['Slovenia', 'SI'],
+ ['Solomon Islands', 'SB'],
+ ['Somalia', 'SO'],
+ ['Somaliland', 'SO'],
+ ['South Africa', 'Rand'],
+ ['South Korea', 'KR'],
+ ['South Ossetia', 'GE'],
+ ['Spain', 'ES'],
+ ['Sri Lanka', 'LK'],
+ ['Sudan', 'SD'],
+ ['Suriname', 'SR'],
+ ['Swaziland', 'SZ'],
+ ['Sweden', 'SE'],
+ ['Switzerland', 'CH'],
+ ['Syria', 'SY'],
+ ['Taiwan', 'TW'],
+ ['Tajikistan', 'TJ'],
+ ['Tanzania', 'TZ'],
+ ['Thailand', 'TH'],
+ ['Timor-Leste', 'TL'],
+ ['Togo', 'TG'],
+ ['Tonga', 'TO'],
+ ['Transnistria', 'MD'],
+ ['Trinidad and Tobago', 'TT'],
+ ['Tunisia', 'TN'],
+ ['Turkey', 'TR'],
+ ['Turkmenistan', 'TM'],
+ ['Tuvalu', 'TV'],
+ ['Uganda', 'UG'],
+ ['Ukraine', 'UA'],
+ ['United Arab Emirates', 'AE'],
+ ['United Kingdom', 'GB'],
+ ['Uruguay', 'UY'],
+ ['Uzbekistan', 'UZ'],
+ ['Vanuatu', 'VU'],
+ ['Vatican City', 'VA'],
+ ['Venezuela', 'VE'],
+ ['Vietnam', 'VN'],
+ ['Yemen', 'YE'],
+ ['Zambia', 'ZM'],
+ ['Zimbabwe', 'ZW'],
+]
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js b/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js
index 33ecab79..1855b7a9 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js
@@ -1,27 +1,53 @@
-var CreditCardView = View.extend({
+var CreditCardView = SerializableView.extend({
template: $("#creditcard_template").html(),
+ cardOptions: {
+ accept: ['visa', 'mastercard', 'amex'],
+ },
+
events: {
},
initialize: function(opt){
this.parent = opt.parent
- this.parent.$(".cc").html(this.template)
+ this.setElement( this.parent.$(".cc") )
+ this.$el.html(this.template)
+
+ this.$number = this.$("[name=Number]")
+ this.$number.validateCreditCard(this.updateCard.bind(this), this.cardOptions)
},
populate: function(data){
+ this.data = data
+ data.Number = "XXXX XXXX XXXX " + data.Number
+ this.$number.attr("type", "text")
this.parent.$(".cc input").val("")
- Object.keys(data).forEach(function(key){
- this.parent$(".cc [name=" + key + "]").val(data[key])
- }.bind(this))
+ this.$(".cc input").val("")
+ this.load_data(data)
+ },
+
+ updateCard: function(card){
+ // console.log(card)
+ // card.card_type.name
+ // card.card_type.valid
},
validate_presence: {
+ 'Number': 'Please enter your credit card number.',
+ 'Cvv': 'Please enter your security code.',
},
validate_fields: function(data, errors){
+ var card = this.$number.validateCreditCard(this.cardOptions)
+ if (! card.valid) { errors.push([ "Number", "Your card number is invalid." ]) }
+ if (! data.ExpirationMonth || data.ExpirationMonth == "NONE") { errors.push([ "ExpirationMonth", "Please enter the expiration month." ]) }
+ if (! data.ExpirationYear || data.ExpirationYear == "NONE") { errors.push([ "ExpirationYear", "Please select the expiration month." ]) }
+ data.UserId = auth.user_id
+ if (card.valid) {
+ data.Type = card.card_type.name
+ }
},
})
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js b/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js
index 7563be2d..b2f01208 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js
@@ -14,7 +14,9 @@ var HeaderView = View.extend({
this.$cart_count = this.$(".cart_count")
},
+ back_state: false,
set_back: function(state){
+ this.back_state = state
if (state) {
this.$burger[0].className = "burger ion-ios-arrow-left"
}
@@ -24,7 +26,7 @@ var HeaderView = View.extend({
},
nav: function(){
- if (app.view.back) {
+ if (this.back_state) {
app.view.back()
}
else {
@@ -43,7 +45,7 @@ var HeaderView = View.extend({
count: 0,
set_cart_count: function(n){
this.count = n
- this.$cart_count.html(n)
+ this.$cart_count.html(n || " ")
},
increment_cart_count: function(){
this.$cart_count.html( ++this.count )
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js b/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js
index 87e68959..2d8dca43 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js
@@ -34,6 +34,7 @@ var IntroView = View.extend({
else {
heading = e.alpha || 0
}
+ heading = - heading
this.compass.style[transformProp] = "translateZ(0) translateX(-50%) translateY(-50%) rotate(" + heading + "deg)"
},
diff --git a/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js b/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js
index 8ea03bd4..e35b789d 100644
--- a/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js
@@ -36,7 +36,7 @@ var CollectionView = ScrollableView.extend({
this.fetch()
},
- ok: function(){
+ save: function(){
this.filterView.filter()
},
diff --git a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js
index c99ff0ab..e151c208 100644
--- a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js
@@ -34,6 +34,7 @@ var ProductView = ScrollableView.extend({
size: null,
color: null,
code: null,
+ is_onesize: false,
sizes: null,
colors: null,
@@ -105,6 +106,8 @@ var ProductView = ScrollableView.extend({
var sizes = this.find_sizes_for_color(default_color_id)
var size = sizes[0]
var size_label = this.sizes[size].label
+
+ this.is_onesize = !! this.sizes[1]
// console.log(color, color_label, size, size_label)
@@ -158,7 +161,7 @@ var ProductView = ScrollableView.extend({
colors[ color['ColorId'] ] = {
id: color['Code10'],
code: color['Code10'],
- label: color['ColorDescription'],
+ label: color['ColorDescription'].toUpperCase(),
sizes: {},
}
})
@@ -167,7 +170,7 @@ var ProductView = ScrollableView.extend({
size_lookup[ label ] = size['SizeId']
sizes[ size['SizeId'] ] = {
id: label,
- label: label,
+ label: label.toUpperCase(),
colors: {},
}
})
@@ -182,6 +185,7 @@ var ProductView = ScrollableView.extend({
},
select_size: function(){
+ if (this.is_onesize) { return this.select_color() }
if (this.item['Sizes'].length == 0) { return }
var sizes = Object.keys(this.sizes).map(function(key){
return this.sizes[key]
@@ -205,27 +209,14 @@ var ProductView = ScrollableView.extend({
// ADD TO CART
save: function(){
- auth.deferred_product = { Size: this.size, Code10: this.code }
- if ( ! auth.logged_in() ) {
- app.router.go("account/login")
- app.last_view = app.cart
- }
- else if ( ! auth.has_cart() ) {
- auth.create_cart(function(){
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
- })
- })
- }
- else {
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
- })
- }
+ this.add_to_cart({ route: false })
},
-
// BUY NOW
cancel: function(){
+ this.add_to_cart({ route: true })
+ },
+
+ add_to_cart: function(opt){
auth.deferred_product = { Size: this.size, Code10: this.code }
if ( ! auth.logged_in() ) {
app.router.go("account/login")
@@ -240,7 +231,9 @@ var ProductView = ScrollableView.extend({
}
else {
auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
+ if (opt.route) {
+ app.router.go("cart")
+ }
})
}
},
@@ -262,6 +255,7 @@ var SIZE_LOOKUP = {
"XL": "X-LARGE",
"XXL": "XX-LARGE",
"3XL": "3X-LARGE",
+ "OneSize": "ONESIZE",
}
var SIZE_ORDER = "XS S M L XL XXL 3XL".split(" ")
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/router.js b/StoneIsland/platforms/ios/www/js/lib/view/Router.js
index a8ec331f..a8ec331f 100644
--- a/StoneIsland/platforms/ios/www/js/vendor/view/router.js
+++ b/StoneIsland/platforms/ios/www/js/lib/view/Router.js
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js b/StoneIsland/platforms/ios/www/js/lib/view/Scrollable.js
index 7cd96f89..7cd96f89 100644
--- a/StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js
+++ b/StoneIsland/platforms/ios/www/js/lib/view/Scrollable.js
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/serializable.js b/StoneIsland/platforms/ios/www/js/lib/view/Serializable.js
index e9459229..b1e095d3 100644
--- a/StoneIsland/platforms/ios/www/js/vendor/view/serializable.js
+++ b/StoneIsland/platforms/ios/www/js/lib/view/Serializable.js
@@ -3,13 +3,17 @@ var SerializableView = View.extend({
events: {
"change select": "update_select",
"focus input": "focus_input",
+ "submit form": "save",
},
preload: function(data){
if (! data && sdk.env == "production") { return }
data = data || this.test_data
if (! data) { return }
+ this.load_data(data)
+ },
+ load_data: function(data){
Object.keys(data).forEach(function(key){
var value = data[key]
var $el = this.$("[name=" + key + "]")
@@ -55,22 +59,21 @@ var SerializableView = View.extend({
update_select: function(e){
var $target = $(e.currentTarget), value = $target.val()
- var label = $($("select")[0]).find("option").filter(function(){ return this.value === value }).html()
-
+ var label = $target.find("option").filter(function(){ return this.value === value }).html()
$target.parent().addClass("picked")
$target.parent().find("span").html(label)
},
- validate: function(errors){
- var data = this.serialize()
- var errors = []
- var presence_msgs = this.validate_presence
+ validate: function(data, errors){
+ var data = data || this.serialize()
+ var errors = errors || []
+ var presence_msgs = this.validate_presence || {}
Object.keys(presence_msgs).forEach(function(k){
if (! data[k]) errors.push( [ k, presence_msgs[k] ] )
})
this.validate_fields && this.validate_fields(data, errors)
- this.cc && this.cc.validate(errors)
- this.address && this.address.validate(errors)
+ this.cc && this.cc.validate(data, errors)
+ this.address && this.address.validate(data, errors)
return { errors: errors, data: data }
},
@@ -89,6 +92,10 @@ var SerializableView = View.extend({
this.$msg.removeClass('alert-notice')
this.$msg.html("")
},
+
+ finalize: function(data){
+ return data
+ },
save: function(e){
e && e.preventDefault()
@@ -102,9 +109,17 @@ var SerializableView = View.extend({
this.hide_errors()
}
+ var finalized_data = this.finalize(valid.data)
+ this.submit( finalized_data )
+ },
+
+ submit: function(data){
+ if (! data) {
+ return
+ }
app.curtain.show("loading")
this.action({
- data: valid.data,
+ data: data,
success: function(data){
app.curtain.hide("loading")
this.success(data)
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/view.js b/StoneIsland/platforms/ios/www/js/lib/view/View.js
index 41638ab7..41638ab7 100644
--- a/StoneIsland/platforms/ios/www/js/vendor/view/view.js
+++ b/StoneIsland/platforms/ios/www/js/lib/view/View.js
diff --git a/StoneIsland/platforms/ios/www/js/sdk/_sdk.js b/StoneIsland/platforms/ios/www/js/sdk/_sdk.js
index 27773310..b7880e50 100644
--- a/StoneIsland/platforms/ios/www/js/sdk/_sdk.js
+++ b/StoneIsland/platforms/ios/www/js/sdk/_sdk.js
@@ -13,7 +13,7 @@ var sdk = (function(){
break
default:
case 'development':
- endpoint = "http://api.yoox.biz/"
+ endpoint = "/"
break
case 'production':
endpoint = "https://secure.api.yoox.biz/"
diff --git a/StoneIsland/platforms/ios/www/js/sdk/address.js b/StoneIsland/platforms/ios/www/js/sdk/address.js
index f4e36376..4fb12ad0 100644
--- a/StoneIsland/platforms/ios/www/js/sdk/address.js
+++ b/StoneIsland/platforms/ios/www/js/sdk/address.js
@@ -1,6 +1,23 @@
sdk.address = (function(){
var address = {}
+ address.list = function(opt){
+ return $.ajax({
+ method: "GET",
+ url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/addressBook.json"),
+ headers: {
+ "x-yoox-appname": auth.appname,
+ "x-yoox-account-token": auth.access_token,
+ },
+ data: opt.data,
+ success: function(data){
+ // console.log(data)
+ opt.success(data)
+ },
+ error: opt.error,
+ })
+ }
+
address.add = function(opt){
return $.ajax({
method: "POST",
@@ -18,15 +35,15 @@ sdk.address = (function(){
})
}
- address.list = function(opt){
+ address.update = function(opt){
return $.ajax({
- method: "GET",
- url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/addressBook.json"),
+ method: "PUT",
+ url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/addressBook/item.json"),
headers: {
"x-yoox-appname": auth.appname,
"x-yoox-account-token": auth.access_token,
},
- data: opt.data,
+ data: JSON.stringify( opt.data ),
success: function(data){
// console.log(data)
opt.success(data)
@@ -34,7 +51,24 @@ sdk.address = (function(){
error: opt.error,
})
}
-
+
+ address.destroy = function(opt){
+ return $.ajax({
+ method: "DELETE",
+ url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/" + opt.id + "/addressBook.json"),
+ headers: {
+ "x-yoox-appname": auth.appname,
+ "x-yoox-account-token": auth.access_token,
+ },
+ data: JSON.stringify( opt.data ),
+ success: function(data){
+ // console.log(data)
+ opt.success(data)
+ },
+ error: opt.error,
+ })
+ }
+
return address
})() \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/sdk/auth.js b/StoneIsland/platforms/ios/www/js/sdk/auth.js
index 8a72dd46..87ce60ea 100644
--- a/StoneIsland/platforms/ios/www/js/sdk/auth.js
+++ b/StoneIsland/platforms/ios/www/js/sdk/auth.js
@@ -95,15 +95,20 @@ var auth = sdk.auth = (function(){
auth.add_deferred_product_to_cart = function(cb){
// auth.deferred_product
if (! auth.deferred_product) {
+ console.log("VV NO DEF PROD")
cb && cb()
return
}
sdk.cart.add_item({
data: auth.deferred_product,
success: function(){
- console.log("ADDED")
+ console.log("ADDED ITEM")
cb && cb()
- }
+ },
+ error: function(data){
+ console.log("ERROR ADDING ITEM", data)
+ cb && cb()
+ },
})
auth.deferred_product = null
app.header.increment_cart_count()
@@ -112,13 +117,12 @@ var auth = sdk.auth = (function(){
auth.log_out = function(){
auth.clear_user()
auth.clear_cart()
- auth.view_logged_out()
}
auth.logged_in = function(){
- return (auth.user_id !== -1) && (auth.user_id !== "undefined")
+ return (auth.user_id && auth.user_id !== -1 && auth.user_id !== "undefined")
}
auth.has_cart = function(){
- return (sdk.cart.id !== -1) && (sdk.cart.id !== "undefined")
+ return (sdk.cart.id && sdk.cart.id !== -1 && sdk.cart.id !== "undefined")
}
return auth
diff --git a/StoneIsland/platforms/ios/www/js/sdk/cart.js b/StoneIsland/platforms/ios/www/js/sdk/cart.js
index bbd03299..a5e85089 100644
--- a/StoneIsland/platforms/ios/www/js/sdk/cart.js
+++ b/StoneIsland/platforms/ios/www/js/sdk/cart.js
@@ -105,7 +105,6 @@ sdk.cart = (function(){
})
}
- // NOTE: data might be wrapped in a Receiver object
cart.set_shipping_address = function(opt){
return $.ajax({
method: "PUT",
@@ -163,6 +162,17 @@ sdk.cart = (function(){
// NB: if "verification number" is 1, use CVV/CID/CVC security code
// if "verification number" is 2, use "Issue Number"
cart.use_stored_credit_card = function(opt){
+ var data = {
+ "Guid": opt.data.guid,
+ "UserId": auth.user_id,
+ "AccessToken": auth.access_token,
+ }
+ if (opt.data.cvv) {
+ data["Cvv"] = opt.data.cvv
+ }
+ if (opt.data.issue) {
+ data["Issue"] = opt.data.issue
+ }
return $.ajax({
method: "PUT",
url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/userCreditCard.json"),
@@ -170,13 +180,7 @@ sdk.cart = (function(){
"x-yoox-appname": auth.appname,
"x-yoox-cart-token": cart.token,
},
- data: JSON.stringify({ // NB may be wrapped in UserCreditCard object
- "Guid": opt.guid,
- "UserId": auth.user_id,
- "AccessToken": auth.access_token,
- "Cvv": opt.cvv,
- "Issue": opt.issue,
- }),
+ data: JSON.stringify(data),
success: function(data){
// console.log(data)
opt.success(data)
@@ -184,17 +188,17 @@ sdk.cart = (function(){
error: opt.error,
})
}
-
- cart.finalize = function(opt){
+
+ cart.secure_finalize = function(opt){
return $.ajax({
- method: "PUT",
+ method: "POST",
url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/secureFinalizer.json"),
headers: {
"x-yoox-appname": auth.appname,
"x-yoox-cart-token": cart.token,
"x-yoox-device": auth.device,
},
- data: JSON.stringify( opt.data ),
+ data: JSON.stringify( opt.data || {} ),
success: function(data){
console.log(data)
// order number is:
@@ -204,5 +208,25 @@ sdk.cart = (function(){
error: opt.error,
})
}
+
+ cart.finalize = function(opt){
+ return $.ajax({
+ method: "POST",
+ url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/finalizer.json"),
+ headers: {
+ "x-yoox-appname": auth.appname,
+ "x-yoox-cart-token": cart.token,
+ },
+ data: JSON.stringify( opt.data || {} ),
+ success: function(data){
+ console.log(data)
+ // order number is:
+ // "Info": "2905Y07FA13020"
+ opt.success(data)
+ },
+ error: opt.error,
+ })
+ }
+
return cart
})() \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/sdk/payment.js b/StoneIsland/platforms/ios/www/js/sdk/payment.js
index d0951017..283fee92 100644
--- a/StoneIsland/platforms/ios/www/js/sdk/payment.js
+++ b/StoneIsland/platforms/ios/www/js/sdk/payment.js
@@ -18,8 +18,6 @@ sdk.payment = (function(){
})
}
- // LISTING A CREDIT CARD ONCE A CARD HAS BEEN ADDED PRODUCES ERROR
-
payment.list_credit_cards = function(opt){
return $.ajax({
method: "GET",
@@ -30,8 +28,6 @@ sdk.payment = (function(){
},
data: opt.data,
success: function(data){
- console.log("listing credit cards")
- console.log(data)
opt.success(data)
},
error: opt.error,
diff --git a/StoneIsland/platforms/ios/www/js/sdk/shipping.js b/StoneIsland/platforms/ios/www/js/sdk/shipping.js
index a4615531..28a0db76 100644
--- a/StoneIsland/platforms/ios/www/js/sdk/shipping.js
+++ b/StoneIsland/platforms/ios/www/js/sdk/shipping.js
@@ -70,12 +70,9 @@ sdk.shipping = (function() {
"x-yoox-appname": auth.appname,
"x-yoox-cart-token": sdk.cart.token,
},
- // temporarily commented out
- /*
data: JSON.stringify({
"Id": opt.id,
}),
- */
success: function(data){
//console.log(data)
opt.success(data)
diff --git a/StoneIsland/platforms/ios/www/js/vendor/jquery.creditCardValidator.js b/StoneIsland/platforms/ios/www/js/vendor/jquery.creditCardValidator.js
new file mode 100644
index 00000000..56ce1bf6
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/vendor/jquery.creditCardValidator.js
@@ -0,0 +1,208 @@
+// Generated by CoffeeScript 1.8.0
+
+/*
+jQuery Credit Card Validator 1.0
+
+Copyright 2012-2015 Pawel Decowski
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+ */
+
+(function() {
+ var $,
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+
+ $ = jQuery;
+
+ $.fn.validateCreditCard = function(callback, options) {
+ var bind, card, card_type, card_types, get_card_type, is_valid_length, is_valid_luhn, normalize, validate, validate_number, _i, _len, _ref;
+ card_types = [
+ {
+ name: 'amex',
+ pattern: /^3[47]/,
+ valid_length: [15]
+ }, {
+ name: 'diners_club_carte_blanche',
+ pattern: /^30[0-5]/,
+ valid_length: [14]
+ }, {
+ name: 'diners_club_international',
+ pattern: /^36/,
+ valid_length: [14]
+ }, {
+ name: 'jcb',
+ pattern: /^35(2[89]|[3-8][0-9])/,
+ valid_length: [16]
+ }, {
+ name: 'laser',
+ pattern: /^(6304|670[69]|6771)/,
+ valid_length: [16, 17, 18, 19]
+ }, {
+ name: 'visa_electron',
+ pattern: /^(4026|417500|4508|4844|491(3|7))/,
+ valid_length: [16]
+ }, {
+ name: 'visa',
+ pattern: /^4/,
+ valid_length: [16]
+ }, {
+ name: 'mastercard',
+ pattern: /^5[1-5]/,
+ valid_length: [16]
+ }, {
+ name: 'maestro',
+ pattern: /^(5018|5020|5038|6304|6759|676[1-3])/,
+ valid_length: [12, 13, 14, 15, 16, 17, 18, 19]
+ }, {
+ name: 'discover',
+ pattern: /^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/,
+ valid_length: [16]
+ }
+ ];
+ bind = false;
+ if (callback) {
+ if (typeof callback === 'object') {
+ options = callback;
+ bind = false;
+ callback = null;
+ } else if (typeof callback === 'function') {
+ bind = true;
+ }
+ }
+ if (options == null) {
+ options = {};
+ }
+ if (options.accept == null) {
+ options.accept = (function() {
+ var _i, _len, _results;
+ _results = [];
+ for (_i = 0, _len = card_types.length; _i < _len; _i++) {
+ card = card_types[_i];
+ _results.push(card.name);
+ }
+ return _results;
+ })();
+ }
+ _ref = options.accept;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ card_type = _ref[_i];
+ if (__indexOf.call((function() {
+ var _j, _len1, _results;
+ _results = [];
+ for (_j = 0, _len1 = card_types.length; _j < _len1; _j++) {
+ card = card_types[_j];
+ _results.push(card.name);
+ }
+ return _results;
+ })(), card_type) < 0) {
+ throw "Credit card type '" + card_type + "' is not supported";
+ }
+ }
+ get_card_type = function(number) {
+ var _j, _len1, _ref1;
+ _ref1 = (function() {
+ var _k, _len1, _ref1, _results;
+ _results = [];
+ for (_k = 0, _len1 = card_types.length; _k < _len1; _k++) {
+ card = card_types[_k];
+ if (_ref1 = card.name, __indexOf.call(options.accept, _ref1) >= 0) {
+ _results.push(card);
+ }
+ }
+ return _results;
+ })();
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ card_type = _ref1[_j];
+ if (number.match(card_type.pattern)) {
+ return card_type;
+ }
+ }
+ return null;
+ };
+ is_valid_luhn = function(number) {
+ var digit, n, sum, _j, _len1, _ref1;
+ sum = 0;
+ _ref1 = number.split('').reverse();
+ for (n = _j = 0, _len1 = _ref1.length; _j < _len1; n = ++_j) {
+ digit = _ref1[n];
+ digit = +digit;
+ if (n % 2) {
+ digit *= 2;
+ if (digit < 10) {
+ sum += digit;
+ } else {
+ sum += digit - 9;
+ }
+ } else {
+ sum += digit;
+ }
+ }
+ return sum % 10 === 0;
+ };
+ is_valid_length = function(number, card_type) {
+ var _ref1;
+ return _ref1 = number.length, __indexOf.call(card_type.valid_length, _ref1) >= 0;
+ };
+ validate_number = (function(_this) {
+ return function(number) {
+ var length_valid, luhn_valid;
+ card_type = get_card_type(number);
+ luhn_valid = false;
+ length_valid = false;
+ if (card_type != null) {
+ luhn_valid = is_valid_luhn(number);
+ length_valid = is_valid_length(number, card_type);
+ }
+ return {
+ card_type: card_type,
+ valid: luhn_valid && length_valid,
+ luhn_valid: luhn_valid,
+ length_valid: length_valid
+ };
+ };
+ })(this);
+ validate = (function(_this) {
+ return function() {
+ var number;
+ number = normalize($(_this).val());
+ return validate_number(number);
+ };
+ })(this);
+ normalize = function(number) {
+ return (number || "").replace(/[ -]/g, '');
+ };
+ if (!bind) {
+ return validate();
+ }
+ this.on('input.jccv', (function(_this) {
+ return function() {
+ $(_this).off('keyup.jccv');
+ return callback.call(_this, validate());
+ };
+ })(this));
+ this.on('keyup.jccv', (function(_this) {
+ return function() {
+ return callback.call(_this, validate());
+ };
+ })(this));
+ callback.call(this, validate());
+ return this;
+ };
+
+}).call(this);