X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=sidebyside;f=www%2Fjssrc%2Fblerg%2FPost.js;h=0c72a99332bf1cc07efeb342005534031e9f5da5;hb=4377f9e224f34c05e7a5de04f390bb2a0cabf6eb;hp=1f7ea7da4bb10e448031721dbfa9a2d2f2b83934;hpb=80ad774f55998cc11e08694245dfd6cb1b49a86f;p=blerg.git diff --git a/www/jssrc/blerg/Post.js b/www/jssrc/blerg/Post.js index 1f7ea7d..0c72a99 100644 --- a/www/jssrc/blerg/Post.js +++ b/www/jssrc/blerg/Post.js @@ -3,19 +3,28 @@ enyo.kind({ kind: "Control", classes: "blerg-post", handlers: { - onPostVisibility: "postVisibilityUpdate" + onPostVisibility: "postVisibilityUpdate", + onLogin: "loggedIn", + onLogout: "loggedOut" }, resizePostContentTimeout: null, components: [ {tag: "h2", content: "What's on your mind?"}, {kind: "onyx.InputDecorator", components: [ - {name: "postContent", classes: "content", kind: "onyx.TextArea", onkeydown: "resizePostContent"} + {name: "postContent", classes: "content", kind: "onyx.TextArea", onkeydown: "resizePostContent", attributes: {tabindex: 4}} ]}, {classes: "buttons", components: [ - {kind: "onyx.Button", content: "Close", onclick: "closePost", classes: "onyx-negative"}, - {kind: "onyx.Button", content: "Post", onclick: "doPost", classes: "onyx-affirmative"} - ]} + {name: "loginReminder", tag: "span", classes: "blerg-error", style: "margin-right: 8px; vertical-align: 60%", content: "You must log in before posting."}, + {kind: "onyx.Button", content: "Close", onclick: "closePost", classes: "onyx-negative", attributes: {tabindex: 6}}, + {name: "postButton", kind: "onyx.Button", content: "Post", onclick: "doPost", classes: "onyx-affirmative", disabled: true, attributes: {tabindex: 5}} + ]}, + {name: "api", kind: "blerg.API", + onPostSuccessful: "postSuccessful", + onPostFailed: "postFailed"} ], + create: function() { + this.inherited(arguments); + }, getData: function() { return this.$.postContent.getValue(); }, @@ -26,13 +35,28 @@ enyo.kind({ this.bubble('onPostVisibility', {showing: false}); }, doPost: function() { - this.bubble('onPost', {data: this.getData()}); + this.$.api.post(this.getData()); + }, + postSuccessful: function() { + this.setData(''); + this.closePost(); + if (location.hash != '#' + blerg.API.username) { + qlink(blerg.API.username); + } else { + this.bubble('onReload'); + } + }, + postFailed: function() { + alert('Could not post!'); }, postVisibilityUpdate: function(inSender, inEvent) { if (inEvent.showing) { this.show(); - if (inEvent.data && this.getData() == "") + this.$.postContent.focus(); + if (inEvent.data && this.getData() == "") { this.setData(inEvent.data); + this.$.postContent.node.setSelectionRange(inEvent.data.length, inEvent.data.length); + } } else { this.hide(); } @@ -56,5 +80,13 @@ enyo.kind({ } this.resizePostContentTimeout = null; }.bind(this), 150); + }, + loggedIn: function() { + this.$.postButton.setDisabled(false); + this.$.loginReminder.hide(); + }, + loggedOut: function() { + this.$.postButton.setDisabled(true); + this.$.loginReminder.show(); } });