Mercurial > snowl
changeset 362:fffaeb8f1950
give the user feedback about the send while it is occurring
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Tue, 04 Nov 2008 18:34:10 -0800 |
parents | edb03b1ae143 |
children | 61e5d18f4428 |
files | content/icons/email_go.png content/stream.css content/stream.js content/stream.xul locale/en-US/stream.dtd locale/en-US/stream.properties modules/twitter.js |
diffstat | 7 files changed, 91 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/content/stream.css Tue Nov 04 15:09:35 2008 -0800 +++ b/content/stream.css Tue Nov 04 18:34:10 2008 -0800 @@ -124,6 +124,15 @@ -moz-appearance: treetwistyopen; } +#sendButton { + list-style-image: url(chrome://snowl/content/icons/email_go.png); +} + +#sendButton[state="sending"] { + list-style-image: url(chrome://global/skin/icons/loading_16.png); +} + + /* Border styles to clarify the structure for debugging purposes. */ /*
--- a/content/stream.js Tue Nov 04 15:09:35 2008 -0800 +++ b/content/stream.js Tue Nov 04 18:34:10 2008 -0800 @@ -78,13 +78,35 @@ return this._log = Log4Moz.Service.getLogger("Snowl.Stream"); }, - // Favicon Service get _faviconSvc() { - let faviconSvc = Cc["@mozilla.org/browser/favicon-service;1"]. - getService(Ci.nsIFaviconService); delete this._faviconSvc; - this._faviconSvc = faviconSvc; - return this._faviconSvc; + return this._faviconSvc = Cc["@mozilla.org/browser/favicon-service;1"]. + getService(Ci.nsIFaviconService); + }, + + get _stringBundle() { + delete this._stringBundle; + return this._stringBundle = document.getElementById("snowlStringBundle"); + }, + + get _writeMessageButton() { + delete this._writeMessageButton; + return this._writeMessageButton = document.getElementById("snowlWriteMessageButton"); + }, + + get _writeBox() { + delete this._writeBox; + return this._writeBox = document.getElementById("writeBox"); + }, + + get _writeTextbox() { + delete this._writeTextbox; + return this._writeTextbox = document.getElementById("writeTextbox"); + }, + + get _sendButton() { + delete this._sendButton; + return this._sendButton = document.getElementById("sendButton"); }, _window: null, @@ -166,10 +188,10 @@ gBrowserWindow.Snowl._initSnowlToolbar(); // For some reason setting hidden="true" in the XUL file prevents us - // from showing the box later via writeBox.hidden = false. + // from showing the box later via writeBox.hidden = false, so we set it + // here instead. // FIXME: file a bug on this abnormality. - let writeBox = document.getElementById("writeBox"); - writeBox.hidden = true; + this._writeBox.hidden = true; this._updateWriteButton(); }, @@ -180,18 +202,16 @@ }, _setMidnightTimout: function() { - let t = this; let now = new Date(); let msUntilMidnight = SnowlDateUtils.tomorrow - now; this._log.info("setting midnight timeout for " + new Date(now.getTime() + msUntilMidnight)); - window.setTimeout(function() { t.onMidnight() }, msUntilMidnight); + window.setTimeout(function() { SnowlMessageView.onMidnight() }, msUntilMidnight); }, // Selectively show/hide the button for writing a message depending on // whether or not the user has an account that supports writing. _updateWriteButton: function() { - document.getElementById("snowlWriteMessageButton").disabled = - (SnowlService.targets.length == 0); + this._writeMessageButton.disabled = (SnowlService.targets.length == 0); }, @@ -253,18 +273,39 @@ }, onWriteMessage: function(event) { - let writeBox = document.getElementById("writeBox"); - writeBox.hidden = !event.target.checked; + this._writeBox.hidden = !event.target.checked; }, onSendMessage: function() { - let writeTextbox = document.getElementById("writeTextbox"); - let content = writeTextbox.value; - let twitter = new SnowlTwitter(); - // FIXME: if there is more than one target, let the user choose which one - // to send to. + this._sendButton.setAttribute("state", "sending"); + this._sendButton.label = this._stringBundle.getString("sendButton.label.sending"); + this._sendButton.disabled = true; + + // FIXME: if there is more than one target, let the user choose + // which one to send to. let target = SnowlService.targets[0]; - target.send(content); + let content = this._writeTextbox.value; + let callback = function() { SnowlMessageView.onMessageSent() }; + + // FIXME: pass an error callback and display a message to users on error. + target.send(content, callback); + }, + + onMessageSent: function() { + this._sendButton.setAttribute("state", "sent"); + this._sendButton.label = this._stringBundle.getString("sendButton.label.sent"); + + window.setTimeout(function() { SnowlMessageView.onMessageSentDelayed() }, 5000); + }, + + onMessageSentDelayed: function() { + this._sendButton.removeAttribute("state"); + this._sendButton.label = this._stringBundle.getString("sendButton.label"); + this._sendButton.disabled = false; + + this._writeBox.hidden = true; + this._writeMessageButton.checked = false; + this._writeTextbox.value = ""; },
--- a/content/stream.xul Tue Nov 04 15:09:35 2008 -0800 +++ b/content/stream.xul Tue Nov 04 18:34:10 2008 -0800 @@ -53,13 +53,17 @@ <script type="application/javascript" src="chrome://snowl/content/strands.js"/> <script type="application/javascript" src="chrome://snowl/content/stream.js"/> + <stringbundleset id="stringbundleset"> + <stringbundle id="snowlStringBundle" src="chrome://snowl/locale/stream.properties"/> + </stringbundleset> + <toolbar id="snowlToolbar"/> <vbox id="writeBox"> <textbox id="writeTextbox" multiline="true" rows="3"/> <hbox> <spacer flex="1"/> - <button label="Send" oncommand="SnowlMessageView.onSendMessage()"/> + <button id="sendButton" label="&sendButton.label;" oncommand="SnowlMessageView.onSendMessage()"/> </hbox> </vbox>
--- a/locale/en-US/stream.dtd Tue Nov 04 15:09:35 2008 -0800 +++ b/locale/en-US/stream.dtd Tue Nov 04 18:34:10 2008 -0800 @@ -1,1 +1,2 @@ <!ENTITY page.title "Snowl Message Stream"> +<!ENTITY sendButton.label "Send">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/locale/en-US/stream.properties Tue Nov 04 18:34:10 2008 -0800 @@ -0,0 +1,3 @@ +sendButton.label=Send +sendButton.label.sending=Sending... +sendButton.label.sent=Sent
--- a/modules/twitter.js Tue Nov 04 15:09:35 2008 -0800 +++ b/modules/twitter.js Tue Nov 04 18:34:10 2008 -0800 @@ -562,12 +562,16 @@ //**************************************************************************// // Sending - send: function(content) { + _sendCallback: null, + + send: function(content, callback) { Observers.notify(this, "snowl:send:start", null); let data = "status=" + encodeURIComponent(content); // + "&in_reply_to_status_id=" + encodeURIComponent(inReplyToID); + this._sendCallback = callback; + let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); request.QueryInterface(Ci.nsIDOMEventTarget); @@ -603,13 +607,19 @@ return; } + if (this._sendCallback) { + this._sendCallback(); + this._sendCallback = null; + } + + this._log.info("onSendLoad: " + request.responseText); + // _authInfo only gets set if we prompted the user to authenticate // and the user checked the "remember password" box. Since we're here, // it means the request succeeded, so we save the login. if (this._authInfo) this._saveLogin(); - this._log.info("onSendLoad: " + request.responseText); this._processSend(request.responseText); },