2020-01-22 11:40:55 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - JS content array manager
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
2021-06-07 17:33:53 +02:00
|
|
|
* @link https://www.egroupware.org
|
2020-01-22 11:40:55 +01:00
|
|
|
* @author Andreas Stöckel
|
2021-06-07 17:33:53 +02:00
|
|
|
*/
|
2020-01-22 11:40:55 +01:00
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
et2_core_common;
|
|
|
|
egw_inheritance;
|
|
|
|
et2_core_phpExpressionCompiler;
|
|
|
|
*/
|
|
|
|
|
2021-06-07 17:33:53 +02:00
|
|
|
import {et2_evalBool} from "./et2_core_common";
|
|
|
|
import type {et2_widget} from "./et2_core_widget";
|
|
|
|
import {egw} from "../jsapi/egw_global";
|
2021-06-08 14:11:59 +02:00
|
|
|
import {et2_compilePHPExpression} from "./et2_core_phpExpressionCompiler";
|
2020-01-22 11:40:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Manage access to various template customisation arrays passed to etemplate->exec().
|
|
|
|
*
|
|
|
|
* This manages access to content, modifications and readonlys arrays
|
|
|
|
*/
|
2020-01-24 10:27:01 +01:00
|
|
|
export class et2_arrayMgr
|
|
|
|
{
|
2022-01-05 21:14:28 +01:00
|
|
|
splitIds : boolean = true;
|
|
|
|
public data : object;
|
2020-01-22 11:40:55 +01:00
|
|
|
// Holds information about the current perspective
|
2022-01-05 21:14:28 +01:00
|
|
|
public perspectiveData : { owner : et2_widget; row : number; key : string } = {
|
2020-01-22 11:40:55 +01:00
|
|
|
"owner": null,
|
|
|
|
"key": null,
|
|
|
|
"row": null
|
|
|
|
};
|
2022-01-05 21:14:28 +01:00
|
|
|
protected static compiledExpressions : object = {};
|
|
|
|
private readonly _parentMgr : et2_arrayMgr;
|
|
|
|
protected readOnly : boolean = false;
|
2020-01-22 11:40:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @memberOf et2_arrayMgr
|
|
|
|
* @param _data
|
|
|
|
* @param _parentMgr
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
constructor(_data : object = {}, _parentMgr? : et2_arrayMgr)
|
|
|
|
{
|
|
|
|
if(typeof _parentMgr == "undefined")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
_parentMgr = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the parent manager which is needed to access relative data when
|
|
|
|
// being in a relative perspective of the manager
|
|
|
|
this._parentMgr = _parentMgr;
|
|
|
|
|
|
|
|
// Hold a reference to the data
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _data == "undefined" || !_data)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
egw.debug("log", "No data passed to content array manager. Probably a mismatch between template namespaces and data.");
|
|
|
|
_data = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand sub-arrays that have been shmushed together, so further perspectives work
|
|
|
|
// Shmushed keys look like: ${row}[info_cat]
|
|
|
|
// Expanded: ${row}: Object{info_cat: ..value}
|
2022-01-05 21:14:28 +01:00
|
|
|
if(this.splitIds)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// For each index, we need a key: {..} sub array
|
2022-01-05 21:14:28 +01:00
|
|
|
for(let key in _data)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Split up indexes
|
|
|
|
const indexes = key.replace(/[/g, "[").split('[');
|
|
|
|
|
|
|
|
// Put data in the proper place
|
2022-01-05 21:14:28 +01:00
|
|
|
if(indexes.length > 1)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
const value = _data[key];
|
|
|
|
let target = _data;
|
2022-01-05 21:14:28 +01:00
|
|
|
for(let i = 0; i < indexes.length; i++)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
indexes[i] = indexes[i].replace(/]/g, '').replace(']', '');
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof target[indexes[i]] == "undefined" || target[indexes[i]] === null)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
target[indexes[i]] = i == indexes.length - 1 ? value : {};
|
|
|
|
}
|
|
|
|
target = target[indexes[i]];
|
|
|
|
}
|
|
|
|
delete _data[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.data = _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the root content array manager object
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
getRoot() : et2_arrayMgr
|
|
|
|
{
|
|
|
|
if(this._parentMgr != null)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return this._parentMgr.getRoot();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
getParentMgr() : et2_arrayMgr
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return this._parentMgr;
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
getPerspectiveData() : { owner : et2_widget; row : number; key : string }
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return this.perspectiveData;
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
setPerspectiveData(new_perspective : { owner : et2_widget; row : number; key : string })
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
this.perspectiveData = new_perspective;
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
setRow(new_row : number)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
this.perspectiveData.row = new_row;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Explodes compound keys (eg IDs) into a list of namespaces
|
|
|
|
* This uses no internal values, just expands
|
|
|
|
*
|
|
|
|
* eg:
|
|
|
|
* a[b][c] => [a,b,c]
|
|
|
|
* col_filter[tr_tracker] => [col_filter, tr_tracker]
|
|
|
|
*
|
|
|
|
* @param {string} _key
|
|
|
|
*
|
|
|
|
* @return {string[]}
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
explodeKey(_key : string) : string[]
|
|
|
|
{
|
|
|
|
if(!_key || typeof _key == 'string' && _key.trim() === "")
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2020-11-13 00:29:57 +01:00
|
|
|
|
2020-01-22 11:40:55 +01:00
|
|
|
// Parse the given key by removing the "]"-chars and splitting at "["
|
|
|
|
let indexes = [_key];
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _key === "string")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
_key = _key.replace(/[/g, "[").replace(/]/g, "]");
|
|
|
|
indexes = _key.split('[');
|
|
|
|
}
|
2022-01-05 21:14:28 +01:00
|
|
|
if(indexes.length > 1)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
indexes = [indexes.shift(), indexes.join('[')];
|
|
|
|
indexes[1] = indexes[1].substring(0, indexes[1].length - 1);
|
|
|
|
const children = indexes[1].split('][');
|
2022-01-05 21:14:28 +01:00
|
|
|
if(children.length)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
indexes = jQuery.merge([indexes[0]], children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return indexes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the path to this content array manager perspective as an array
|
|
|
|
* containing the key values
|
|
|
|
*
|
|
|
|
* @param _path is used internally, do not supply it manually.
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
getPath(_path? : string[]) : string[]
|
|
|
|
{
|
|
|
|
if(typeof _path == "undefined")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
_path = [];
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
if(this.perspectiveData.key != null)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// prepend components of this.perspectiveData.key to path, can be more then one eg. "nm[rows]"
|
|
|
|
_path = this.perspectiveData.key.replace(/]/g, '').split('[').concat(_path);
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
if(this._parentMgr != null)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
_path = this._parentMgr.getPath(_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get array entry is the equivalent to the boetemplate get_array function.
|
|
|
|
* It returns a reference to the (sub) array with the given key. This also works
|
|
|
|
* for keys using the ETemplate referencing scheme like a[b][c]
|
|
|
|
*
|
|
|
|
* @param _key is the string index, may contain sub-indices like a[b]
|
|
|
|
* @param _referenceInto if true none-existing sub-arrays/-indices get created
|
|
|
|
* to be returned as reference, else false is returned. Defaults to false
|
|
|
|
* @param _skipEmpty returns null if _key is not present in this content array.
|
|
|
|
* Defaults to false.
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
getEntry(_key : string, _referenceInto? : boolean, _skipEmpty? : boolean) : any
|
|
|
|
{
|
|
|
|
if(typeof _referenceInto == "undefined")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
_referenceInto = false;
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _skipEmpty == "undefined")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
_skipEmpty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the given key by removing the "]"-chars and splitting at "["
|
|
|
|
const indexes = this.explodeKey(_key);
|
2022-01-05 21:14:28 +01:00
|
|
|
if(indexes.length == 0 && _skipEmpty)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2020-01-22 11:40:55 +01:00
|
|
|
|
|
|
|
let entry = this.data;
|
2022-01-05 21:14:28 +01:00
|
|
|
for(let i = 0; i < indexes.length; i++)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Abort if the current entry is not an object (associative array) and
|
|
|
|
// we should descend further into it.
|
|
|
|
const isObject = typeof entry === 'object';
|
2022-01-05 21:14:28 +01:00
|
|
|
if(!isObject && !_referenceInto || entry == null || jQuery.isEmptyObject(entry))
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the entry actually exists
|
|
|
|
const idx = indexes[i];
|
2022-01-05 21:14:28 +01:00
|
|
|
if(_skipEmpty && (!isObject || typeof entry[idx] == "undefined"))
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = entry[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Equivalent to the boetemplate::expand_name function.
|
|
|
|
*
|
|
|
|
* Expands variables inside the given identifier to their values inside the
|
|
|
|
* content array.
|
|
|
|
*
|
|
|
|
* @param {string} _ident Key used to reference into managed array
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
expandName(_ident : string) : string | object
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Check whether the identifier refers to an index in the content array
|
|
|
|
const is_index_in_content = _ident.charAt(0) == '@';
|
|
|
|
|
|
|
|
// Check whether "$" occurs in the given identifier
|
|
|
|
const pos_var = _ident.indexOf('$');
|
2022-01-05 21:14:28 +01:00
|
|
|
if(pos_var >= 0 && (this.perspectiveData.row != null || !_ident.match(/\$\{?row\}?/))
|
2020-07-10 21:27:48 +02:00
|
|
|
// Avoid messing with regex in validators
|
|
|
|
&& pos_var !== _ident.indexOf("$/")
|
2022-01-05 21:14:28 +01:00
|
|
|
)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Get the content array for the current row
|
2020-02-10 22:13:46 +01:00
|
|
|
const row = typeof this.perspectiveData.row == 'number' ? this.perspectiveData.row : '';
|
2020-01-22 11:40:55 +01:00
|
|
|
const row_cont = this.data[row] || {};
|
|
|
|
// $cont is NOT root but current name-space in old eTemplate
|
|
|
|
const cont = this.data;//getRoot().data;
|
|
|
|
const _cont = this.data;// according to a grep only used in ImportExport just twice
|
|
|
|
|
|
|
|
// Check whether the expression has already been compiled - if not,
|
|
|
|
// try to compile it first. If an error occurs, the identifier
|
|
|
|
// function is set to null
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof et2_arrayMgr.compiledExpressions[_ident] == "undefined")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(this.perspectiveData.row == null)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// No row, compile for only top level content
|
|
|
|
// @ts-ignore
|
2020-01-24 10:27:01 +01:00
|
|
|
et2_arrayMgr.compiledExpressions[_ident] = et2_compilePHPExpression(
|
2020-01-22 11:40:55 +01:00
|
|
|
_ident, ["cont", "_cont"]);
|
2022-01-05 21:14:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// @ts-ignore
|
2020-01-24 10:27:01 +01:00
|
|
|
et2_arrayMgr.compiledExpressions[_ident] = et2_compilePHPExpression(
|
2020-01-22 11:40:55 +01:00
|
|
|
_ident, ["row", "cont", "row_cont", "_cont"]);
|
|
|
|
}
|
2022-01-05 21:14:28 +01:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
2020-01-24 10:27:01 +01:00
|
|
|
et2_arrayMgr.compiledExpressions[_ident] = null;
|
2020-01-22 11:40:55 +01:00
|
|
|
egw.debug("error", "Error while compiling PHP->JS ", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute the previously compiled expression, if it is not "null"
|
|
|
|
// because compilation failed. The parameters have to be in the same
|
|
|
|
// order as defined during compilation.
|
2022-01-05 21:14:28 +01:00
|
|
|
if(et2_arrayMgr.compiledExpressions[_ident])
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(this.perspectiveData.row == null)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// No row, exec with only top level content
|
2020-01-24 10:27:01 +01:00
|
|
|
_ident = et2_arrayMgr.compiledExpressions[_ident](cont, _cont);
|
2022-01-05 21:14:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-24 10:27:01 +01:00
|
|
|
_ident = et2_arrayMgr.compiledExpressions[_ident](row, cont, row_cont, _cont);
|
2020-01-22 11:40:55 +01:00
|
|
|
}
|
2022-01-05 21:14:28 +01:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// only log error, as they are no real errors but missing data
|
|
|
|
egw.debug("log", typeof e == 'object' ? e.message : e);
|
|
|
|
_ident = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
if(is_index_in_content && _ident)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// If an additional "@" is specified, this means that we have to return
|
|
|
|
// the entry from the root element
|
2022-01-05 21:14:28 +01:00
|
|
|
if(_ident.charAt(1) == '@')
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return this.getRoot().getEntry(_ident.substr(2));
|
2022-01-05 21:14:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return this.getEntry(_ident.substr(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _ident;
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
parseBoolExpression(_expression : string)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// If the first char of the expression is a '!' this means, that the value
|
|
|
|
// is to be negated.
|
2022-01-05 21:14:28 +01:00
|
|
|
if(_expression.charAt(0) == '!')
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return !this.parseBoolExpression(_expression.substr(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the expression at a possible "="
|
|
|
|
const parts = _expression.split('=');
|
|
|
|
|
|
|
|
// Expand the first value
|
2020-02-12 19:10:52 +01:00
|
|
|
let val = this.expandName(parts[0]);
|
2022-01-05 21:14:28 +01:00
|
|
|
val = (typeof val == "undefined" || val === null) ? '' : '' + val;
|
2020-01-22 11:40:55 +01:00
|
|
|
|
|
|
|
// If a second expression existed, test that one
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof parts[1] != "undefined")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Expand the second value
|
|
|
|
const checkVal = '' + this.expandName(parts[1]);
|
|
|
|
|
|
|
|
// Values starting with / are treated as regular expression. It is
|
|
|
|
// checked whether the first value matches the regular expression
|
2022-01-05 21:14:28 +01:00
|
|
|
if(checkVal.charAt(0) == '/')
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return (new RegExp(checkVal.substr(1, checkVal.length - 2)))
|
|
|
|
.test(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise check for simple equality
|
|
|
|
return val == checkVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return et2_evalBool(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ?
|
|
|
|
*
|
|
|
|
* @param {object} _owner owner object
|
|
|
|
* @param {(string|null|object)} _root string with key, null for whole data or object with data
|
|
|
|
* @param {number?} _row key for into the _root for the desired row
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
openPerspective(_owner : et2_widget, _root : (string | null | object), _row? : number | null) : et2_arrayMgr
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Get the root node
|
|
|
|
let root = typeof _root == "string" ? this.data[_root] :
|
2022-01-05 21:14:28 +01:00
|
|
|
(_root == null ? this.data : _root);
|
|
|
|
if(typeof root == "undefined" && typeof _root == "string")
|
|
|
|
{
|
|
|
|
root = this.getEntry(_root);
|
|
|
|
}
|
2020-01-22 11:40:55 +01:00
|
|
|
|
|
|
|
// Create a new content array manager with the given root
|
|
|
|
const constructor = this.readOnly ? et2_readonlysArrayMgr : et2_arrayMgr;
|
|
|
|
const mgr = new constructor(root, this);
|
|
|
|
|
|
|
|
// Set the owner
|
|
|
|
mgr.perspectiveData.owner = _owner;
|
|
|
|
|
|
|
|
// Set the root key
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _root == "string")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
mgr.perspectiveData.key = _root;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set _row parameter
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _row != "undefined")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
mgr.perspectiveData.row = _row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mgr;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @augments et2_arrayMgr
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
export class et2_readonlysArrayMgr extends et2_arrayMgr
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
|
2020-01-29 22:29:38 +01:00
|
|
|
readOnly : boolean = true;
|
|
|
|
|
2020-01-22 11:40:55 +01:00
|
|
|
/**
|
|
|
|
* Find out if the given ID is readonly, according to the array data
|
|
|
|
*
|
|
|
|
* @memberOf et2_readonlysArrayMgr
|
|
|
|
* @param _id
|
|
|
|
* @param _attr
|
|
|
|
* @param _parent
|
|
|
|
* @returns
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
isReadOnly(_id : string, _attr : string, _parent? : et2_arrayMgr) : boolean | string
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
let entry = null;
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
if(_id != null)
|
|
|
|
{
|
|
|
|
if(_id.indexOf('$') >= 0 || _id.indexOf('@') >= 0)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
_id = this.expandName(_id);
|
|
|
|
}
|
|
|
|
// readonlys was not namespaced in old eTemplate, therefore if we dont find data
|
|
|
|
// under current namespace, we look into parent
|
|
|
|
// (if there is anything namespaced, we will NOT look for parent!)
|
2022-01-05 21:14:28 +01:00
|
|
|
let mgr : et2_arrayMgr = this;
|
|
|
|
while(mgr.getParentMgr() && jQuery.isEmptyObject(mgr.data))
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
mgr = mgr.getParentMgr();
|
|
|
|
}
|
|
|
|
entry = mgr.getEntry(_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let the array entry override the read only attribute entry
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof entry != "undefined" && !(typeof entry === 'object'))
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the attribute is set, return that
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _attr != "undefined" && _attr !== null)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Accept 'editable', but otherwise boolean
|
|
|
|
return this.expandName(_attr) === 'editable' ? 'editable' : et2_evalBool(_attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise take into accounf whether the parent is readonly
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _parent != "undefined" && _parent)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise return the default value
|
|
|
|
entry = this.getEntry("__ALL__");
|
|
|
|
return entry !== null && (typeof entry != "undefined");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override parent to handle cont and row_cont.
|
|
|
|
*
|
|
|
|
* Normally these should refer to the readonlys data, but that's not
|
|
|
|
* useful, so we use the owner inside perspective data to expand using content.
|
|
|
|
*
|
|
|
|
* @param {string} ident Key for searching into the array.
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
expandName(ident : string) : any
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
return this.perspectiveData.owner.getArrayMgr('content').expandName(ident);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new set of array managers
|
|
|
|
*
|
|
|
|
* @param _owner is the owner object of the array managers - this object (a widget)
|
|
|
|
* will free the array manager
|
|
|
|
* @param _mgrs is the original set of array managers, the array managers are
|
|
|
|
* inside an associative array as recived from et2_widget::getArrayMgrs()
|
|
|
|
* @param _data is an associative array of new data which will be merged into the
|
|
|
|
* existing array managers.
|
|
|
|
* @param _row is the row for which the array managers will be opened.
|
|
|
|
*/
|
2022-01-05 21:14:28 +01:00
|
|
|
export function et2_arrayMgrs_expand(_owner : et2_widget, _mgrs : object, _data : object, _row : number)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Create a copy of the given _mgrs associative array
|
|
|
|
let result = {};
|
|
|
|
|
|
|
|
// Merge the given data associative array into the existing array managers
|
2022-01-05 21:14:28 +01:00
|
|
|
for(let key in _mgrs)
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
result[key] = _mgrs[key];
|
|
|
|
|
2022-01-05 21:14:28 +01:00
|
|
|
if(typeof _data[key] != "undefined")
|
|
|
|
{
|
2020-01-22 11:40:55 +01:00
|
|
|
// Open a perspective for the given data row
|
|
|
|
let rowData = {};
|
|
|
|
rowData[_row] = _data[key];
|
|
|
|
|
|
|
|
result[key] = _mgrs[key].openPerspective(_owner, rowData, _row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the resulting managers object
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|