forked from extern/egroupware
Solution for boolean attributes that need row data: Use the default but hold on to the value that couldn't be parsed, defer processing until later.
This commit is contained in:
parent
801398e69b
commit
f34d7f4d9c
@ -76,6 +76,13 @@ const Et2WidgetMixin = (superClass) =>
|
|||||||
protected _dom_id : string = "";
|
protected _dom_id : string = "";
|
||||||
private statustext : string = "";
|
private statustext : string = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TypeScript & LitElement ensure type correctness, so we can't have a string value like "$row_cont[disable_me]"
|
||||||
|
* as a boolean property so we store them here, and parse them when expanding. Strings do not have this problem,
|
||||||
|
* since $row_cont[disable_me] is still a valid string.
|
||||||
|
*/
|
||||||
|
protected _deferred_properties : { [key : string] : string } = {};
|
||||||
|
|
||||||
|
|
||||||
/** WebComponent **/
|
/** WebComponent **/
|
||||||
static get styles()
|
static get styles()
|
||||||
@ -343,6 +350,20 @@ const Et2WidgetMixin = (superClass) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any attribute that refers to row content cannot be resolved immediately, but some like booleans cannot stay a
|
||||||
|
* string because it's a boolean attribute. We store them for later, and parse when they're fully in their row.
|
||||||
|
*/
|
||||||
|
get deferredProperties()
|
||||||
|
{
|
||||||
|
return this._deferred_properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
set deferredProperties(value)
|
||||||
|
{
|
||||||
|
this._deferred_properties = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do some fancy stuff on the label, splitting it up if there's a %s in it
|
* Do some fancy stuff on the label, splitting it up if there's a %s in it
|
||||||
*
|
*
|
||||||
@ -963,6 +984,9 @@ const Et2WidgetMixin = (superClass) =>
|
|||||||
copy[key] = this[key];
|
copy[key] = this[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep the deferred properties
|
||||||
|
copy._deferred_properties = this._deferred_properties;
|
||||||
|
|
||||||
// Create a clone of all child widgets of the given object
|
// Create a clone of all child widgets of the given object
|
||||||
for(let i = 0; i < this.getChildren().length; i++)
|
for(let i = 0; i < this.getChildren().length; i++)
|
||||||
{
|
{
|
||||||
@ -1276,6 +1300,14 @@ function transformAttributes(widget, mgr : et2_arrayMgr, attributes)
|
|||||||
// If the attribute is marked as boolean, parse the
|
// If the attribute is marked as boolean, parse the
|
||||||
// expression as bool expression.
|
// expression as bool expression.
|
||||||
attrValue = mgr ? mgr.parseBoolExpression(attrValue) : attrValue;
|
attrValue = mgr ? mgr.parseBoolExpression(attrValue) : attrValue;
|
||||||
|
if(typeof attrValue === "string")
|
||||||
|
{
|
||||||
|
// Parse decided we still needed a string ($row most likely) so we'll defer it until later
|
||||||
|
// Repeating rows & nextmatch will parse it again when doing the row
|
||||||
|
widget.deferredProperties[attribute] = attrValue;
|
||||||
|
// Leave the current value at whatever the default is
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Function:
|
case Function:
|
||||||
// We parse it into a function here so we can pass in the widget as context.
|
// We parse it into a function here so we can pass in the widget as context.
|
||||||
|
@ -23,7 +23,6 @@ import {et2_arrayMgrs_expand} from "./et2_core_arrayMgr";
|
|||||||
import {et2_dataview_grid} from "./et2_dataview_view_grid";
|
import {et2_dataview_grid} from "./et2_dataview_view_grid";
|
||||||
import {egw} from "../jsapi/egw_global";
|
import {egw} from "../jsapi/egw_global";
|
||||||
import {et2_IDetachedDOM, et2_IDOMNode} from "./et2_core_interfaces";
|
import {et2_IDetachedDOM, et2_IDOMNode} from "./et2_core_interfaces";
|
||||||
import {Et2DateTimeReadonly} from "./Et2Date/Et2DateTimeReadonly";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The row provider contains prototypes (full clonable dom-trees)
|
* The row provider contains prototypes (full clonable dom-trees)
|
||||||
@ -180,17 +179,7 @@ export class et2_nextmatch_rowProvider
|
|||||||
// WebComponent IS the node, and we've already cloned it
|
// WebComponent IS the node, and we've already cloned it
|
||||||
if(typeof window.customElements.get(widget.localName) != "undefined")
|
if(typeof window.customElements.get(widget.localName) != "undefined")
|
||||||
{
|
{
|
||||||
/*
|
widget = this._cloneWebComponent(entry, row, data);
|
||||||
// N.B. cloneNode widget is missing its unreflected properties and we need to use widget.clone()
|
|
||||||
// instead to get them. This slows things down.
|
|
||||||
let c = widget.clone();
|
|
||||||
let partial = entry.nodeFuncs[0](row);
|
|
||||||
partial.parentNode.insertBefore(c, partial);
|
|
||||||
partial.parentNode.removeChild(partial);
|
|
||||||
widget = c;
|
|
||||||
*/
|
|
||||||
// Use the clone, not the original
|
|
||||||
widget = entry.nodeFuncs[0](row);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -267,6 +256,30 @@ export class et2_nextmatch_rowProvider
|
|||||||
return rowWidget;
|
return rowWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cloned web component
|
||||||
|
*/
|
||||||
|
_cloneWebComponent(entry, row, data)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
// N.B. cloneNode widget is missing its unreflected properties and we need to use widget.clone()
|
||||||
|
// instead to get them. This slows things down and is to be avoided if we can.
|
||||||
|
let c = widget.clone();
|
||||||
|
let partial = entry.nodeFuncs[0](row);
|
||||||
|
partial.parentNode.insertBefore(c, partial);
|
||||||
|
partial.parentNode.removeChild(partial);
|
||||||
|
widget = c;
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Use the clone, not the original
|
||||||
|
let widget = entry.nodeFuncs[0](row);
|
||||||
|
|
||||||
|
// Deal with the deferred properties like booleans with string values - we can't reflect them, and we don't want to lose them
|
||||||
|
// No need to transform here, that happens later
|
||||||
|
Object.assign(data, entry.widget.deferredProperties);
|
||||||
|
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder for empty row
|
* Placeholder for empty row
|
||||||
|
Loading…
Reference in New Issue
Block a user