From 9128d15bb2c74113cc137bc52ebef463644df88b Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 26 Feb 2021 15:22:47 -0700 Subject: [PATCH] Etemplate: Fix some load bugs - tabs got doLoadingFinished() multiple times if tablist was modified by data - selectbox with cached options did not load correctly first time --- api/js/etemplate/et2_widget_selectbox.js | 10 ++++++---- api/js/etemplate/et2_widget_selectbox.ts | 11 ++++++----- api/js/etemplate/et2_widget_tabs.js | 7 +++++-- api/js/etemplate/et2_widget_tabs.ts | 9 +++++++-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/api/js/etemplate/et2_widget_selectbox.js b/api/js/etemplate/et2_widget_selectbox.js index fb37e3ce49..23c86ecaf7 100644 --- a/api/js/etemplate/et2_widget_selectbox.js +++ b/api/js/etemplate/et2_widget_selectbox.js @@ -24,6 +24,7 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); +exports.et2_menulist = exports.et2_selectbox_ro = exports.et2_selectbox = void 0; /*egw:uses /vendor/bower-asset/jquery/dist/jquery.js; /api/js/jquery/chosen/chosen.jquery.js; @@ -497,6 +498,7 @@ var et2_selectbox = /** @class */ (function (_super) { } else if (jQuery.isEmptyObject(this.options.select_options)) { this.egw().debug("warn", "Can't set value to '%s', widget has no options set", _value, this); + this.value = null; } else { var debug_value = _value; @@ -769,13 +771,13 @@ var et2_selectbox = /** @class */ (function (_super) { this.input.trigger("liszt:updated"); } // Sometimes value gets set before options - if (this.value || (this.options.empty_label && !this.options.multiple) || this.value === '' && this.input && this.input.children('[value=""]').length === 1) { - this.set_value(this.value, true); // true = dont try to set_options, to avoid an infinit recursion - } - else if (this.value === null && this.options.value) { + if (this.value === null && this.options.value) { // Null means it tried to set the value, and it got stripped by missing options this.set_value(this.options.value, true); } + else if (this.value || (this.options.empty_label && !this.options.multiple) || this.value === '' && this.input && this.input.children('[value=""]').length === 1) { + this.set_value(this.value, true); // true = dont try to set_options, to avoid an infinit recursion + } }; et2_selectbox.prototype.getValue = function () { var value = []; diff --git a/api/js/etemplate/et2_widget_selectbox.ts b/api/js/etemplate/et2_widget_selectbox.ts index 79b4d13281..e26b57cf41 100644 --- a/api/js/etemplate/et2_widget_selectbox.ts +++ b/api/js/etemplate/et2_widget_selectbox.ts @@ -688,6 +688,7 @@ export class et2_selectbox extends et2_inputWidget else if (jQuery.isEmptyObject(this.options.select_options)) { this.egw().debug("warn", "Can't set value to '%s', widget has no options set",_value, this); + this.value = null; } else { @@ -1031,15 +1032,15 @@ export class et2_selectbox extends et2_inputWidget this.input.trigger("liszt:updated"); } // Sometimes value gets set before options - if(this.value || (this.options.empty_label && !this.options.multiple) || this.value === '' && this.input && this.input.children('[value=""]').length === 1) - { - this.set_value(this.value, true); // true = dont try to set_options, to avoid an infinit recursion - } - else if (this.value === null && this.options.value) + if (this.value === null && this.options.value) { // Null means it tried to set the value, and it got stripped by missing options this.set_value(this.options.value, true); } + else if(this.value || (this.options.empty_label && !this.options.multiple) || this.value === '' && this.input && this.input.children('[value=""]').length === 1) + { + this.set_value(this.value, true); // true = dont try to set_options, to avoid an infinit recursion + } } getValue() : string[] | string diff --git a/api/js/etemplate/et2_widget_tabs.js b/api/js/etemplate/et2_widget_tabs.js index c582da3278..afc1821fdf 100644 --- a/api/js/etemplate/et2_widget_tabs.js +++ b/api/js/etemplate/et2_widget_tabs.js @@ -202,6 +202,9 @@ var et2_tabbox = /** @class */ (function (_super) { var tabs = this; // Specially process the selected index so it shows up right away this._loadTab(this.selected_index, promises); + // Avoid reloading if tabs were modified by data + if (this.isInTree() && this.isAttached()) + return; // Apply parent now, which actually puts into the DOM // This has to be before loading the child, so the dom sub-tree is not // disconnected, which causes problems for things like CKEditor @@ -233,6 +236,8 @@ var et2_tabbox = /** @class */ (function (_super) { var tabData = this.tabData[index]; if (!tabData || tabData.loaded) return; + // Set loaded flag to not do this again, even if not fully done + tabData.loaded = true; if (tabData.XMLNode != null) { if (tabData.hidden) { // Set hidden tab to readonly, so widgets aren't active @@ -247,8 +252,6 @@ var et2_tabbox = /** @class */ (function (_super) { else if (tabData.widget_options) { tabData.widget = et2_core_widget_1.et2_createWidget('template', tabData.widget_options, this); } - // Set loaded flag to not do this again, even if not fully done - tabData.loaded = true; // loadingFinished() will be called either when the promise from doLoadingFinished is resolved, // or during the normal execution }; diff --git a/api/js/etemplate/et2_widget_tabs.ts b/api/js/etemplate/et2_widget_tabs.ts index 67a7823941..5236ebf2aa 100644 --- a/api/js/etemplate/et2_widget_tabs.ts +++ b/api/js/etemplate/et2_widget_tabs.ts @@ -256,6 +256,9 @@ class et2_tabbox extends et2_valueWidget implements et2_IInput,et2_IResizeable,e // Specially process the selected index so it shows up right away this._loadTab(this.selected_index,promises); + // Avoid reloading if tabs were modified by data + if(this.isInTree() && this.isAttached()) return; + // Apply parent now, which actually puts into the DOM // This has to be before loading the child, so the dom sub-tree is not // disconnected, which causes problems for things like CKEditor @@ -291,6 +294,10 @@ class et2_tabbox extends et2_valueWidget implements et2_IInput,et2_IResizeable,e { var tabData = this.tabData[index]; if(!tabData || tabData.loaded) return; + + // Set loaded flag to not do this again, even if not fully done + tabData.loaded = true; + if(tabData.XMLNode != null) { if(tabData.hidden) @@ -311,8 +318,6 @@ class et2_tabbox extends et2_valueWidget implements et2_IInput,et2_IResizeable,e tabData.widget = et2_createWidget('template',tabData.widget_options,this); } - // Set loaded flag to not do this again, even if not fully done - tabData.loaded = true; // loadingFinished() will be called either when the promise from doLoadingFinished is resolved, // or during the normal execution