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
This commit is contained in:
nathangray 2021-02-26 15:22:47 -07:00
parent 2c4982d2ac
commit 51407479ee
4 changed files with 23 additions and 13 deletions

View File

@ -488,6 +488,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;
@ -757,13 +758,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 = [];

View File

@ -674,6 +674,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
{
@ -1015,15 +1016,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

View File

@ -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
};

View File

@ -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