X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=sidebyside;f=www%2Fjssrc%2Fblerg%2FControls.js;h=1bbfd2dbfce858917bb609ce2c610a296c592e70;hb=80ad774f55998cc11e08694245dfd6cb1b49a86f;hp=4ef8a41b9ff214fd255cf27d71c5357cc490e3df;hpb=21db04ef3e4f66d7b5c4c9be2be36703b18cbcaa;p=blerg.git diff --git a/www/jssrc/blerg/Controls.js b/www/jssrc/blerg/Controls.js index 4ef8a41..1bbfd2d 100644 --- a/www/jssrc/blerg/Controls.js +++ b/www/jssrc/blerg/Controls.js @@ -1,61 +1,97 @@ enyo.kind({ - name: "blerg.Controls", - kind: "Control", - style: "float: right", - classes: "blerg-controls", - published: { - loggedIn: false - }, - components: [ - {name: "loggedOutControls", components: [ - {tag: "form", onsubmit: "doLogin", 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: "doLogin"} - ]} - ]}, - {name: "loggedInControls", showing: false, components: [ - {name: "greeting"}, - {kind: "onyx.Toolbar", components: [ - {kind: "onyx.Button", content: "Write", onClick: "writeClicked"}, - {kind: "onyx.Button", content: "Hearsay", onClick: "chatterClicked"}, - {kind: "onyx.Button", content: "Stalking", onClick: "feedClicked"} - ]}, - {components: [ - {name: "rssButton", showing: false, kind: "blerg.Link", components: [ - {kind: "Image", src: "/images/rss.png", width: 16, height: 16}, - {noDom: true, content: " RSS"} - ]} - ]} - ]} - ], - 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(); - } - }, - doLogin: function() { - this.bubble('onTryLogin', { - username: this.$.username.getValue(), - password: this.$.password.getValue() - }); - } + 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); + } });