X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FControls.js;fp=www%2Fjssrc%2Fblerg%2FControls.js;h=508cd608319562e79c8d617c95804bd2d99c37cc;hb=be0647e6531fec4b4b50a1a0c0d4e826e5e6f16b;hp=4ef8a41b9ff214fd255cf27d71c5357cc490e3df;hpb=21db04ef3e4f66d7b5c4c9be2be36703b18cbcaa;p=blerg.git diff --git a/www/jssrc/blerg/Controls.js b/www/jssrc/blerg/Controls.js index 4ef8a41..508cd60 100644 --- a/www/jssrc/blerg/Controls.js +++ b/www/jssrc/blerg/Controls.js @@ -3,12 +3,17 @@ enyo.kind({ kind: "Control", style: "float: right", classes: "blerg-controls", + username: null, published: { loggedIn: false }, + handlers: { + onLogin: "login", + onLogout: "logout" + }, components: [ {name: "loggedOutControls", components: [ - {tag: "form", onsubmit: "doLogin", classes: "login", components: [ + {tag: "form", onsubmit: "loginClicked", classes: "login", components: [ {kind: "onyx.Groupbox", components: [ {kind: "onyx.InputDecorator", components: [ {name: "username", kind: "onyx.Input", placeholder: "Username"} @@ -17,15 +22,20 @@ enyo.kind({ {name: "password", kind: "onyx.Input", placeholder: "Password", type: "password"} ]}, ]}, - {kind: "onyx.Button", content: "Login", onclick: "doLogin"} + {kind: "onyx.Button", content: "Login", onclick: "loginClicked"} ]} ]}, {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"} + {name: "greeting", components: [ + {noDom: true, content: "Hello, "}, + {name: "userlink", tag: "a"}, + {noDom: true, content: "."} + ]}, + {classes: "onyx-toolbar-inline", components: [ + {kind: "onyx.Button", content: "Write", onclick: "writeClicked"}, + {kind: "onyx.Button", content: "Hearsay", onclick: "chatterClicked"}, + {kind: "onyx.Button", content: "Stalking", onclick: "feedClicked"}, + {kind: "onyx.Button", content: "Logout", onclick: "logoutClicked"} ]}, {components: [ {name: "rssButton", showing: false, kind: "blerg.Link", components: [ @@ -52,10 +62,25 @@ enyo.kind({ this.$.loggedInControls.hide(); } }, - doLogin: function() { + loginClicked: function(inSender, inEvent) { this.bubble('onTryLogin', { username: this.$.username.getValue(), password: this.$.password.getValue() }); + inEvent.preventDefault(); + return true; + }, + logoutClicked: function() { + this.bubble('onTryLogout'); + }, + 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); } });