summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/account
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-11-24 20:57:41 -0500
committerJules Laplace <jules@okfoc.us>2015-11-24 20:57:41 -0500
commit612561818f907f0f9988247c82ec158ba4494986 (patch)
tree8bbc773dad7a6364cbdb8aed2ef4cab04854f49a /StoneIsland/platforms/ios/www/js/lib/account
parentd548a7d02ce6349ca9a820b6824e4374b759812b (diff)
build
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/account')
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/AccountView.js70
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/OrdersView.js29
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js25
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js100
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js23
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js24
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js17
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js18
8 files changed, 306 insertions, 0 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
new file mode 100644
index 00000000..cbd9a9c6
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
@@ -0,0 +1,70 @@
+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)
+ }
+ },
+
+ populateAddresses: function(data){
+ console.log("populate addresses:", data)
+ 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
+ }
+ else if (item.isBillingDefault) {
+ // populate app.billing.address
+ }
+ })
+ },
+
+ logged_in: function(cb){
+ sdk.address.list({
+ success: this.populateAddresses.bind(this)
+ })
+ $("#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()
+ }
+ else {
+ cb && cb()
+ }
+ if ( ! auth.has_cart() ) {
+ auth.create_cart(auth.add_deferred_product_to_cart)
+ }
+ else {
+ if (auth.deferred_product) {
+ auth.add_deferred_product_to_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/ios/www/js/lib/account/OrdersView.js b/StoneIsland/platforms/ios/www/js/lib/account/OrdersView.js
new file mode 100644
index 00000000..7283b65c
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/OrdersView.js
@@ -0,0 +1,29 @@
+var OrdersView = View.extend({
+
+ el: "#orders",
+
+ events: {
+ "click .back": "back",
+ "click .details": "load_single",
+ },
+
+ initialize: function(){
+ this.single = new SingleOrder ({ parent: this })
+ this.list = new OrderList ({ parent: this })
+ },
+
+ show: function(){
+ if (! auth.logged_in()) { return app.router.go("intro") }
+ app.footer.hide()
+ document.body.className = "orders"
+ this.el.className = "list"
+ },
+
+ load_single: function(){
+ },
+
+ back: function(){
+ this.list.show()
+ },
+
+})
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js b/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js
new file mode 100644
index 00000000..d61ab5ab
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js
@@ -0,0 +1,25 @@
+var PaymentView = FormView.extend({
+
+ el: "#payment",
+
+ events: {
+ },
+
+ initialize: function(){
+ this.$form = this.$("form")
+ this.$msg = this.$(".msg")
+ this.address = new AddressView ({ parent: this })
+ 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"
+ },
+
+ save: function(){
+ },
+
+})
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js b/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js
new file mode 100644
index 00000000..9150f874
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js
@@ -0,0 +1,100 @@
+var ProfileView = FormView.extend({
+
+ el: "#profile",
+
+ events: {
+ },
+
+ 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)
+ },
+
+ 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." ]) }
+
+ 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
+ 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(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 = ""
+ 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),
+ })
+ },
+
+ success: function(data){
+ },
+
+ error: function(data){
+ },
+
+}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js b/StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js
new file mode 100644
index 00000000..81b8b5cc
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js
@@ -0,0 +1,23 @@
+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"
+ },
+
+ save: function(){
+ },
+
+}) \ 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
new file mode 100644
index 00000000..f5bf1661
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js
@@ -0,0 +1,24 @@
+var ShippingView = FormView.extend({
+
+ el: "#shipping",
+
+ events: {
+ },
+
+ 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") }
+ app.footer.show("SAVE", "CANCEL")
+ document.body.className = "shipping"
+ },
+
+ save: function(){
+ },
+
+}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js b/StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js
new file mode 100644
index 00000000..876f609e
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js
@@ -0,0 +1,17 @@
+var OrderList = ScrollableView.extend({
+
+ el: "#order_list",
+
+ template: $("#order_list .template"),
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.scroller = new IScroll('#order_list', app.iscroll_options)
+ },
+
+ show: function(){
+ document.body.className = "orders"
+ app.orders.el.className = "list"
+ },
+
+})
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js b/StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js
new file mode 100644
index 00000000..21416401
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js
@@ -0,0 +1,18 @@
+var SingleOrder = ScrollableView.extend({
+
+ el: "#single_order",
+
+ template: $("#single_order .template"),
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.scroller = new IScroll('#single_order', app.iscroll_options)
+ },
+
+ show: function(id){
+ document.body.className = "orders"
+ app.orders.el.className = "single"
+ this.deferScrollToTop()
+ },
+
+})