summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/lib/account/ProfileView.js
blob: d05ef5cd40d0c66d81144c00310148733baccdac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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." ]) }
  },

  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
      
      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(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"
    
    return submissible_data
  },
  
  success: function(data){
  },
  
  error: function(data){
  },

})