Fix that graphs disappear after using form controls (#5182)

This commit is contained in:
Johannes Meyer 2024-08-07 11:38:14 +02:00 committed by GitHub
commit fa394c8895
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 20 deletions

View File

@ -64,6 +64,11 @@
*/ */
this.behaviors = {}; this.behaviors = {};
/**
* Site behaviors which hook into the rendering process
*/
this.renderHooks = [];
/** /**
* Loaded modules * Loaded modules
*/ */
@ -94,9 +99,20 @@
this.loader = new Icinga.Loader(this); this.loader = new Icinga.Loader(this);
this.events = new Icinga.Events(this); this.events = new Icinga.Events(this);
this.history = new Icinga.History(this); this.history = new Icinga.History(this);
var _this = this;
$.each(Icinga.Behaviors, function(name, Behavior) { // Initialize all available behaviors
_this.behaviors[name.toLowerCase()] = new Behavior(_this); for (const name in Icinga.Behaviors) {
const behavior = new Icinga.Behaviors[name](this);
this.behaviors[name.toLowerCase()] = behavior;
if (behavior.renderHook) {
this.renderHooks.push(behavior);
}
}
// Sort render hooks by priority
this.renderHooks.sort(function (a, b) {
// Treats all hooks without a priority as "greater", meaning they will be applied last
return (a.priority || 999) - (b.priority || 999);
}); });
this.timezone.initialize(); this.timezone.initialize();

View File

@ -11,6 +11,8 @@
function Detach(icinga) { function Detach(icinga) {
Icinga.EventListener.call(this, icinga); Icinga.EventListener.call(this, icinga);
this.priority = 2;
} }
Detach.prototype = new Icinga.EventListener(); Detach.prototype = new Icinga.EventListener();

View File

@ -13,6 +13,8 @@
Icinga.EventListener.call(this, icinga); Icinga.EventListener.call(this, icinga);
this.on('rendered', '.container', this.onRendered, this); this.on('rendered', '.container', this.onRendered, this);
this.priority = 1;
// store the modification state of all input fields // store the modification state of all input fields
this.inputs = new WeakMap(); this.inputs = new WeakMap();
}; };
@ -76,13 +78,13 @@
return null; return null;
} }
var origFocus = document.activeElement; const origFocus = document.activeElement;
var containerId = $container.attr('id'); const containerId = $container.attr('id');
if ($container.has(origFocus).length if ($container[0].contains(origFocus)
&& $(origFocus).length && origFocus.form
&& ! $(origFocus).hasClass('autofocus') && ! origFocus.matches(
&& $(origFocus).closest('form').length 'input[type=submit], input[type=reset], input[type=button], .autofocus, .autosubmit:not(:hover)'
&& $(origFocus).not(':input[type=button], :input[type=submit], :input[type=reset]').length )
) { ) {
this.icinga.logger.debug('Not changing content for ' + containerId + ' form has focus'); this.icinga.logger.debug('Not changing content for ' + containerId + ' form has focus');
return null; return null;

View File

@ -1267,17 +1267,16 @@
$container.trigger('beforerender', [content, action, autorefresh, scripted, autoSubmit]); $container.trigger('beforerender', [content, action, autorefresh, scripted, autoSubmit]);
var discard = false; let discard = false;
$.each(_this.icinga.behaviors, function(name, behavior) { for (const hook of _this.icinga.renderHooks) {
if (behavior.renderHook) { const changed = hook.renderHook(content, $container, action, autorefresh, autoSubmit);
var changed = behavior.renderHook(content, $container, action, autorefresh, autoSubmit); if (changed === null) {
if (changed === null) { discard = true;
discard = true; break;
} else { } else {
content = changed; content = changed;
}
} }
}); }
$('.container', $container).each(function() { $('.container', $container).each(function() {
_this.stopPendingRequestsFor($(this)); _this.stopPendingRequestsFor($(this));