User:Robmoen/bugStatusUpdate.js

/* * Bug Status Update Gadget * Author: Robmoen (robm) * Description: *   Finds and updates bug status templates on page load. * * Uses Bugzilla JSON RPC api

*/

(function($){	var					ids = [],			bugs = [],						params = {},			target = 'https://bugzilla.wikimedia.org/jsonrpc.cgi';	var getParams = function (ids) {		return 'method=Bug.get&id=158&params=[ { "ids": ['+ ids.join(',') +'],"include_fields":["last_change_time","status", "id"]}]';	};

$('.mw-trackedTemplate').each(function {		var title = $(this).find('a[title^="bugzilla:"]').attr('title');		ids.push(title.split(':')[1]);		bugs.push( $( this ) );	});

params = $.param({		method: 'Bug.get',		id: 158,		params: [{			'ids': ids,			'include_fields':['last_change_time','status', 'id']		}]

});

$.ajax({		url: target,		dataType:'jsonp',		data: getParams(ids),		success: function (data) {			var color = {				"RESOLVED": "green",				"CRITICAL": "red"			};			if(data.result.bugs) {				for(var b in data.result.bugs) {					console.log(data.result.bugs[b].status);					//find item					$item = $('.mw-trackedTemplate')						.find('a[title^="bugzilla:'+data.result.bugs[b].id+'"]');

if($item) { //find child, if exists $status = $item .parent .next('p') .children('span'); //create the status element if it does not exist if($status.length === 0){ console.log('got here'); $item .parent .parent .append(									$('').append( $(' ').css({'font-weight': 'bold', 'font-size': '1.5em', 'text-transform': 'uppercase'}).text('Status') )								);						}						$item .parent .next('p') .children('span') .css('color', color[data.result.bugs[b].status]) .text(data.result.bugs[b].status); $status = null;

} //if item

} //end foreach }			}	});

})(jQuery);