fc8dde231535578cd08629669973d59f15629f9b
[blerg.git] / www / jssrc / blerg / PasswdDialog.js
1 enyo.kind({
2     name: "blerg.PasswdDialog",
3     kind: "onyx.Popup",
4     classes: "blerg-dialog",
5     autoDismiss: true,
6     centered: true,
7     floating: true,
8     modal: true,
9     components: [
10         {tag: "h2", content: "Change Password"},
11         {name: "spinner", kind: "OldSchoolSpinner", showing: false, style: "position: absolute; top: 8px; right: 8px;"},
12         {kind: "onyx.Groupbox", components: [
13             {kind: "onyx.InputDecorator", components: [
14                 {name: "oldpassword", kind: "onyx.Input", placeholder: "Old Password", type: "password"}
15             ]}
16         ]},
17         {kind: "onyx.Groupbox", components: [
18             {kind: "onyx.InputDecorator", components: [
19                 {name: "password1", kind: "onyx.Input", placeholder: "New Password", type: "password"}
20             ]},
21             {kind: "onyx.InputDecorator", components: [
22                 {name: "password2", kind: "onyx.Input", placeholder: "New Password (again)", type: "password"}
23             ]}
24         ]},
25         {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?"},
26         {name: "passwordMatchError", tag: "p", showing: false, classes: "blerg-error", content: "Your new passwords don't match."},
27         {name: "changeButton", kind: "onyx.Button", content: "Change", onclick: "changeClick", classes: "onyx.affirmative"},
28         {kind: "onyx.Button", content: "Cancel", onclick: "cancelClick", classes: "onyx-negative"},
29         {name: "api", kind: "blerg.API",
30          onPasswordChangeSuccessful: "passwordChangeSuccessful",
31          onPasswordChangeFailed: "passwordChangeFailed"}
32     ],
33     hideErrors: function() {
34         this.$.changePasswordError.hide();
35         this.$.passwordMatchError.hide();
36     },
37     changeClick: function() {
38         this.hideErrors();
39         if (this.$.oldpassword.getValue() == '') {
40             this.$.changePasswordError.show();
41             return;
42         }
43         if (this.$.password1.getValue() != this.$.password2.getValue()) {
44             this.$.passwordMatchError.show();
45             return;
46         }
47         this.$.changeButton.setDisabled(true);
48         this.$.spinner.show();
49         this.$.spinner.start();
50         this.$.api.changePassword(this.$.oldpassword.getValue(), this.$.password1.getValue());
51     },
52     cancelClick: function() {
53         this.hide();
54     },
55     passwordChangeSuccessful: function(inSender, inEvent) {
56         this.$.changeButton.setDisabled(false);
57         this.$.spinner.hide();
58         this.$.spinner.stop();
59         this.cancelClick();
60         alert("Password Changed Successfully");
61     },
62     passwordChangeFailed: function(inSender, inEvent) {
63         this.$.changeButton.setDisabled(false);
64         this.$.spinner.hide();
65         this.$.spinner.stop();
66         this.hideErrors();
67         this.$.changePasswordError.show();
68     }
69 });