Add password change functionality
[blerg.git] / www / jssrc / blerg / Blerg.js
1 enyo.kind({
2     name: "blerg.Blerg",
3     kind: "Control",
4     lastHash: null,
5     pathHandlers: [ blerg.User, blerg.Tag, blerg.Feed, blerg.ExternalURLPost, blerg.Welcome ],
6     handlers: {
7         onStartSignup: "showSignupDialog",
8         onTryLogin: "tryLogin",
9         onTryLogout: "tryLogout",
10         onSetTitle: "setTitle",
11         onPostVisibility: "postVisibilityUpdate",
12         onReload: "sendReload",
13         onShowChangePassword: "showChangePassword",
14     },
15     components: [
16         {classes: "blerg-header", components: [
17             {name: "title", kind: "blerg.Title"},
18             {name: "controls", kind: "blerg.Controls"},
19             {style: "clear: both;"},
20             {name: "post", kind: "blerg.Post", showing: false},
21             {name: "help", kind: "blerg.Help"}
22         ]},
23         {name: "main", kind: "blerg.Main"},
24         {name: "signupDialog", kind: "blerg.SignupDialog"},
25         {name: "passwdDialog", kind: "blerg.PasswdDialog"},
26         {name: "api", kind: "blerg.API",
27          onLoginSuccessful: "loginSuccessful",
28          onLoginFailed: "loginFailed",
29          onLogoutSuccessful: "logout"}
30     ],
31     rendered: function() {
32         this.inherited(arguments);
33
34         this.lastHash = location.hash;
35         this.urlSwitch();
36
37         setInterval(this.hashCheck.bind(this), 250);
38
39         document.body.addEventListener('keyup', function(event) {
40             if (event.shiftKey && event.keyCode == 32) {
41                 this.waterfall('onPostVisibility', {showing: true});
42                 event.stopPropagation();
43             }
44         }.bind(this), false);
45     },
46     hashCheck: function() {
47         if (location.hash != this.lastHash) {
48             this.lastHash = location.hash;
49             this.urlSwitch();
50         }
51     },
52     urlSwitch: function() {
53         var m;
54         var objdef = null;
55
56         for (var i = 0; i < this.pathHandlers.length; i++) {
57             var handler = this.pathHandlers[i];
58             objdef = handler.locationDetect(window.location);
59             if (objdef)
60                 break;
61         }
62         if (!objdef)
63             objdef = {classes: "blerg-error", content: "No handler found"}
64
65         this.$.main.updateView(objdef);
66     },
67     showSignupDialog: function() {
68         this.$.signupDialog.show();
69     },
70     setTitle: function(inSender, inEvent) {
71         this.$.title.waterfall('onSetTitle', inEvent);
72     },
73     tryLogin: function(inSender, inEvent) {
74         this.$.api.login(inEvent.username, inEvent.password);
75     },
76     tryLogout: function(inSender, inEvent) {
77         this.$.api.logout();
78     },
79     loginSuccessful: function(inSender, inEvent) {
80         this.waterfall('onLogin', inEvent);
81     },
82     loginFailed: function(inSender, inEvent) {
83         alert('Login failed');
84         this.logout();
85     },
86     logout: function(inSender, inEvent) {
87         clearInterval(this.feedStatusUpdateInterval);
88         this.waterfall('onLogout');
89     },
90     postVisibilityUpdate: function(inSender, inEvent) {
91         this.$.post.waterfall('onPostVisibility', inEvent);
92         this.$.controls.waterfall('onPostVisibility', inEvent);
93     },
94     sendReload: function() {
95         this.$.main.waterfall('onReload');
96     },
97     showChangePassword: function() {
98         this.$.passwdDialog.show();
99     }
100 });