loader.js: Support behaviors as well as multipart update targets

This commit is contained in:
Johannes Meyer 2020-11-06 11:28:32 +01:00
parent f05f905d14
commit 2c7b2330a7

View File

@ -771,30 +771,40 @@
} }
$.each(req.responseText.split(contentSeparator), function (idx, el) { $.each(req.responseText.split(contentSeparator), function (idx, el) {
var match = el.match(/for=(\S+)\s+(.*)/ms); var match = el.match(/for=(Behavior:)?(\S+)\s+(.*)/ms);
if (!! match) { if (!! match) {
var $target = $('#' + match[1]); if (match[1]) {
if ($target.length) { var behavior = _this.icinga.behaviors[match[2].toLowerCase()];
var forceFocus; if (typeof behavior !== 'undefined' && typeof behavior.update === 'function') {
if (req.forceFocus behavior.update(JSON.parse(match[3]));
&& typeof req.forceFocus.jquery !== 'undefined' } else {
&& $.contains($target[0], req.forceFocus[0]) _this.icinga.logger.warn(
) { 'Invalid behavior. Cannot update behavior "' + match[2] + '"');
forceFocus = req.forceFocus;
} }
_this.renderContentToContainer(
match[2],
$target,
'replace',
req.autorefresh,
forceFocus,
autoSubmit,
req.scripted
);
} else { } else {
_this.icinga.logger.warn( var $target = $('#' + match[2]);
'Invalid target ID. Cannot render multipart to #' + match[1]); if ($target.length) {
var forceFocus;
if (req.forceFocus
&& typeof req.forceFocus.jquery !== 'undefined'
&& $.contains($target[0], req.forceFocus[0])
) {
forceFocus = req.forceFocus;
}
_this.renderContentToContainer(
match[3],
$target,
'replace',
req.autorefresh,
forceFocus,
autoSubmit,
req.scripted
);
} else {
_this.icinga.logger.warn(
'Invalid target ID. Cannot render multipart to #' + match[2]);
}
} }
} else { } else {
_this.icinga.logger.error('Ill-formed multipart', el); _this.icinga.logger.error('Ill-formed multipart', el);