Allow target being extended by Icinga.Loader.loadUrl
This commit is contained in:
parent
758fd06cfe
commit
7440d61189
|
@ -44,14 +44,18 @@
|
||||||
* @param {object} target Target jQuery element
|
* @param {object} target Target jQuery element
|
||||||
* @param {object} data Optional parameters, usually for POST requests
|
* @param {object} data Optional parameters, usually for POST requests
|
||||||
* @param {string} method HTTP method, default is 'GET'
|
* @param {string} method HTTP method, default is 'GET'
|
||||||
|
* @param {string} action How to handle the response ('replace' or 'append'), default is 'replace'
|
||||||
*/
|
*/
|
||||||
loadUrl: function (url, $target, data, method, autorefresh) {
|
loadUrl: function (url, $target, data, method, action, autorefresh) {
|
||||||
var id = null;
|
var id = null;
|
||||||
|
|
||||||
// Default method is GET
|
// Default method is GET
|
||||||
if ('undefined' === typeof method) {
|
if ('undefined' === typeof method) {
|
||||||
method = 'GET';
|
method = 'GET';
|
||||||
}
|
}
|
||||||
|
if ('undefined' === typeof action) {
|
||||||
|
action = 'replace';
|
||||||
|
}
|
||||||
if ('undefined' === typeof autorefresh) {
|
if ('undefined' === typeof autorefresh) {
|
||||||
autorefresh = false;
|
autorefresh = false;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +114,7 @@
|
||||||
req.complete(this.onComplete);
|
req.complete(this.onComplete);
|
||||||
req.historyTriggered = false;
|
req.historyTriggered = false;
|
||||||
req.autorefresh = autorefresh;
|
req.autorefresh = autorefresh;
|
||||||
|
req.action = action;
|
||||||
if (id) {
|
if (id) {
|
||||||
this.requests[id] = req;
|
this.requests[id] = req;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +190,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.loadUrl($el.data('icingaUrl'), $el, undefined, undefined, true) === false) {
|
if (self.loadUrl($el.data('icingaUrl'), $el, undefined, undefined, undefined, true) === false) {
|
||||||
self.icinga.logger.debug(
|
self.icinga.logger.debug(
|
||||||
'NOT autorefreshing ' + id + ', even if ' + interval + ' ms passed. Request pending?'
|
'NOT autorefreshing ' + id + ', even if ' + interval + ' ms passed. Request pending?'
|
||||||
);
|
);
|
||||||
|
@ -424,7 +429,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// .html() removes outer div we added above
|
// .html() removes outer div we added above
|
||||||
this.renderContentToContainer($resp.html(), req.$target);
|
this.renderContentToContainer($resp.html(), req.$target, req.action);
|
||||||
if (url.match(/#/)) {
|
if (url.match(/#/)) {
|
||||||
this.icinga.ui.scrollContainerToAnchor(req.$target, url.split(/#/)[1]);
|
this.icinga.ui.scrollContainerToAnchor(req.$target, url.split(/#/)[1]);
|
||||||
}
|
}
|
||||||
|
@ -469,7 +474,8 @@
|
||||||
this.icinga.logger.error(req.status, errorThrown, req.responseText.slice(0, 100));
|
this.icinga.logger.error(req.status, errorThrown, req.responseText.slice(0, 100));
|
||||||
this.renderContentToContainer(
|
this.renderContentToContainer(
|
||||||
req.responseText,
|
req.responseText,
|
||||||
req.$target
|
req.$target,
|
||||||
|
req.action
|
||||||
);
|
);
|
||||||
|
|
||||||
// Header example:
|
// Header example:
|
||||||
|
@ -521,7 +527,7 @@
|
||||||
/**
|
/**
|
||||||
* Smoothly render given HTML to given container
|
* Smoothly render given HTML to given container
|
||||||
*/
|
*/
|
||||||
renderContentToContainer: function (content, $container) {
|
renderContentToContainer: function (content, $container, action) {
|
||||||
// Disable all click events while rendering
|
// Disable all click events while rendering
|
||||||
$('*').click(function (event) {
|
$('*').click(function (event) {
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
|
@ -552,8 +558,10 @@
|
||||||
var title = $('h1', $container).first().detach();
|
var title = $('h1', $container).first().detach();
|
||||||
$('h1', $content).first().detach();
|
$('h1', $content).first().detach();
|
||||||
$container.html(title).append(content);
|
$container.html(title).append(content);
|
||||||
} else {
|
} else if (action === 'replace') {
|
||||||
$container.html(content);
|
$container.html(content);
|
||||||
|
} else {
|
||||||
|
$container.append(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue