Redesign user tasks
[blerg.git] / www / jssrc / blerg / Blerg.js
index 080e644..31d28a8 100644 (file)
@@ -5,19 +5,25 @@ enyo.kind({
        handlers: {
                onStartSignup: "showSignupDialog",
                onTryLogin: "tryLogin",
-               onSetTitle: "setTitle"
+               onTryLogout: "tryLogout",
+               onSetTitle: "setTitle",
+               onPostVisibility: "postVisibilityUpdate"
        },
        components: [
                {classes: "blerg-header", components: [
-                       {kind: "blerg.Title"},
-                       {kind: "blerg.Controls"},
+                       {name: "title", kind: "blerg.Title"},
+                       {name: "controls", kind: "blerg.Controls"},
                        {style: "clear: both"},
                        {name: "post", kind: "blerg.Post", showing: false},
                        {name: "help", kind: "blerg.Help"}
                ]},
                {name: "main", kind: "blerg.Main"},
                {name: "signupDialog", kind: "blerg.SignupDialog"},
-               {name: "passwdDialog", kind: "blerg.PasswdDialog"}
+               {name: "passwdDialog", kind: "blerg.PasswdDialog"},
+               {name: "api", kind: "blerg.API",
+                onLoginSuccessful: "loginSuccessful",
+                onLoginFailed: "loginFailed",
+                onLogoutSuccessful: "logout"}
        ],
        urlmap: [
                ['search', /^\?post\/([^/]+)\/(.+)/, "blerg.ExternalURLPost"],
@@ -66,17 +72,31 @@ enyo.kind({
                this.$.signupDialog.show();
        },
        setTitle: function(inSender, inEvent) {
-               if (inEvent.section != undefined)
-                       this.$.title.setSection(inEvent.section);
-
-               if (inEvent.subscribed != undefined)
-                       this.$.title.setSubscribed(inEvent.subscribed);
-
-               if (inEvent.showControls)
-                       this.$.title.showControls()
-               else
-                       this.$.title.hideControls();
+               this.$.title.waterfall('onSetTitle', inEvent);
        },
        tryLogin: function(inSender, inEvent) {
+               this.$.api.login(inEvent.username, inEvent.password);
+       },
+       tryLogout: function(inSender, inEvent) {
+               this.$.api.logout();
+       },
+       loginSuccessful: function(inSender, inEvent) {
+               this.$.api.requestFeedStatus();
+               this.feedStatusUpdateInterval = setInterval(function() {
+                       this.$.api.requestFeedStatus();
+               }.bind(this), 900000);
+               this.waterfall('onLogin', inEvent);
+       },
+       loginFailed: function(inSender, inEvent) {
+               alert('Login failed');
+               this.logout();
+       },
+       logout: function(inSender, inEvent) {
+               clearInterval(this.feedStatusUpdateInterval);
+               this.waterfall('onLogout');
+       },
+       postVisibilityUpdate: function(inSender, inEvent) {
+               this.$.post.waterfall('onPostVisibility', inEvent);
+               this.$.controls.waterfall('onPostVisibility', inEvent);
        }
 });