Skip to content

Instantly share code, notes, and snippets.

@technoweenie
Forked from kneath/gist:9337
Created September 8, 2008 00:15

Revisions

  1. technoweenie revised this gist Sep 8, 2008. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -31,12 +31,13 @@ CmdUtils.CreateCommand({
    xhr.setRequestHeader("Content-Type", "application/json" );
    }
    })


    var statusData = '{"status": {"code_and_message": ' + statusText.text + '}}';

    jQuery.ajax({
    type: "POST",
    url: updateUrl,
    data: {"status[code_and_message]": statusText.text},
    data: statusData,
    dataType: "json",
    error: function() {
    displayMessage("XTT error - status not updated");
  2. @kneath kneath created this gist Sep 7, 2008.
    49 changes: 49 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    // Beginning of a Ubiquty script for use with xtt

    CmdUtils.CreateCommand({
    name: "xtt",
    takes: {status: noun_arb_text},

    preview: function(previewBlock, statusText) {
    var previewTemplate = "Updates your XTT status to: <br/>" +
    "<b>${status}</b><br /><br />";
    var previewData = {
    status: statusText.text
    };

    var previewHTML = CmdUtils.renderTemplate(previewTemplate,
    previewData);

    previewBlock.innerHTML = previewHTML;
    },

    execute: function(statusText) {
    if(statusText.text.length < 1) {
    displayMessage("XTT requires a status to be entered");
    return;
    }

    var updateUrl = "http://tt.entp.com/statuses.json";

    jQuery.ajaxSetup({
    'beforeSend': function(xhr) {
    xhr.setRequestHeader("Accept", "application/json");
    xhr.setRequestHeader("Content-Type", "application/json" );
    }
    })


    jQuery.ajax({
    type: "POST",
    url: updateUrl,
    data: {"status[code_and_message]": statusText.text},
    dataType: "json",
    error: function() {
    displayMessage("XTT error - status not updated");
    },
    success: function() {
    displayMessage("XTT status updated");
    }
    });
    }
    });