The javascript to populate the portlet. JQuery is available as 'Q' and console.log() is ensured to work even in IE.
The js is called in a function context with variables defined:
- divId: The id of an empty div content can be written to with jquery
- rootUrl: The jenkins root url
- ajaxViaJenkins: a function to proxy ajax requests via jenkins in order to avoid the cross domain security
restrictions (see https://wiki.jenkins-ci.org/display/JENKINS/AJAX+with+JavaScript+proxy for implementation details). The first
argument is the url, as a second and third argument credentials can be passed in (optional). The last argument is the callback
function that receives the response object.
Examples
// Google Search Form
var googleUrl = 'http://www.google.com';
Q('#'+divId).html('Loading google home page result...');
ajaxViaJenkins(googleUrl, function(resp) {
Q('#'+divId).html('Processing response (link rewriting, replacing this content)...');
var responseText = resp.responseText.replace(/(\/search)/g, googleUrl + '$1');
var responseDom = Q("<div>").append(responseText);
Q('#'+divId).html( responseDom.find("form").first());
});
// Load JSON from API with authentication
var url = 'http://myservice.intranet/api/rest';
Q('#'+divId).html('Loading portlet...');
ajaxViaJenkins(url, "myuser", "password", function(resp) {
var jsonObject = resp.responseObject();
...
});