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