Make Account Center only usable when logged in
[blerg.git] / www / jssrc / blerg / PasswdForm.js
1 enyo.kind({
2     name: "blerg.PasswdForm",
3     classes: "blerg-form",
4     components: [
5         {kind: "onyx.Groupbox", components: [
6             {kind: "onyx.InputDecorator", components: [
7                 {name: "oldpassword", kind: "onyx.Input", placeholder: "Old Password", type: "password"}
8             ]}
9         ]},
10         {kind: "onyx.Groupbox", components: [
11             {kind: "onyx.InputDecorator", components: [
12                 {name: "password1", kind: "onyx.Input", placeholder: "New Password", type: "password"}
13             ]},
14             {kind: "onyx.InputDecorator", components: [
15                 {name: "password2", kind: "onyx.Input", placeholder: "New Password (again)", type: "password"}
16             ]}
17         ]},
18         {name: "changePasswordError", tag: "p", showing: false, classes: "blerg-error", content: "I couldn't change your password. Are you sure you have the right old password?"},
19         {name: "passwordMatchError", tag: "p", showing: false, classes: "blerg-error", content: "Your new passwords don't match."},
20         {name: "changeButton", kind: "onyx.Button", content: "Change", onclick: "changeClick", classes: "onyx.affirmative"},
21         {name: "spinner", kind: "OldSchoolSpinner", showing: false},
22         {name: "api", kind: "blerg.API",
23          onPasswordChangeSuccessful: "passwordChangeSuccessful",
24          onPasswordChangeFailed: "passwordChangeFailed"}
25     ],
26     hideErrors: function() {
27         this.$.changePasswordError.hide();
28         this.$.passwordMatchError.hide();
29     },
30     changeClick: function() {
31         this.hideErrors();
32         if (this.$.oldpassword.getValue() == '') {
33             this.$.changePasswordError.show();
34             return;
35         }
36         if (this.$.password1.getValue() != this.$.password2.getValue()) {
37             this.$.passwordMatchError.show();
38             return;
39         }
40         this.$.changeButton.setDisabled(true);
41         this.$.spinner.show();
42         this.$.spinner.start();
43         this.$.api.changePassword(this.$.oldpassword.getValue(), this.$.password1.getValue());
44     },
45     passwordChangeSuccessful: function(inSender, inEvent) {
46         this.$.oldpassword.setValue('');
47         this.$.password1.setValue('');
48         this.$.password2.setValue('');
49         this.$.changeButton.setDisabled(false);
50         this.$.spinner.hide();
51         this.$.spinner.stop();
52         alert("Password Changed Successfully");
53     },
54     passwordChangeFailed: function(inSender, inEvent) {
55         this.$.changeButton.setDisabled(false);
56         this.$.spinner.hide();
57         this.$.spinner.stop();
58         this.hideErrors();
59         this.$.changePasswordError.show();
60     }
61 });