508cd608319562e79c8d617c95804bd2d99c37cc
[blerg.git] / www / jssrc / blerg / Controls.js
1 enyo.kind({
2         name: "blerg.Controls",
3         kind: "Control",
4         style: "float: right",
5         classes: "blerg-controls",
6         username: null,
7         published: {
8                 loggedIn: false
9         },
10         handlers: {
11                 onLogin: "login",
12                 onLogout: "logout"
13         },
14         components: [
15                 {name: "loggedOutControls", components: [
16                         {tag: "form", onsubmit: "loginClicked", classes: "login", components: [
17                                 {kind: "onyx.Groupbox", components: [
18                                         {kind: "onyx.InputDecorator", components: [
19                                                 {name: "username", kind: "onyx.Input", placeholder: "Username"}
20                                         ]},
21                                         {kind: "onyx.InputDecorator", components: [
22                                                 {name: "password", kind: "onyx.Input", placeholder: "Password", type: "password"}
23                                         ]},
24                                 ]},
25                                 {kind: "onyx.Button", content: "Login", onclick: "loginClicked"}
26                         ]}
27                 ]},
28                 {name: "loggedInControls", showing: false, components: [
29                         {name: "greeting", components: [
30                                 {noDom: true, content: "Hello, "},
31                                 {name: "userlink", tag: "a"},
32                                 {noDom: true, content: "."}
33                         ]},
34                         {classes: "onyx-toolbar-inline", components: [
35                                 {kind: "onyx.Button", content: "Write", onclick: "writeClicked"},
36                                 {kind: "onyx.Button", content: "Hearsay", onclick: "chatterClicked"},
37                                 {kind: "onyx.Button", content: "Stalking", onclick: "feedClicked"},
38                                 {kind: "onyx.Button", content: "Logout", onclick: "logoutClicked"}
39                         ]},
40                         {components: [
41                                 {name: "rssButton", showing: false, kind: "blerg.Link", components: [
42                                         {kind: "Image", src: "/images/rss.png", width: 16, height: 16},
43                                         {noDom: true, content: " RSS"}
44                                 ]}
45                         ]}
46                 ]}
47         ],
48         showRSS: function(url) {
49                 this.$.rssButton.show();
50                 if (url)
51                         this.$.rssButton.setAttribute('href', url);
52         },
53         hideRSS: function() {
54                 this.$.rssButton.hide();
55         },
56         loggedInChanged: function() {
57                 if (this.loggedIn) {
58                         this.$.loggedOutControls.hide();
59                         this.$.loggedInControls.show();
60                 } else {
61                         this.$.loggedOutControls.show();
62                         this.$.loggedInControls.hide();
63                 }
64         },
65         loginClicked: function(inSender, inEvent) {
66                 this.bubble('onTryLogin', {
67                         username: this.$.username.getValue(),
68                         password: this.$.password.getValue()
69                 });
70                 inEvent.preventDefault();
71                 return true;
72         },
73         logoutClicked: function() {
74                 this.bubble('onTryLogout');
75         },
76         login: function(inSender, inEvent) {
77                 this.$.password.setValue('');
78                 this.setLoggedIn(true);
79                 this.$.userlink.setAttribute('href', '/#' + inEvent.username);
80                 this.$.userlink.setContent('@' + inEvent.username);
81                 this.username = inEvent.username;
82         },
83         logout: function(inSender, inEvent) {
84                 this.setLoggedIn(false);
85         }
86 });