Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JS events from legacy controllers are bound multiple times #2688

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.6.0 (unreleased)
------------------

- #2688 Fix JS events from legacy controllers are bound multiple times
- #2682 Added Limit of Quantification (LOQ) for services and analyses
- #2687 Remove legacy and obsolete rejection.js
- #2685 Fix missing default instrument import template
Expand Down
2 changes: 1 addition & 1 deletion src/senaite/core/browser/static/bundles/legacy.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions src/senaite/core/browser/static/js/bika.lims.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,26 @@ window.bika.lims.controllers = {
*/
window.bika.lims.loadControllers = function(all, controllerKeys) {
var controllers = window.bika.lims.controllers;
var _bika_lims_loaded_js = new Array();
var _bika_lims_loaded_js = window.bika.lims._loaded || []; // Track loaded controllers globally
var prev = _bika_lims_loaded_js.length;
for (var key in controllers) {
// Check if the key have value. Also check if this key exists in the controllerKeys array.
// If controllerKeys contains the key, the JS controllers defined inside window.bika.lims.controllers
// and indexed with that key will be reloaded/loaded (wherever you are.)
if ($(key).length || $.inArray(key, controllerKeys) >= 0) {
controllers[key].forEach(function(js) {
if (all == true || $.inArray(key, controllerKeys) >= 0 || $.inArray(js, _bika_lims_loaded_js) < 0) {
console.debug('[bika.lims.loader] Loading '+js);
obj = new window[js]();
obj.load();
// Register the object for further access
window.bika.lims[js]=obj;
_bika_lims_loaded_js.push(js);
if (all || $.inArray(key, controllerKeys) >= 0 || $.inArray(js, _bika_lims_loaded_js) < 0) {
console.debug("[senaite.loader] Loading " + js);
if (!window.bika.lims[js]) { // Ensure it's not already initialized
obj = new window[js]();
obj.load();
window.bika.lims[js] = obj;
_bika_lims_loaded_js.push(js);
}
}
});
}
}
return _bika_lims_loaded_js.length - prev;

window.bika.lims._loaded = _bika_lims_loaded_js; // Store the updated list globally
return _bika_lims_loaded_js.length - prev;
};

document.addEventListener("DOMContentLoaded", function(event) {
Expand Down
Loading