blob: d0e5d0577277658c23d73b0dc774fa46a77cf834 (
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
|
var EditProfileModal = ModalFormView.extend({
el: ".mediaDrawer.editProfile",
action: "/api/profile",
method: "put",
events: {
"click [data-role='changePasswordToggle']": 'togglePasswordFields'
},
load: function(){
this.reset()
$.get("/api/profile", function(data){
for (var i in data) {
this.$("[name='" + i + "']").val(data[i])
}
this.$("#profile_username").html(data.username)
if (data.photo && data.photo.length) {
this.$("#load_avatar").attr("src", data.photo)
}
else {
this.$("#load_avatar").hide()
}
this.show()
}.bind(this))
},
togglePasswordFields: function(){
this.$("[data-role='changePasswordFields']").toggleClass("hidden")
},
validate: function(){
var errors = []
var email = this.$("#profile_email").val()
var pw0 = this.$("#profile_old_password").val()
var pw1 = this.$("#profile_new_password").val()
var pw2 = this.$("#profile_new_password2").val()
if (pw1.length) {
if (! pw0.length) {
errors.push("Please enter your old password.")
}
if (pw1 !== pw2) {
errors.push("New passwords don't match");
}
}
if (email.length && email.indexOf("@") === -1) {
errors.push("Please enter a valid email address");
}
return errors
},
success: function(){
window.location.href = "/profile"
}
})
|