Make Account Center only usable when logged in
[blerg.git] / www / jssrc / blerg / ForgotPasswordDialog.js
1 enyo.kind({
2     name: "blerg.ForgotPasswordDialog",
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: "Forgot 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: "username", kind: "onyx.Input", placeholder: "Username"}
15             ]},
16             {kind: "onyx.InputDecorator", components: [
17                 {name: "email", kind: "onyx.Input", placeholder: "Email Address"}
18             ]}
19         ]},
20         {name: "recoverError", tag: "p", showing: false, classes: 'blerg-error', content: "Please enter both username and email."},
21         {name: "recoverButton", kind: "onyx.Button", content: "Send Recovery Email", onclick: "recoverClick", classes: "onyx-affirmative"},
22         {kind: "onyx.Button", content: "Cancel", onclick: "cancelClick", classes: "onyx-negative"}
23     ],
24     recoverClick: function() {
25         var username = this.$.username.getValue();
26         var email = this.$.email.getValue();
27
28         if (!(username != '' && email != '')) {
29             this.$.recoverError.show();
30             return;
31         }
32
33         this.$.recoverButton.setDisabled(true);
34         this.$.spinner.show();
35         this.$.spinner.start();
36
37         var req = new enyo.Ajax({
38             url: '/aux/recovery/mail',
39             method: 'POST',
40             postBody: {
41                 username: username,
42                 email: email
43             }
44         });
45
46         req.response(this, function(inSender, inResponse) {
47             this.$.spinner.stop();
48             this.$.spinner.hide();
49             this.$.recoverButton.setDisabled(false);
50
51             if (inResponse.status == 'success') {
52                 alert("Recovery email sent");
53                 this.cancelClick();
54             }
55         });
56
57         req.error(this, function(inSender, inResponse) {
58             this.$.spinner.stop();
59             this.$.spinner.hide();
60             this.$.recoverButton.setDisabled(false);
61
62             alert("Failed due to backend error");
63         });
64
65         req.go();
66     },
67     cancelClick: function() {
68         this.$.username.setValue('');
69         this.$.email.setValue('');
70         this.hide();
71     },
72     setUsername: function(v) {
73         this.$.username.setValue(v);
74     }
75 });