diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-11-24 20:57:41 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-11-24 20:57:41 -0500 |
| commit | 612561818f907f0f9988247c82ec158ba4494986 (patch) | |
| tree | 8bbc773dad7a6364cbdb8aed2ef4cab04854f49a /StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js | |
| parent | d548a7d02ce6349ca9a820b6824e4374b759812b (diff) | |
build
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js')
| -rw-r--r-- | StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js | 100 |
1 files changed, 100 insertions, 0 deletions
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 |
