kneath (owner)

Forks

Revisions

gist: 9337 Download_button fork
public
Public Clone URL: git://gist.github.com/9337.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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");
      }
    });
  }
});