-
-
Save rmanalan/142248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // max of 140 chars is recommended, but it really allows 160 | |
| const STATUS_MAXLEN = 140; | |
| CmdUtils.CreateCommand({ | |
| name: "connect", | |
| takes: {status: noun_arb_text}, | |
| // borrowed the code written by: | |
| homepage: "http://theunfocused.net/moz/ubiquity/verbs/", | |
| author: {name: "Blair McBride", homepage: "http://theunfocused.net/"}, | |
| license: "MPL", | |
| preview: function(previewBlock, statusText) { | |
| var previewTemplate = "Updates your Connect status to: <br/>" + | |
| "<b>${status}</b><br /><br />" + | |
| "Characters remaining: <b>${chars}</b>"; | |
| var truncateTemplate = "<br />The last <b>${truncate}</b> " + | |
| "characters will be truncated!"; | |
| var previewData = { | |
| status: statusText.text, | |
| chars: STATUS_MAXLEN - statusText.text.length | |
| }; | |
| var previewHTML = CmdUtils.renderTemplate(previewTemplate, | |
| previewData); | |
| if(previewData.chars < 0) { | |
| var truncateData = { | |
| truncate: 0 - previewData.chars | |
| }; | |
| previewHTML += CmdUtils.renderTemplate(truncateTemplate, | |
| truncateData); | |
| } | |
| previewBlock.innerHTML = previewHTML; | |
| }, | |
| execute: function(statusText) { | |
| if(statusText.text.length < 1) { | |
| displayMessage("Connect requires a status to be entered"); | |
| return; | |
| } | |
| var updateUrl = "http://connect.oraclecorp.com/activities/update_status"; | |
| var updateParams = { | |
| status: statusText.text | |
| }; | |
| jQuery.ajax({ | |
| type: "POST", | |
| url: updateUrl, | |
| data: updateParams, | |
| dataType: "json", | |
| error: function(http) { | |
| if (http.status == 200) displayMessage("Connect status updated"); | |
| else displayMessage("ERROR: Connect status not updated"); | |
| }, | |
| success: function() { | |
| displayMessage("Connect status updated"); | |
| } | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment