SPICEWORKS.plugin.add(     { name:"Bulk Delete and Close/Open Ticket(s)", version:"0.3", description:"Allows you to :\ndelete in a bulk, even if they are not closed.\nClose/Open in a bulk, Relying on the Ticket(s) state (if the ticket is open it will closed and contrary) Updating the user according to the Email Notifications settings.\nAdds checkbox left side of each ticket line", guid:"p-7c080a80-c16c-012c-ce32-001e0b1c8c8a-1274862188", settings:{}, contentAreas: [{"content_type":"image/png","updated_at":"2010/06/29 10:33:25 +0100","id":41,"description":null,"content_name":"clopen.png","user_id":null},{"content_type":"text/javascript","updated_at":"2010/06/29 10:33:25 +0100","id":42,"description":null,"content_name":"initialize.js","user_id":null},{"content_type":"text/css","updated_at":"2010/06/29 10:33:25 +0100","id":43,"description":null,"content_name":"plugin.css","user_id":null}], initialize:function(plugin){ SPICEWORKS.app.helpdesk.ready(function(){
  var toolbarDInsert = '<a class="delete toolbar_buton" href="#" id="plugin-Dactions"><span class="inner icon">Delete Ticket(s)</span></a>';
  var toolbarCInsert = '<a class="clopen toolbar_buton" href="#" id="plugin-Cactions"><span class="inner icon">Close/Open Ticket(s)</span></a>';
  var cbInsert = '<span style="float:left;"><input type="checkbox" class="plugin-operation" name="cbselection" /></span>';
  var HdInsert = 'div#ticket-list-body table tr td.cell-status';
  var thinsert = '<div style="display:none;"><span>CheckAll</span></div>'; 
  var thloc = $$('div#ticket-list table tr th.cell-status');
  plugin.includeStyles();  

  var insertth = function(actions){
    actions.style.width = '34px';
    actions.insert({top:thinsert});
    };

  $('main-toolbar').insert(toolbarCInsert);
  $('main-toolbar').insert(toolbarDInsert);  
  thloc.each(insertth);

    var insertcheckbox = function(actions){
    actions.style.width = '34px';
    actions.insert({top:cbInsert});
    };

    $$(HdInsert).each(insertcheckbox);


  $('plugin-Dactions').observe('click', function(event){
    event.stop();
    var entries = $$('input.plugin-operation').select(function(input){
      return input.checked;
    }).collect(function(input){
      return input.up('tr').id.replace('ticket-', '');
    });
    if(entries.size() > 0){    
    var answer = confirm('You are about to delete ' + entries.size() + ' Ticket(s). \nThere is no way to undo this action. Are you sure you want to delete ?') ;   
    if (answer){
      entries.each(function(entry){ new Ajax.Request('/tickets/delete/' + entry);
      });
    }    }
    if(entries.size() <= 0){
    alert('No ticket(s) selected, please select at least one ticket to delete');    
    } 
  });

  $('plugin-Cactions').observe('click', function(event){
    event.stop();
    var entries = $$('input.plugin-operation').select(function(input){
      return input.checked;
    }).collect(function(input){
      return input.up('tr').id.replace('ticket-', '');
    });
    if(entries.size() > 0){    
    var answer = confirm('You are about to Close / Open ' + entries.size() + ' Ticket(s) Relying on the Ticket(s) state. \nContinue ?') ;   
    if (answer){
      entries.each(function(entry){ new Ajax.Request('/tickets/toggle_status/' + entry);
      });
    }}  
    if(entries.size() <= 0){
    alert('No ticket(s) selected, please select at least one ticket');    
    }
  });
});

      }
    }
 );
