2 name: "blerg.Controls",
4 classes: "blerg-controls",
13 onPostVisibility: "postVisibilityUpdate"
16 {name: "loggedOutControls", components: [
17 {tag: "form", onkeyup: "loginKeyUp", classes: "login", components: [
18 {kind: "onyx.Groupbox", components: [
19 {kind: "onyx.InputDecorator", components: [
20 {name: "username", kind: "onyx.Input", placeholder: "Username", attributes: {tabindex: 1}}
22 {kind: "onyx.InputDecorator", components: [
23 {name: "password", kind: "onyx.Input", placeholder: "Password", type: "password", attributes: {tabindex: 2}}
26 {kind: "onyx.Button", content: "Login", onclick: "loginClicked", attributes: {tabindex: 3}}
29 {name: "loggedInControls", showing: false, components: [
30 {name: "greeting", classes: "blerg-controls-greeting", components: [
31 {tag: null, content: "Hello, "},
32 {name: "userlink", tag: "a"},
33 {tag: null, content: ". "},
34 {kind: "blerg.Link", content: "Logout", onNavigate: "logoutClicked"},
35 {tag: null, content: "."},
37 {kind: "blerg.Link", content: "Account Center", href: '/#/account'},
38 {tag: null, content: "."}
40 {classes: "blerg-controls-toolbar", components: [
41 {name: "mentionButton", kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"},
42 {name: "feedButton", kind: "onyx.Button", classes: "feed-button", content: "Stalk Your Victims", onclick: "feedClicked"},
43 {name: "spewButton", kind: "onyx.Button", classes: "spew-button", content: "Spew It!", onclick: "spewToggle"}
46 {name: "api", kind: "blerg.API",
47 onStatus: "gotStatus"},
49 onClearNotification: "clearNotification"}
51 showRSS: function(url) {
52 this.$.rssButton.show();
54 this.$.rssButton.setAttribute('href', url);
57 this.$.rssButton.hide();
59 loggedInChanged: function() {
61 this.$.loggedOutControls.hide();
62 this.$.loggedInControls.show();
64 this.$.loggedOutControls.show();
65 this.$.loggedInControls.hide();
68 loginClicked: function(inSender, inEvent) {
69 this.bubble('onTryLogin', {
70 username: this.$.username.getValue(),
71 password: this.$.password.getValue()
73 inEvent.preventDefault();
76 loginKeyUp: function(inSender, inEvent) {
77 if (inEvent.keyCode == 13) {
78 if (this.$.username.hasFocus()) {
79 this.$.password.focus();
81 this.loginClicked(this, inEvent);
86 logoutClicked: function() {
87 this.bubble('onTryLogout');
90 login: function(inSender, inEvent) {
91 this.$.password.setValue('');
92 // TODO: Replace with regular blur() call in future enyo
93 this.$.password.node.blur();
94 this.setLoggedIn(true);
95 this.$.userlink.setAttribute('href', '/#' + inEvent.username);
96 this.$.userlink.setContent('@' + inEvent.username);
97 this.username = inEvent.username;
100 this.feedStatusUpdateInterval = setInterval(function() {
102 }.bind(this), 900000);
104 logout: function(inSender, inEvent) {
105 this.setLoggedIn(false);
106 clearInterval(this.feedStatusUpdateInterval);
108 changePasswordClicked: function() {
109 this.bubble('onShowChangePassword');
111 spewToggle: function(inSender, inEvent) {
112 this.postShowing = !this.postShowing;
113 this.bubble('onPostVisibility', {showing: this.postShowing});
115 postVisibilityUpdate: function(inSender, inEvent) {
116 this.postShowing = inEvent.showing;
117 this.$.spewButton.addRemoveClass('active', inEvent.showing);
119 updateStatus: function() {
120 this.$.api.getStatus();
122 gotStatus: function(inSender, inEvent) {
123 if ('mentioned' in inEvent) {
124 this.$.mentionButton.addRemoveClass('new', inEvent.mentioned);
126 if ('feed_new' in inEvent) {
127 this.$.feedButton.addRemoveClass('new', inEvent.feed_new > 0);
128 if (inEvent.feed_new > 0) {
129 this.$.feedButton.setContent('Stalk Your Victims (' + inEvent.feed_new + ')');
131 this.$.feedButton.setContent('Stalk Your Victims');
135 chatterClicked: function() {
136 window.location.href = '/#/ref/' + this.username;
137 this.bubble('onNavigate');
139 feedClicked: function() {
140 window.location.href = '/#/feed';
141 this.bubble('onNavigate');
143 clearNotification: function(inSender, inEvent) {
144 if (inEvent.type == 'feed') {
145 this.gotStatus(this, {feed_new: 0});
146 } else if (inEvent.type == 'mentioned') {
147 this.gotStatus(this, {mentioned: false});