Revisions

gist: 13668 Download_button fork
public
Public Clone URL: git://gist.github.com/13668.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
var noun_type_trac_type = new CmdUtils.NounType( "Trac Type", ['defect', 'enhancement', 'task'])
 
CmdUtils.CreateCommand({
  name:"tickets",
  author: {name:"Fernando 'fern' Takai",email:"fernando.takai@gmail.com"},
  license:"MPL",
  icon:"http://labs.toolness.com/trac/chrome/common/trac.ico",
  takes: {'summary':noun_arb_text},
  modifiers: {'keywords':noun_arb_text, 'type':noun_type_trac_type},
  description: 'Queries Ubiquity Trac for tickets - w/o parameters, get the last 8 open tickets.',
  preview: function(pblock ,summary, mods){
    pblock.innerHTML = "<p>Getting the tickets...</p>"
    var url = "http://ubiquity.mozilla.com/trac/query?status=%21closed&format=csv&desc=1&order=id&col=id&col=summary";
    if(summary && summary.text.length > 0) url += "&summary=~" + summary.text
    if(mods.type && mods.type.text && mods.type.text.length > 0) url += "&type=" + mods.type.text
    jQuery.get(url, null, function(data){
       pblock.innerHTML = "";
      var template = "<span style='text-decoration:underline'><a href='http://ubiquity.mozilla.com/trac/ticket/${number}'>#${number}</a></span> ${title} <br />"
       data = data.split("\n");
       data = data.slice(1, data.length + 2);
       var size = 0;
       for each(var line in data){
         var splitted = line.split(",");
         if(size < 8 && splitted[1].length > 0 ){
           if(splitted[1].length > 59){
              splitted[1] = splitted[1].slice(0, 55) + "..."
           }
           pblock.innerHTML += CmdUtils.renderTemplate(template, {number:splitted[0], title:splitted[1]});
           size++;
         }
       }
    });
  }
})