From 0463b796cea541eba5b53976d21913a3712c996c Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 19 Aug 2021 10:46:34 +0200 Subject: [PATCH] implement some missing features from old eTemplate: - evaluate class set on a grid cell as done for the widget contained (probably more a bug-fix then a feature) - allow to preset query for link-entry widget by passing an object with a query attribute - allow to overwrite not only $readonlys[__ALL__] but also widget readonly attribute with a $readonlys value of false --- api/js/etemplate/et2_widget_grid.ts | 4 ++-- api/js/etemplate/et2_widget_link.ts | 7 +++++++ api/src/Etemplate/Widget.php | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/api/js/etemplate/et2_widget_grid.ts b/api/js/etemplate/et2_widget_grid.ts index 4e44bdaee3..3b73827160 100644 --- a/api/js/etemplate/et2_widget_grid.ts +++ b/api/js/etemplate/et2_widget_grid.ts @@ -499,9 +499,9 @@ export class et2_grid extends et2_DOMWidget implements et2_IDetachedDOM, et2_IAl cell.nm_id = node.getAttribute('id'); } // Apply widget's class to td, for backward compatability - if(node.getAttribute("class")) + if (node.getAttribute("class")) { - cell.class += (cell.class ? " " : "") + node.getAttribute("class"); + cell.class += (cell.class ? " " : "") + this.getArrayMgr("content").expandName(node.getAttribute("class")); } // Create the element diff --git a/api/js/etemplate/et2_widget_link.ts b/api/js/etemplate/et2_widget_link.ts index 4f103347e7..1046944523 100644 --- a/api/js/etemplate/et2_widget_link.ts +++ b/api/js/etemplate/et2_widget_link.ts @@ -1014,6 +1014,13 @@ export class et2_link_entry extends et2_inputWidget }; } } + // display a search query, not a selected entry + else if (_value !== null && typeof _value === 'object' && typeof _value.query === 'string') + { + this.options.value = { app: _value.app || this.options.only_app, id: null }; + this.search.val(_value.query); + return; + } this._oldValue = this.options.value; if(!_value || _value.length == 0 || _value == null || jQuery.isEmptyObject(_value)) { diff --git a/api/src/Etemplate/Widget.php b/api/src/Etemplate/Widget.php index 48cc30bf7d..b5b02787a3 100644 --- a/api/src/Etemplate/Widget.php +++ b/api/src/Etemplate/Widget.php @@ -923,9 +923,10 @@ class Widget /** * Checks if a widget is readonly: - * - readonly attribute set - * - $readonlys[__ALL__] set and $readonlys[$form_name] !== false - * - $readonlys[$form_name] evaluates to true + * 1. $readonlys set to true for $form_name: + * a) $readonlys[$form_name] is set to true (flat array) + * b) self::get_array($readonlys, $form_name) is set to true (hierarchical) + * 2. ($readonlys[__ALL__] or widget readonly attribute) is true AND NOT $readonlys set to false for $form_name * * @param string $cname ='' * @param string $form_name =null form_name, to not calculate him again @@ -940,13 +941,12 @@ class Widget ); $form_name = self::form_name($cname, $this->id, $expand); } - $readonly = $this->attrs['readonly'] || self::$request->readonlys[$form_name] || - self::get_array(self::$request->readonlys,$form_name) === true || - isset(self::$request->readonlys['__ALL__']) && ( - // Exceptions to all - self::$request->readonlys[$form_name] !== false && - self::get_array(self::$request->readonlys,$form_name) !== false - ); + // readonlys can either be set / used as flat array with complete form-name, hierarchical + $readonlys = self::$request->readonlys[$form_name] ?? self::get_array(self::$request->readonlys,$form_name); + + $readonly = $readonlys === true || + // exception to __ALL__ or readonly="true" attribute by setting $readonlys[$from_name] === false + ($this->attrs['readonly'] || isset(self::$request->readonlys['__ALL__'])) && $readonlys !== false; //error_log(__METHOD__."('$cname') this->id='$this->id' --> form_name='$form_name': attrs[readonly]=".array2string($this->attrs['readonly']).", readonlys['$form_name']=".array2string(self::$request->readonlys[$form_name]).", readonlys[$form_name]=".array2string(self::get_array(self::$request->readonlys,$form_name)).", readonlys['__ALL__']=".array2string(self::$request->readonlys['__ALL__'])." returning ".array2string($readonly)); return $readonly;