User:Technical 13/SandBox/Gadget-BugStatusUpdate.js/sandbox.js: Difference between revisions
Content deleted Content added
Technical 13 (talk | contribs) Testing ground... Recreate this process as a function so I can use it recursively if there is a failure. |
Technical 13 (talk | contribs) wth... |
||
(6 intermediate revisions by the same user not shown) | |||
Line 10:
*/
(function
// // Create function to retrieve bug statuses
function bugStatus(){
$.ajax({
url: target,
dataType: 'jsonp',
data: getParams( ids ),
success: function ( data ) {
var color = {
"RESOLVED": "green",
"CRITICAL": "red"
},
statusProps = {
'font-weight': 'bold',
'font-size': '1.5em',
'text-transform': 'uppercase'
};
if ( data.result.bugs ) {
for( var b in data.result.bugs ) {
// //find the right bug to update
var $item = $( '.mw-trackedTemplate' ).find( 'a[title^="bugzilla:' + data.result.bugs[b].id + '"]' );
var title = $( '.trakbug-' + data.result.bugs[b].id );
if( title ) {
title.text( data.result.bugs[b].summary );
}
if( $item ) {
// // Find child, if it exists.
$status = $item
.parent()
.next( 'p' )
.children( 'span' );
// //create the status element if it does not exist
if( $status.length === 0 ){
$item
.parent()
.parent()
.append(
$( '<p />' ).append(
$( '<span />' ).css( statusProps )
.text( 'Status' )
)
);
}
// // Udpate the status element.
$item
.parent()
.next( 'p' )
.children( 'span' )
.css( 'color', color[data.result.bugs[b].status] || '#333333' )
.text( data.result.bugs[b].status );
$status = null;
}
}
}
error: function ( foo, data, error ) {
/* Using this string with 49741 being a ticket I can't see:
https://bugzilla.wikimedia.org/jsonrpc.cgi?method=Bug.get&id=158¶ms=[{%20%22ids%22:%20[35810,35909,300,48745,49741,54598],%22include_fields%22:[%22last_change_time%22,%22status%22,%20%22id%22,%20%22summary%22]}]
returns:
{"error":{"message":"You are not authorized to access bug #49741. To see this bug, you must first log in to an account with the appropriate permissions.","code":102},"id":"158","result":null}
*/
console.error( 'Foo: %o\nRaw data: %o\nError: %o', foo, data, error );
console.error( 'id array: %o', ids );
}
});
}
var ids = [], target = 'https://bugzilla.wikimedia.org/jsonrpc.cgi';
Line 28 ⟶ 92:
}
// Make jsonp request
bugStatus();
})(jQuery);
|