Version 1.7
[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.$.oldpassword.setValue('');
57         this.$.password1.setValue('');
58         this.$.password2.setValue('');
59         this.$.changeButton.setDisabled(false);
60         this.$.spinner.hide();
61         this.$.spinner.stop();
62         this.cancelClick();
63         alert("Password Changed Successfully");
64     },
65     passwordChangeFailed: function(inSender, inEvent) {
66         this.$.changeButton.setDisabled(false);
67         this.$.spinner.hide();
68         this.$.spinner.stop();
69         this.hideErrors();
70         this.$.changePasswordError.show();
71     }
72 });