Make Account Center only usable when logged in
[blerg.git] / www / jssrc / blerg / Controls.js
index e593976..cc8ae8d 100644 (file)
@@ -10,42 +10,48 @@ enyo.kind({
     handlers: {
         onLogin: "login",
         onLogout: "logout",
-        onPostVisibility: "postVisibilityUpdate"
+        onPostVisibility: "postVisibilityUpdate",
+        onShowForgotPasswordLink: "showForgotPasswordLink"
     },
     components: [
         {name: "loggedOutControls", components: [
-            {tag: "form", onsubmit: "loginClicked", classes: "login", components: [
+            {tag: "form", onkeyup: "loginKeyUp", classes: "login", components: [
                 {kind: "onyx.Groupbox", components: [
                     {kind: "onyx.InputDecorator", components: [
-                        {name: "username", kind: "onyx.Input", placeholder: "Username"}
+                        {name: "username", kind: "onyx.Input", placeholder: "Username", attributes: {tabindex: 1}}
                     ]},
                     {kind: "onyx.InputDecorator", components: [
-                        {name: "password", kind: "onyx.Input", placeholder: "Password", type: "password"}
+                        {name: "password", kind: "onyx.Input", placeholder: "Password", type: "password", attributes: {tabindex: 2}}
                     ]},
                 ]},
-                {kind: "onyx.Button", content: "Login", onclick: "loginClicked"}
+                {kind: "onyx.Button", content: "Login", onclick: "loginClicked", attributes: {tabindex: 3}},
+                {name: "forgotPassword", showing: false, style: "margin-top: 10px; text-align: left", components: [
+                    {kind: "blerg.Link", content: "Forgot your password?", onNavigate: "popupForgotPasswordDialog"}
+                ]}
             ]}
         ]},
         {name: "loggedInControls", showing: false, components: [
-            {name: "greeting", components: [
-                {noDom: true, content: "Hello, "},
+            {name: "greeting", classes: "blerg-controls-greeting", components: [
+                {tag: null, content: "Hello, "},
                 {name: "userlink", tag: "a"},
-                {noDom: true, content: ". "},
+                {tag: null, content: ". "},
                 {kind: "blerg.Link", content: "Logout", onNavigate: "logoutClicked"},
-                {noDom: true, content: "."}
-            ]},
-            {components: [
-                {name: "rssButton", kind: "blerg.Link", showing: false, components: [
-                    {kind: "Image", src: "/images/rss.png", width: 16, height: 16},
-                    {noDom: true, content: " RSS"}
-                ]}
+                {tag: null, content: "."},
+                {tag: "br"},
+                {kind: "blerg.Link", content: "Account Center", href: '/#/account'},
+                {tag: null, content: "."}
             ]},
             {classes: "blerg-controls-toolbar", components: [
-                {kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"},
-                {kind: "onyx.Button", content: "Stalk Your Victims", onclick: "feedClicked"},
+                {name: "mentionButton", kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"},
+                {name: "feedButton", kind: "onyx.Button", classes: "feed-button", content: "Stalk Your Victims", onclick: "feedClicked"},
                 {name: "spewButton", kind: "onyx.Button", classes: "spew-button", content: "Spew It!", onclick: "spewToggle"}
             ]},
-        ]}
+        ]},
+        {name: "forgotPasswordDialog", kind: "blerg.ForgotPasswordDialog"},
+        {name: "api", kind: "blerg.API",
+         onStatus: "gotStatus"},
+        {kind: "Signals", 
+         onClearNotification: "clearNotification"}
     ],
     showRSS: function(url) {
         this.$.rssButton.show();
@@ -72,19 +78,41 @@ enyo.kind({
         inEvent.preventDefault();
         return true;
     },
+    loginKeyUp: function(inSender, inEvent) {
+        if (inEvent.keyCode == 13) {
+            if (this.$.username.hasFocus()) {
+                this.$.password.focus();
+            } else {
+                this.loginClicked(this, inEvent);
+            }
+            return true;
+        }
+    },
     logoutClicked: function() {
         this.bubble('onTryLogout');
         return true;
     },
     login: function(inSender, inEvent) {
         this.$.password.setValue('');
+        this.$.forgotPassword.hide();
+        // TODO: Replace with regular blur() call in future enyo
+        this.$.password.node.blur();
         this.setLoggedIn(true);
         this.$.userlink.setAttribute('href', '/#' + inEvent.username);
         this.$.userlink.setContent('@' + inEvent.username);
         this.username = inEvent.username;
+
+        this.updateStatus();
+        this.feedStatusUpdateInterval = setInterval(function() {
+            this.updateStatus();
+        }.bind(this), 900000);
     },
     logout: function(inSender, inEvent) {
         this.setLoggedIn(false);
+        clearInterval(this.feedStatusUpdateInterval);
+    },
+    changePasswordClicked: function() {
+        this.bubble('onShowChangePassword');
     },
     spewToggle: function(inSender, inEvent) {
         this.postShowing = !this.postShowing;
@@ -94,6 +122,22 @@ enyo.kind({
         this.postShowing = inEvent.showing;
         this.$.spewButton.addRemoveClass('active', inEvent.showing);
     },
+    updateStatus: function() {
+        this.$.api.getStatus();
+    },
+    gotStatus: function(inSender, inEvent) {
+        if ('mentioned' in inEvent) {
+            this.$.mentionButton.addRemoveClass('new', inEvent.mentioned);
+        }
+        if ('feed_new' in inEvent) {
+            this.$.feedButton.addRemoveClass('new', inEvent.feed_new > 0);
+            if (inEvent.feed_new > 0) {
+                this.$.feedButton.setContent('Stalk Your Victims (' + inEvent.feed_new + ')');
+            } else {
+                this.$.feedButton.setContent('Stalk Your Victims');
+            }
+        }
+    },
     chatterClicked: function() {
         window.location.href = '/#/ref/' + this.username;
         this.bubble('onNavigate');
@@ -101,5 +145,19 @@ enyo.kind({
     feedClicked: function() {
         window.location.href = '/#/feed';
         this.bubble('onNavigate');
+    },
+    clearNotification: function(inSender, inEvent) {
+        if (inEvent.type == 'feed') {
+            this.gotStatus(this, {feed_new: 0});
+        } else if (inEvent.type == 'mentioned') {
+            this.gotStatus(this, {mentioned: false});
+        }
+    },
+    showForgotPasswordLink: function(inSender, inevent) {
+        this.$.forgotPassword.show();
+    },
+    popupForgotPasswordDialog: function() {
+        this.$.forgotPasswordDialog.setUsername(this.$.username.getValue());
+        this.$.forgotPasswordDialog.show();
     }
 });