js: Fix regression for loading dependent modules for sub-containers (#4533)

This commit is contained in:
Markus Frosch 2021-11-08 13:16:06 +01:00 committed by GitHub
parent 08c51d27a6
commit d4763498e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 19 deletions

View File

@ -163,6 +163,37 @@
return 'undefined' !== typeof this.modules[name]; return 'undefined' !== typeof this.modules[name];
}, },
/**
* Ensure we have loaded the javascript code for a module
*
* @param {string} moduleName
*/
ensureModule: function(moduleName) {
if (this.hasModule(moduleName) && ! this.isLoadedModule(moduleName)) {
this.loadModule(moduleName);
}
},
/**
* If a container contains sub-containers for other modules,
* make sure the javascript code for each module is loaded.
*
* Containers are identified by "data-icinga-module" which
* holds the module name.
*
* @param container
*/
ensureSubModules: function (container) {
var icinga = this;
$(container).find('[data-icinga-module]').each(function () {
var moduleName = $(this).data('icingaModule');
if (moduleName) {
icinga.ensureModule(moduleName);
}
});
},
/** /**
* Get a module by name * Get a module by name
* *

View File

@ -35,16 +35,8 @@
behavior.bind($(document)); behavior.bind($(document));
}); });
var _this = this; // Initialize module javascript (Applies only to module.js code)
$('.container').each(function () { this.icinga.ensureSubModules(document);
// Initialize module javascript (Applies only to module.js code)
var moduleName = $(this).data('icingaModule');
if (moduleName) {
if (_this.icinga.hasModule(moduleName) && ! _this.icinga.isLoadedModule(moduleName)) {
_this.icinga.loadModule(moduleName);
}
}
});
// We catch resize events // We catch resize events
$(window).on('resize', { self: this.icinga.ui }, this.icinga.ui.onWindowResize); $(window).on('resize', { self: this.icinga.ui }, this.icinga.ui.onWindowResize);

View File

@ -734,9 +734,7 @@
}); });
if (moduleName) { if (moduleName) {
// Lazy load module javascript (Applies only to module.js code) // Lazy load module javascript (Applies only to module.js code)
if (_this.icinga.hasModule(moduleName) && ! _this.icinga.isLoadedModule(moduleName)) { _this.icinga.ensureModule(moduleName);
_this.icinga.loadModule(moduleName);
}
req.$target.data('icingaModule', moduleName); req.$target.data('icingaModule', moduleName);
classes.push('icinga-module'); classes.push('icinga-module');
@ -1025,13 +1023,10 @@
} }
} }
req.$target.find('.container').each(function () { // Lazy load module javascript (Applies only to module.js code)
// Lazy load module javascript (Applies only to module.js code) this.icinga.ensureSubModules(req.$target);
var moduleName = $(this).data('icingaModule');
if (_this.icinga.hasModule(moduleName) && ! _this.icinga.isLoadedModule(moduleName)) {
_this.icinga.loadModule(moduleName);
}
req.$target.find('.container').each(function () {
$(this).trigger('rendered', [req.autorefresh, req.scripted, req.autosubmit]); $(this).trigger('rendered', [req.autorefresh, req.scripted, req.autosubmit]);
}); });
req.$target.trigger('rendered', [req.autorefresh, req.scripted, req.autosubmit]); req.$target.trigger('rendered', [req.autorefresh, req.scripted, req.autosubmit]);