From dccf43f3e3e56b7a042762448b07bc2d46278f88 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 3 Sep 2021 11:20:53 -0600 Subject: [PATCH] Fix clone & child handling This gets webcomponents (Et2Box) working in nextmatch --- api/js/etemplate/Et2Box/Et2Box.ts | 33 +++++++++++++++- api/js/etemplate/Et2Widget/Et2Widget.ts | 38 ++++++++++++++----- .../et2_extension_nextmatch_rowProvider.ts | 5 +++ 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/api/js/etemplate/Et2Box/Et2Box.ts b/api/js/etemplate/Et2Box/Et2Box.ts index 3f5b21a423..0ad86be9bf 100644 --- a/api/js/etemplate/Et2Box/Et2Box.ts +++ b/api/js/etemplate/Et2Box/Et2Box.ts @@ -11,8 +11,9 @@ import {css, html, LitElement} from "@lion/core"; import {Et2Widget} from "../Et2Widget/Et2Widget"; +import {et2_IDetachedDOM} from "../et2_core_interfaces"; -export class Et2Box extends Et2Widget(LitElement) +export class Et2Box extends Et2Widget(LitElement) implements et2_IDetachedDOM { static get styles() { @@ -60,6 +61,36 @@ export class Et2Box extends Et2Widget(LitElement) { return true; } + + /** + * Code for implementing et2_IDetachedDOM + * + * Individual widgets are detected and handled by the grid, but the interface is needed for this to happen + * + * @param {array} _attrs array to add further attributes to + */ + getDetachedAttributes(_attrs) + { + _attrs.push('data'); + } + + getDetachedNodes() + { + return [this.getDOMNode()]; + } + + setDetachedAttributes(_nodes, _values) + { + if(_values.data) + { + var pairs = _values.data.split(/,/g); + for(var i = 0; i < pairs.length; ++i) + { + var name_value = pairs[i].split(':'); + jQuery(_nodes[0]).attr('data-' + name_value[0], name_value[1]); + } + } + } } customElements.define("et2-box", Et2Box); diff --git a/api/js/etemplate/Et2Widget/Et2Widget.ts b/api/js/etemplate/Et2Widget/Et2Widget.ts index fa2ea50ec2..1ed3ec2a9c 100644 --- a/api/js/etemplate/Et2Widget/Et2Widget.ts +++ b/api/js/etemplate/Et2Widget/Et2Widget.ts @@ -469,7 +469,7 @@ const Et2WidgetMixin = (superClass) => iterateOver(_callback : Function, _context, _type) { - if(et2_implements_registry[_type] && et2_implements_registry[_type](this)) + if(typeof _type == "undefined" || et2_implements_registry[_type] && et2_implements_registry[_type](this)) { _callback.call(_context, this); } @@ -500,9 +500,9 @@ const Et2WidgetMixin = (superClass) => this.getParent().getDOMNode(this).append(this); } - for(let i = 0; i < this._legacy_children.length; i++) + for(let i = 0; i < this.getChildren().length; i++) { - let child = this._legacy_children[i]; + let child = this.getChildren()[i]; let child_node = typeof child.getDOMNode !== "undefined" ? child.getDOMNode(child) : null; if(child_node && child_node !== this) { @@ -640,16 +640,26 @@ const Et2WidgetMixin = (superClass) => } // Create the copy - var copy = this.cloneNode(true); + var copy = this.cloneNode(); - // Create a clone of all child widgets of the given object - for(var i = 0; i < copy.getChildren().length; i++) + if(_parent) { - copy.addChild(copy.getChildren()[i].clone(this)); + copy.setParent(_parent); + } + else + { + // Copy a reference to the content array manager + copy.setArrayMgrs(this.getArrayMgrs()); + + // Pass on instance too + copy.setInstanceManager(this.getInstanceManager()); } - // Copy a reference to the content array manager - copy.setArrayMgrs(this.getArrayMgrs()); + // Create a clone of all child widgets of the given object + for(var i = 0; i < this.getChildren().length; i++) + { + this.getChildren()[i].clone(copy); + } return copy; } @@ -767,6 +777,16 @@ const Et2WidgetMixin = (superClass) => } } + /** + * Set the instance manager + * Normally this is not needed as it's set on the top-level container, and we just return that reference + * + */ + setInstanceManager(manager : etemplate2) + { + this._inst = manager; + } + /** * Returns the instance manager * diff --git a/api/js/etemplate/et2_extension_nextmatch_rowProvider.ts b/api/js/etemplate/et2_extension_nextmatch_rowProvider.ts index 7e7b3b422d..ba1b57f4dc 100644 --- a/api/js/etemplate/et2_extension_nextmatch_rowProvider.ts +++ b/api/js/etemplate/et2_extension_nextmatch_rowProvider.ts @@ -282,6 +282,11 @@ export class et2_nextmatch_rowProvider // Get all attribute values for (const key in _widget.attributes) { + if(typeof _widget.attributes[key] !== "object") + { + continue; + } + if(!_widget.attributes[key].ignore && typeof _widget.options[key] != "undefined") {