SPICEWORKS.plugin.add(     { name:"Ticket Gauge", version:"0.3", description:"Displays a gauge showing the number of open tickets in your helpdesk.", guid:"p-c9fd4f10-d118-012b-476a-0011856b5722-1233378232", settings:{"yellowstart":"10","redstart":"15"}, contentAreas: [{"content_type":"text/javascript","updated_at":"2010/01/04 12:38:16 +0000","id":6,"description":null,"content_name":"initialize.js","user_id":null}], initialize:function(plugin){ // ==SPICEWORKS-PLUGIN==
// @name          Ticket Gauge
// @description  Displays a gauge showing the number of open tickets in your helpdesk.
// @version       0.3
// ==/SPICEWORKS-PLUGIN==





plugin.configure({
   settingDefinitions:[
    { name:'yellowstart', label:'Yellow Line Begins', type:'integer', defaultValue:10, example:'Where does the yellow line start: 15'},
    { name:'redstart', label:'Red Line Begins', type:'integer', defaultValue:15, example:'Where does the redline start: 15'}
   ]
 });

SPICEWORKS.app.dashboard.addWidgetType({
 name: 'open_tickets',
 label: 'Open Tickets',



 update: function (element, settings) {


   var pieElem = new Element('div', {id: 'pie_chart', align: 'center', style: 'align:"middle";width:200px;height:225px'});
   element.insert(pieElem);
   element.align='center';
   SPICEWORKS.utils.google.withVisualizations( ['gauge'], function (viz) {

     gaugeData = new viz.DataTable();
     gaugeData.addColumn('number', 'Open Tickets');

     yl = parseInt(plugin.settings.yellowstart);
     if(!yl) yl = 10;

     rl = parseInt(plugin.settings.redstart);
     if (!rl) rl = 15;
     if (rl < yl) {t = rl; rl = yl; yl = t;}

     tkt_ct = 
(new Ajax.Request('/api/tickets.json?total_count=true&filter=open', {method:'get', asynchronous:false})).transport.responseText.evalJSON().count;
     tkt_max = tkt_ct > rl+5 ? tkt_ct : rl+5;
     gaugeData.addRows(1);
     gaugeData.setCell(0, 0, tkt_ct);

     gauge = new viz.Gauge(pieElem);
     gaugeOptions = {
       min: 0,
       max: tkt_max,
       yellowFrom: yl,
       yellowTo: rl,
       redFrom: rl,
       redTo: tkt_max,
       minorTicks: 5
     };
     gauge.draw(gaugeData, gaugeOptions);

    });

 }
})



      }
    }
 );
