SPICEWORKS.plugin.add(     { name:"Help Desk customizations", version:"0.2", description:"Adds minor enhancements to your Help Desk, including ticket status in the toolbar, increased ticket window height, colors for past due tickets and private messages, and information on devices in the Related To field.", guid:"p-a55c56f0-aacd-012b-3354-0016353cc494-1233680343", settings:{"past_due_color":"#ffdede","private_note_color":"#e3eaf2"}, contentAreas: [{"content_type":"text/javascript","updated_at":"2010/01/04 12:38:16 +0000","id":2,"description":null,"content_name":"initialize.js","user_id":null}], initialize:function(plugin){ // ==SPICEWORKS-PLUGIN==
// @name          Help Desk customizations
// @description   Adds minor enhancements to your Help Desk, including ticket status in the toolbar, increased ticket window height, colors for past due tickets and private messages, and information on devices in the Related To field.
// @version       0.2
// ==/SPICEWORKS-PLUGIN==  
// Name, description and version should be modified in the section above.
// Add your code here.  

plugin.configure({
	settingDefinitions: [
		{name: 'past_due_color', label: 'Past Due Highlight Color', type: 'string', defaultValue: '#ffdede', example: 'Default: #ffdede'},
		{name: 'private_note_color', label: 'Private Note Color', type: 'string', defaultValue: '#e3eaf2', example: 'Default: #e3eaf2'}
	]
});

SPICEWORKS.app.helpdesk.ready(function(){
	// increase window size
	SPICEWORKS.utils.addStyle("body.tickets #active_overview {height: 500px !important;}");

	// mark past due ticket rows
	$$('td.past_due').each(function(item){
		item.up().setStyle({backgroundColor: plugin.settings.past_due_color});
	});

	// display ticket stats
	var numOpenTickets = SPICEWORKS.data.Ticket.find('all', {filter:'open'}).length;
	var numPastDue = SPICEWORKS.data.Ticket.find('all', {filter:'past_due'}).length;
	$('toolbar').down('span.advanced_controls').insert('<span style="font-size: 1em; color: #000; float: right; background: #e8e8e8; padding: 3px 5px; border: #888 1px solid;"><strong>Open Tickets:</strong> ' + numOpenTickets + '&nbsp;&nbsp;&nbsp;<strong>Past Due:</strong> ' + numPastDue + '</span>');
});

SPICEWORKS.app.helpdesk.ticket.ready(function(){
	// color private messages
	$$('li.private').each(function(item){
		item.setStyle({backgroundColor: plugin.settings.private_note_color})
	});

	// add device summary
	var deviceLink = $('ticket_review_summary_view').down('p.related_to a');
	if(deviceLink) {
		var deviceURL = deviceLink.readAttribute('href');
		var startIndex = deviceURL.indexOf('id-');
		if(startIndex != -1) {
		var substring = deviceURL.substring(startIndex);
		var deviceID = substring.gsub(/[^\d]/, '');
		var device = SPICEWORKS.data.Device.find(deviceID);
		if(device) {
			var displayInfo = '<div id="related_to_summary" style="display: none; clear: both; border:1px solid #ccc; padding: 10px; margin: 5px 0; overflow: hidden;"><ul style="margin: 0; padding: 0;">'
			var listStyle = '<li style="float: left; width: 200px;">'
			if(device.ip_address && !device.ip_address.empty()) {
				displayInfo += listStyle + '<strong>IP:</strong> ' + device.ip_address + '</li>';
			}
			if(device.mac_address && !device.mac_address.empty()) {
				displayInfo += listStyle + '<strong>MAC:</strong> ' + device.mac_address + '</li>';
			}
			if(device.manufacturer && !device.manufacturer.empty()) {
				displayInfo += listStyle + '<strong>Vendor:</strong> ' + device.manufacturer + '</li>';	
			}
			if(device.current_user && !device.current_user.empty()) {
				displayInfo += listStyle + '<strong>Last Login:</strong> ' + device.current_user + '</li>';
			}
			if(device.primary_owner_name && !device.primary_owner_name.empty()) {
				displayInfo += listStyle + '<strong>Owner:</strong> ' + device.primary_owner_name + '</li>';
			}
			if(device.asset_tag && !device.asset_tag.empty()) {
				displayInfo += listStyle + '<strong>Asset Tag:</strong> ' + device.asset_tag + '</li>';
			}
			if(device.operating_system && !device.operating_system.empty()) {
				displayInfo += listStyle + '<strong>OS:</strong> ' + device.operating_system + '</li>';
			}
			if(device.serial_number && !device.serial_number.empty()) {
				displayInfo += listStyle + '<strong>Serial No:</strong> ' + device.serial_number + '</li>';
			}
			displayInfo += '</ul><p style="float: right;"><a href="#" onclick="new Effect.BlindUp(\'related_to_summary\', {duration:0.20}); return false;">hide</a></p></div>';
			$('ticket_purchase_container').insert({after: displayInfo});
			deviceLink.insert({after: '&nbsp;&nbsp;(<a href="#" onclick="new Effect.BlindDown(\'related_to_summary\', {duration:0.20}); return false;">info</a>)'})
		}
		}
	}
});

      }
    }
 );
