diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-11-24 20:18:57 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-11-24 20:18:57 -0500 |
| commit | 144a3ecb4f610879c12dd10c31a7e310755e4781 (patch) | |
| tree | e6b8566d06d138c20b9b3a6af06afe19da4c6e2d | |
| parent | 5feeefffa62b131baff63e3241441727cf956fb6 (diff) | |
update profile
| -rw-r--r-- | StoneIsland/www/css/account.css | 10 | ||||
| -rw-r--r-- | StoneIsland/www/index.html | 27 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/OrdersView.js | 1 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/PaymentView.js | 1 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/ProfileView.js | 65 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/SettingsView.js | 1 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/ShippingView.js | 1 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/auth/SignupView.js | 14 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/account.js | 17 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/auth.js | 10 | ||||
| -rw-r--r-- | StoneIsland/www/js/vendor/view/serializable.js | 21 | ||||
| -rw-r--r-- | test/test/02-login.js | 10 |
12 files changed, 146 insertions, 32 deletions
diff --git a/StoneIsland/www/css/account.css b/StoneIsland/www/css/account.css index 765f575a..1c06ba1b 100644 --- a/StoneIsland/www/css/account.css +++ b/StoneIsland/www/css/account.css @@ -349,8 +349,9 @@ input.switch:checked + label:after { position: relative; text-align: center; + overflow: hidden; font-size: 14px; - outline: none!important; + outline: none !important; color: #000; letter-spacing: 1px; text-transform: uppercase; @@ -375,9 +376,14 @@ input.switch:checked + label:after { .select-wrapper select { opacity: 0; width: 100%; - height: 100%; + height: 35px; + line-height: 35px; position: absolute; top: 0; left: 0; + box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + border: 10px solid; } .select-wrapper span { position: relative; diff --git a/StoneIsland/www/index.html b/StoneIsland/www/index.html index 79543f97..2c27ad27 100644 --- a/StoneIsland/www/index.html +++ b/StoneIsland/www/index.html @@ -329,8 +329,7 @@ <input type="text" name="Surname" placeholder="LAST NAME" required> <input type="email" name="Email" placeholder="EMAIL ADDRESS" required> <input type="email" name="ConfirmEmail" placeholder="CONFIRM EMAIL ADDRESS" required> - <!-- NOTE: mm/dd/yyyy is pushed over to the left because of the dropdown arrow --> - <input type="text" onfocus="(this.type='date')" name="BirthDay" placeholder="BIRTHDAY (MM/DD/YYYY)" required> + <input type="date" name="BirthDay" placeholder="BIRTHDAY (MM/DD/YYYY)" required> <div class="select-wrapper"> <span>GENDER</span> @@ -346,7 +345,6 @@ </div> <div class="container-row"> <div class="container-message"> - <span class="msg"> * Your personal and payment<br> information will always remain private @@ -382,7 +380,7 @@ </form> </div> </div> - + <div id="profile"> <div class="scroll"> <h1>PROFILE</h1> @@ -392,14 +390,17 @@ <input type="text" name="Name" placeholder="FIRST NAME" required> <input type="text" name="Surname" placeholder="LAST NAME" required> <input type="email" name="Email" placeholder="EMAIL ADDRESS" required> - <div class="half-input"> - <input type="text" name="Zip" placeholder="ZIP" required> - <div id="country-wrapper"> - <div id="country-select"> - <input type="text" name="Country" placeholder="UNITED STATES" required> - </div> - </div> + <input type="date" name="BirthDay" placeholder="BIRTHDAY (MM/DD/YYYY)" required> + + <div class="select-wrapper"> + <span>GENDER</span> + <select name="Gender"> + <option value="NONE">Gender</option> + <option value="U">Male</option> + <option value="D">Female</option> + </select> </div> + <h2>CHANGE PASSWORD</h2> <input type="password" name="CurrentPassword" placeholder="CURRENT PASSWORD" required> <input type="password" name="NewPassword" placeholder="NEW PASSWORD (7 CHARACTERS OR MORE)" required> @@ -409,15 +410,13 @@ Receive Stone Island Newsletter </div> <div class="toggle"> - <input type="checkbox" id="receive-newsletter" name="YooxLetter" class="switch"> + <input type="checkbox" id="receive-newsletter" name="YooxLetter" class="switch" value="true"> <label for="receive-newsletter"></label> </div> </div> </div> <div class="container-fill"> <div class="container-message"> - <!-- addClass ".alert-notice" to make the - error message text red in the span below --> <span class="msg"> * Your personal and payment<br> information will always remain private diff --git a/StoneIsland/www/js/lib/account/OrdersView.js b/StoneIsland/www/js/lib/account/OrdersView.js index f9a2a35c..7283b65c 100644 --- a/StoneIsland/www/js/lib/account/OrdersView.js +++ b/StoneIsland/www/js/lib/account/OrdersView.js @@ -13,6 +13,7 @@ var OrdersView = View.extend({ }, show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } app.footer.hide() document.body.className = "orders" this.el.className = "list" diff --git a/StoneIsland/www/js/lib/account/PaymentView.js b/StoneIsland/www/js/lib/account/PaymentView.js index 4d6ccce5..d61ab5ab 100644 --- a/StoneIsland/www/js/lib/account/PaymentView.js +++ b/StoneIsland/www/js/lib/account/PaymentView.js @@ -14,6 +14,7 @@ var PaymentView = FormView.extend({ }, show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } app.footer.show("SAVE", "CANCEL") document.body.className = "payment" }, diff --git a/StoneIsland/www/js/lib/account/ProfileView.js b/StoneIsland/www/js/lib/account/ProfileView.js index 83ab0cdc..9150f874 100644 --- a/StoneIsland/www/js/lib/account/ProfileView.js +++ b/StoneIsland/www/js/lib/account/ProfileView.js @@ -12,8 +12,11 @@ var ProfileView = FormView.extend({ }, 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: { @@ -23,9 +26,69 @@ var ProfileView = FormView.extend({ }, validate_fields: function(data, errors){ - if (! data.CurrentPassword && data.NewPassword) { errors.push([ "CurrentPassword", "Please enter your current password." ]) } + 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){ diff --git a/StoneIsland/www/js/lib/account/SettingsView.js b/StoneIsland/www/js/lib/account/SettingsView.js index ba871543..81b8b5cc 100644 --- a/StoneIsland/www/js/lib/account/SettingsView.js +++ b/StoneIsland/www/js/lib/account/SettingsView.js @@ -12,6 +12,7 @@ var SettingsView = FormView.extend({ }, show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } app.footer.show("SAVE", "CANCEL") document.body.className = "settings" }, diff --git a/StoneIsland/www/js/lib/account/ShippingView.js b/StoneIsland/www/js/lib/account/ShippingView.js index bc4d24ef..f5bf1661 100644 --- a/StoneIsland/www/js/lib/account/ShippingView.js +++ b/StoneIsland/www/js/lib/account/ShippingView.js @@ -13,6 +13,7 @@ var ShippingView = FormView.extend({ }, show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } app.footer.show("SAVE", "CANCEL") document.body.className = "shipping" }, diff --git a/StoneIsland/www/js/lib/auth/SignupView.js b/StoneIsland/www/js/lib/auth/SignupView.js index 5d947d41..7f894c3c 100644 --- a/StoneIsland/www/js/lib/auth/SignupView.js +++ b/StoneIsland/www/js/lib/auth/SignupView.js @@ -12,7 +12,7 @@ var SignupView = FormView.extend({ "Gender": "U", "Name": "TestName", "Surname": "TestSurname", - "Birthday": "1978-11-12", + "BirthDay": "1978-11-12", "DataProfiling": true, "DataProfiling2": true, }, @@ -55,16 +55,17 @@ var SignupView = FormView.extend({ validate_fields: function(data, errors){ if (data.Password.length < 7) { errors.push([ "Password", "Password must be 7 characters or more." ]) } if (data.Password !== data.Password2) { errors.push([ "Password2", "Passwords don't match." ]) } + if (! data.Email.match("@")) { errors.push([ "Email", "Email address is not valid." ]) } if (data.Email.toLowerCase() !== data.ConfirmEmail.toLowerCase()) { errors.push([ "ConfirmEmail", "Email addresses don't match." ]) } if (data.Gender === "NONE") { errors.push([ "Gender", "Please supply your gender." ]) } 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" } + if (! data.YooxLetter) { data.YooxLetter = false } delete data.DataProfiling2 delete data.ConfirmEmail - data.Birthday += "T00:00:00Z" + data.BirthDay += "T00:00:00Z" this.last_data = data console.log(data) @@ -84,9 +85,10 @@ var SignupView = FormView.extend({ success: function(data){ console.log('success', data) auth.user = auth.user || {} - auth.user.name = this.last_data.Name - auth.user.surname = this.last_data.Surname - auth.user.email = this.last_data.Email + auth.user.Name = this.last_data.Name + auth.user.Surname = this.last_data.Surname + auth.user.Email = this.last_data.Email + auth.user.BirthDay = this.last_data.BirthDay app.account.logged_in(function(){ app.router.go("store") }) }, diff --git a/StoneIsland/www/js/sdk/account.js b/StoneIsland/www/js/sdk/account.js index 5b3b9f1e..fe5f03cd 100644 --- a/StoneIsland/www/js/sdk/account.js +++ b/StoneIsland/www/js/sdk/account.js @@ -47,6 +47,23 @@ sdk.account = (function(){ }) } + account.checkin = function(opt){ + return $.ajax({ + method: "GET", + url: sdk.path("Account.API/1.5", "users/" + auth.user_id + ".json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + }, + data: "{}", + success: function(data){ + auth.user = data.User + opt.success(data) + }, + error: opt.error, + }) + } + account.update = function(opt){ return $.ajax({ method: "PUT", diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js index 1fbf48ec..8a72dd46 100644 --- a/StoneIsland/www/js/sdk/auth.js +++ b/StoneIsland/www/js/sdk/auth.js @@ -26,11 +26,17 @@ var auth = sdk.auth = (function(){ auth.init = function(fn){ console.log("AUTH INIT") auth.get_user(function(){ - console.log("cool") if (auth.logged_in()) { + sdk.account.checkin({ + success: function(data){ + fn && fn( auth.logged_in() ) + } + }) auth.get_cart() } - fn && fn( auth.logged_in() ) + else { + fn && fn( auth.logged_in() ) + } }) } diff --git a/StoneIsland/www/js/vendor/view/serializable.js b/StoneIsland/www/js/vendor/view/serializable.js index a2ff1147..e9459229 100644 --- a/StoneIsland/www/js/vendor/view/serializable.js +++ b/StoneIsland/www/js/vendor/view/serializable.js @@ -5,13 +5,13 @@ var SerializableView = View.extend({ "focus input": "focus_input", }, - preload: function(){ - if (sdk.env == "production") { return } - - this.test_data['ConfirmEmail'] = this.test_data['Email'] - Object.keys(this.test_data).forEach(function(key){ + preload: function(data){ + if (! data && sdk.env == "production") { return } + data = data || this.test_data + if (! data) { return } - var value = this.test_data[key] + Object.keys(data).forEach(function(key){ + var value = data[key] var $el = this.$("[name=" + key + "]") if ($el.attr("type") == "checkbox") { @@ -30,7 +30,14 @@ var SerializableView = View.extend({ serialize: function(){ var fields = {} this.$("input[name], select[name], textarea[name]").each( function(){ - fields[this.name] = this.value + if (this.type == "checkbox") { + if ($(this).prop("checked")) { + fields[this.name] = this.value + } + } + else { + fields[this.name] = this.value + } }) return fields }, diff --git a/test/test/02-login.js b/test/test/02-login.js index ea3eaa3b..9ec157c1 100644 --- a/test/test/02-login.js +++ b/test/test/02-login.js @@ -85,6 +85,16 @@ describe('account', function(){ }) }) }) + + describe('#checkin()', function(){ + it('fetches the user account info', function(done){ + promise(sdk.account.checkin, {}).then(function(data){ + assert(data.Header.StatusCode == 200) + assert('User' in data) + done() + }).error(function(data){ console.log(data) }) + }) + }) describe('#update()', function(){ it('updates the user account info', function(done){ |
