X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FControls.js;h=f386627fbca091fb0c923a017dd62e16ebd819c3;hb=868758a60c47c984eb76bae45183d063981ebdd5;hp=f23f63f34148d766684b6623b66cb7e0393c0a1c;hpb=55431b133192e59138a51591d7ef4ef20b6ceb52;p=blerg.git diff --git a/www/jssrc/blerg/Controls.js b/www/jssrc/blerg/Controls.js index f23f63f..f386627 100644 --- a/www/jssrc/blerg/Controls.js +++ b/www/jssrc/blerg/Controls.js @@ -1,97 +1,128 @@ enyo.kind({ - name: "blerg.Controls", - kind: "Control", - classes: "blerg-controls", - username: null, - postShowing: false, - published: { - loggedIn: false - }, - handlers: { - onLogin: "login", - onLogout: "logout", - onPostVisibility: "postVisibilityUpdate" - }, - components: [ - {name: "loggedOutControls", components: [ - {tag: "form", onsubmit: "loginClicked", classes: "login", components: [ - {kind: "onyx.Groupbox", components: [ - {kind: "onyx.InputDecorator", components: [ - {name: "username", kind: "onyx.Input", placeholder: "Username"} - ]}, - {kind: "onyx.InputDecorator", components: [ - {name: "password", kind: "onyx.Input", placeholder: "Password", type: "password"} - ]}, - ]}, - {kind: "onyx.Button", content: "Login", onclick: "loginClicked"} - ]} - ]}, - {name: "loggedInControls", showing: false, components: [ - {name: "greeting", components: [ - {noDom: true, content: "Hello, "}, - {name: "userlink", tag: "a"}, - {noDom: true, 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"} - ]} - ]}, - {classes: "blerg-controls-toolbar", components: [ - {kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"}, - {kind: "onyx.Button", content: "Stalk Your Victims", onclick: "feedClicked"}, - {name: "spewButton", kind: "onyx.Button", classes: "spew-button", content: "Spew It!", onclick: "spewToggle"} - ]}, - ]} - ], - showRSS: function(url) { - this.$.rssButton.show(); - if (url) - this.$.rssButton.setAttribute('href', url); - }, - hideRSS: function() { - this.$.rssButton.hide(); - }, - loggedInChanged: function() { - if (this.loggedIn) { - this.$.loggedOutControls.hide(); - this.$.loggedInControls.show(); - } else { - this.$.loggedOutControls.show(); - this.$.loggedInControls.hide(); - } - }, - loginClicked: function(inSender, inEvent) { - this.bubble('onTryLogin', { - username: this.$.username.getValue(), - password: this.$.password.getValue() - }); - inEvent.preventDefault(); - return true; - }, - logoutClicked: function() { - this.bubble('onTryLogout'); - return true; - }, - login: function(inSender, inEvent) { - this.$.password.setValue(''); - this.setLoggedIn(true); - this.$.userlink.setAttribute('href', '/#' + inEvent.username); - this.$.userlink.setContent('@' + inEvent.username); - this.username = inEvent.username; - }, - logout: function(inSender, inEvent) { - this.setLoggedIn(false); - }, - spewToggle: function(inSender, inEvent) { - this.postShowing = !this.postShowing; - this.bubble('onPostVisibility', {showing: this.postShowing}); - }, - postVisibilityUpdate: function(inSender, inEvent) { - this.postShowing = inEvent.showing; - this.$.spewButton.addRemoveClass('active', inEvent.showing); - } + name: "blerg.Controls", + kind: "Control", + classes: "blerg-controls", + username: null, + postShowing: false, + published: { + loggedIn: false + }, + handlers: { + onLogin: "login", + onLogout: "logout", + onPostVisibility: "postVisibilityUpdate", + onClearFeedStatus: "clearFeedStatus" + }, + components: [ + {name: "loggedOutControls", components: [ + {tag: "form", onsubmit: "loginClicked", classes: "login", components: [ + {kind: "onyx.Groupbox", components: [ + {kind: "onyx.InputDecorator", components: [ + {name: "username", kind: "onyx.Input", placeholder: "Username", attributes: {tabindex: 1}} + ]}, + {kind: "onyx.InputDecorator", components: [ + {name: "password", kind: "onyx.Input", placeholder: "Password", type: "password", attributes: {tabindex: 2}} + ]}, + ]}, + {kind: "onyx.Button", content: "Login", onclick: "loginClicked", attributes: {tabindex: 3}} + ]} + ]}, + {name: "loggedInControls", showing: false, components: [ + {name: "greeting", classes: "blerg-controls-greeting", components: [ + {tag: null, content: "Hello, "}, + {name: "userlink", tag: "a"}, + {tag: null, content: ". "}, + {kind: "blerg.Link", content: "Logout", onNavigate: "logoutClicked"}, + {tag: null, content: "."}, + {tag: "br"}, + {kind: "blerg.Link", content: "Change Password", onNavigate: "changePasswordClicked"}, + {tag: null, content: "."} + ]}, + {classes: "blerg-controls-toolbar", components: [ + {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: "api", kind: "blerg.API", + onFeedInfo: "gotFeedInfo"} + ], + showRSS: function(url) { + this.$.rssButton.show(); + if (url) + this.$.rssButton.setAttribute('href', url); + }, + hideRSS: function() { + this.$.rssButton.hide(); + }, + loggedInChanged: function() { + if (this.loggedIn) { + this.$.loggedOutControls.hide(); + this.$.loggedInControls.show(); + } else { + this.$.loggedOutControls.show(); + this.$.loggedInControls.hide(); + } + }, + loginClicked: function(inSender, inEvent) { + this.bubble('onTryLogin', { + username: this.$.username.getValue(), + password: this.$.password.getValue() + }); + inEvent.preventDefault(); + return true; + }, + logoutClicked: function() { + this.bubble('onTryLogout'); + return true; + }, + login: function(inSender, inEvent) { + this.$.password.setValue(''); + this.setLoggedIn(true); + this.$.userlink.setAttribute('href', '/#' + inEvent.username); + this.$.userlink.setContent('@' + inEvent.username); + this.username = inEvent.username; + + this.updateFeedInfo(); + this.feedStatusUpdateInterval = setInterval(function() { + this.updateFeedInfo(); + }.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; + this.bubble('onPostVisibility', {showing: this.postShowing}); + }, + postVisibilityUpdate: function(inSender, inEvent) { + this.postShowing = inEvent.showing; + this.$.spewButton.addRemoveClass('active', inEvent.showing); + }, + updateFeedInfo: function() { + this.$.api.getFeedInfo(); + }, + gotFeedInfo: function(inSender, inEvent) { + this.$.feedButton.addRemoveClass('new', inEvent.new > 0); + if (inEvent.new > 0) { + this.$.feedButton.setContent('Stalk Your Victims (' + inEvent.new + ')'); + } else { + this.$.feedButton.setContent('Stalk Your Victims'); + } + }, + chatterClicked: function() { + window.location.href = '/#/ref/' + this.username; + this.bubble('onNavigate'); + }, + feedClicked: function() { + window.location.href = '/#/feed'; + this.bubble('onNavigate'); + }, + clearFeedStatus: function() { + this.gotFeedInfo(this, {new: 0}); + } });