loader.js: Only pre-wrap a search response's html with a div

It's not required for all responses anymore.

refs #3953
This commit is contained in:
Johannes Meyer 2019-09-23 08:49:19 +02:00
parent d699191629
commit b15c012671

View File

@ -445,8 +445,6 @@
_this.loadUrl(_this.url('/layout/announcements'), $('#announcements')); _this.loadUrl(_this.url('/layout/announcements'), $('#announcements'));
} }
// div helps getting an XML tree
var $resp = $('<div>' + req.responseText + '</div>');
var active = false; var active = false;
var rendered = false; var rendered = false;
var classes; var classes;
@ -521,33 +519,32 @@
} }
// Handle search requests, still hardcoded. // Handle search requests, still hardcoded.
if (req.url.match(/^\/search/) && if (req.url.match(/^\/search/) && req.$target.data('icingaUrl').match(/^\/search/)) {
req.$target.data('icingaUrl').match(/^\/search/) && var $resp = $('<div>' + req.responseText + '</div>'); // div helps getting an XML tree
$('.dashboard', $resp).length > 0 && if ($('.dashboard', $resp).length > 0 && $('.dashboard .container', req.$target).length > 0) {
$('.dashboard .container', req.$target).length > 0) // TODO: We need dashboard pane and container identifiers (not ids)
{ var targets = [];
// TODO: We need dashboard pane and container identifiers (not ids) $('.dashboard .container', req.$target).each(function (idx, el) {
var targets = []; targets.push($(el));
$('.dashboard .container', req.$target).each(function (idx, el) { });
targets.push($(el));
});
var i = 0; var i = 0;
// Searching for '.dashboard .container' in $resp doesn't dork?! // Searching for '.dashboard .container' in $resp doesn't dork?!
$('.dashboard .container', $resp).each(function (idx, el) { $('.dashboard .container', $resp).each(function (idx, el) {
var $el = $(el); var $el = $(el);
if ($el.hasClass('dashboard')) { if ($el.hasClass('dashboard')) {
return; return;
} }
var url = $el.data('icingaUrl'); var url = $el.data('icingaUrl');
targets[i].data('icingaUrl', url); targets[i].data('icingaUrl', url);
var title = $('h1', $el).first(); var title = $('h1', $el).first();
$('h1', targets[i]).first().replaceWith(title); $('h1', targets[i]).first().replaceWith(title);
_this.loadUrl(url, targets[i]); _this.loadUrl(url, targets[i]);
i++; i++;
}); });
rendered = true; rendered = true;
}
} }
var referrer = req.referrer; var referrer = req.referrer;
@ -574,8 +571,7 @@
this.icinga.timer.unregister(req.progressTimer); this.icinga.timer.unregister(req.progressTimer);
} }
// .html() removes outer div we added above this.renderContentToContainer(req.responseText, req.$target, req.action, req.autorefresh, req.forceFocus, autoSubmit);
this.renderContentToContainer($resp.html(), req.$target, req.action, req.autorefresh, req.forceFocus, autoSubmit);
if (oldNotifications) { if (oldNotifications) {
oldNotifications.appendTo($('#notifications')); oldNotifications.appendTo($('#notifications'));
} }