mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-10 08:47:46 +02:00
got et2 mostly working: timesheet.edit renders
This commit is contained in:
@ -1,40 +1,25 @@
|
||||
"use strict";
|
||||
/**
|
||||
* EGroupware eTemplate2 - JS content array manager
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package etemplate
|
||||
* @subpackage api
|
||||
* @link http://www.egroupware.org
|
||||
* @link https://www.egroupware.org
|
||||
* @author Andreas Stöckel
|
||||
*
|
||||
|
||||
*/
|
||||
/*egw:uses
|
||||
et2_core_common;
|
||||
egw_inheritance;
|
||||
et2_core_phpExpressionCompiler;
|
||||
*/
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.et2_arrayMgrs_expand = exports.et2_readonlysArrayMgr = exports.et2_arrayMgr = void 0;
|
||||
import { et2_evalBool } from "./et2_core_common";
|
||||
import { egw } from "../jsapi/egw_global";
|
||||
/**
|
||||
* Manage access to various template customisation arrays passed to etemplate->exec().
|
||||
*
|
||||
* This manages access to content, modifications and readonlys arrays
|
||||
*/
|
||||
var et2_arrayMgr = /** @class */ (function () {
|
||||
export class et2_arrayMgr {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -42,8 +27,7 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
* @param _data
|
||||
* @param _parentMgr
|
||||
*/
|
||||
function et2_arrayMgr(_data, _parentMgr) {
|
||||
if (_data === void 0) { _data = {}; }
|
||||
constructor(_data = {}, _parentMgr) {
|
||||
this.splitIds = true;
|
||||
// Holds information about the current perspective
|
||||
this.perspectiveData = {
|
||||
@ -68,14 +52,14 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
// Expanded: ${row}: Object{info_cat: ..value}
|
||||
if (this.splitIds) {
|
||||
// For each index, we need a key: {..} sub array
|
||||
for (var key in _data) {
|
||||
for (let key in _data) {
|
||||
// Split up indexes
|
||||
var indexes = key.replace(/[/g, "[").split('[');
|
||||
const indexes = key.replace(/[/g, "[").split('[');
|
||||
// Put data in the proper place
|
||||
if (indexes.length > 1) {
|
||||
var value = _data[key];
|
||||
var target = _data;
|
||||
for (var i = 0; i < indexes.length; i++) {
|
||||
const value = _data[key];
|
||||
let target = _data;
|
||||
for (let i = 0; i < indexes.length; i++) {
|
||||
indexes[i] = indexes[i].replace(/]/g, '').replace(']', '');
|
||||
if (typeof target[indexes[i]] == "undefined" || target[indexes[i]] === null) {
|
||||
target[indexes[i]] = i == indexes.length - 1 ? value : {};
|
||||
@ -91,24 +75,24 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
/**
|
||||
* Returns the root content array manager object
|
||||
*/
|
||||
et2_arrayMgr.prototype.getRoot = function () {
|
||||
getRoot() {
|
||||
if (this._parentMgr != null) {
|
||||
return this._parentMgr.getRoot();
|
||||
}
|
||||
return this;
|
||||
};
|
||||
et2_arrayMgr.prototype.getParentMgr = function () {
|
||||
}
|
||||
getParentMgr() {
|
||||
return this._parentMgr;
|
||||
};
|
||||
et2_arrayMgr.prototype.getPerspectiveData = function () {
|
||||
}
|
||||
getPerspectiveData() {
|
||||
return this.perspectiveData;
|
||||
};
|
||||
et2_arrayMgr.prototype.setPerspectiveData = function (new_perspective) {
|
||||
}
|
||||
setPerspectiveData(new_perspective) {
|
||||
this.perspectiveData = new_perspective;
|
||||
};
|
||||
et2_arrayMgr.prototype.setRow = function (new_row) {
|
||||
}
|
||||
setRow(new_row) {
|
||||
this.perspectiveData.row = new_row;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Explodes compound keys (eg IDs) into a list of namespaces
|
||||
* This uses no internal values, just expands
|
||||
@ -121,11 +105,11 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
*
|
||||
* @return {string[]}
|
||||
*/
|
||||
et2_arrayMgr.prototype.explodeKey = function (_key) {
|
||||
explodeKey(_key) {
|
||||
if (!_key || typeof _key == 'string' && _key.trim() === "")
|
||||
return [];
|
||||
// Parse the given key by removing the "]"-chars and splitting at "["
|
||||
var indexes = [_key];
|
||||
let indexes = [_key];
|
||||
if (typeof _key === "string") {
|
||||
_key = _key.replace(/[/g, "[").replace(/]/g, "]");
|
||||
indexes = _key.split('[');
|
||||
@ -133,20 +117,20 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
if (indexes.length > 1) {
|
||||
indexes = [indexes.shift(), indexes.join('[')];
|
||||
indexes[1] = indexes[1].substring(0, indexes[1].length - 1);
|
||||
var children = indexes[1].split('][');
|
||||
const children = indexes[1].split('][');
|
||||
if (children.length) {
|
||||
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.
|
||||
*/
|
||||
et2_arrayMgr.prototype.getPath = function (_path) {
|
||||
getPath(_path) {
|
||||
if (typeof _path == "undefined") {
|
||||
_path = [];
|
||||
}
|
||||
@ -158,7 +142,7 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
_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
|
||||
@ -170,7 +154,7 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
* @param _skipEmpty returns null if _key is not present in this content array.
|
||||
* Defaults to false.
|
||||
*/
|
||||
et2_arrayMgr.prototype.getEntry = function (_key, _referenceInto, _skipEmpty) {
|
||||
getEntry(_key, _referenceInto, _skipEmpty) {
|
||||
if (typeof _referenceInto == "undefined") {
|
||||
_referenceInto = false;
|
||||
}
|
||||
@ -178,26 +162,26 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
_skipEmpty = false;
|
||||
}
|
||||
// Parse the given key by removing the "]"-chars and splitting at "["
|
||||
var indexes = this.explodeKey(_key);
|
||||
const indexes = this.explodeKey(_key);
|
||||
if (indexes.length == 0 && _skipEmpty)
|
||||
return null;
|
||||
var entry = this.data;
|
||||
for (var i = 0; i < indexes.length; i++) {
|
||||
let entry = this.data;
|
||||
for (let i = 0; i < indexes.length; i++) {
|
||||
// Abort if the current entry is not an object (associative array) and
|
||||
// we should descend further into it.
|
||||
var isObject = typeof entry === 'object';
|
||||
const isObject = typeof entry === 'object';
|
||||
if (!isObject && !_referenceInto || entry == null || jQuery.isEmptyObject(entry)) {
|
||||
return null;
|
||||
}
|
||||
// Check whether the entry actually exists
|
||||
var idx = indexes[i];
|
||||
const idx = indexes[i];
|
||||
if (_skipEmpty && (!isObject || typeof entry[idx] == "undefined")) {
|
||||
return null;
|
||||
}
|
||||
entry = entry[idx];
|
||||
}
|
||||
return entry;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Equivalent to the boetemplate::expand_name function.
|
||||
*
|
||||
@ -207,20 +191,20 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
* @param {string} _ident Key used to reference into managed array
|
||||
* @return {*}
|
||||
*/
|
||||
et2_arrayMgr.prototype.expandName = function (_ident) {
|
||||
expandName(_ident) {
|
||||
// Check whether the identifier refers to an index in the content array
|
||||
var is_index_in_content = _ident.charAt(0) == '@';
|
||||
const is_index_in_content = _ident.charAt(0) == '@';
|
||||
// Check whether "$" occurs in the given identifier
|
||||
var pos_var = _ident.indexOf('$');
|
||||
const pos_var = _ident.indexOf('$');
|
||||
if (pos_var >= 0 && (this.perspectiveData.row != null || !_ident.match(/\$\{?row\}?/))
|
||||
// Avoid messing with regex in validators
|
||||
&& pos_var !== _ident.indexOf("$/")) {
|
||||
// Get the content array for the current row
|
||||
var row = typeof this.perspectiveData.row == 'number' ? this.perspectiveData.row : '';
|
||||
var row_cont = this.data[row] || {};
|
||||
const row = typeof this.perspectiveData.row == 'number' ? this.perspectiveData.row : '';
|
||||
const row_cont = this.data[row] || {};
|
||||
// $cont is NOT root but current name-space in old eTemplate
|
||||
var cont = this.data; //getRoot().data;
|
||||
var _cont = this.data; // according to a grep only used in ImportExport just twice
|
||||
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
|
||||
@ -272,22 +256,22 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
}
|
||||
}
|
||||
return _ident;
|
||||
};
|
||||
et2_arrayMgr.prototype.parseBoolExpression = function (_expression) {
|
||||
}
|
||||
parseBoolExpression(_expression) {
|
||||
// If the first char of the expression is a '!' this means, that the value
|
||||
// is to be negated.
|
||||
if (_expression.charAt(0) == '!') {
|
||||
return !this.parseBoolExpression(_expression.substr(1));
|
||||
}
|
||||
// Split the expression at a possible "="
|
||||
var parts = _expression.split('=');
|
||||
const parts = _expression.split('=');
|
||||
// Expand the first value
|
||||
var val = this.expandName(parts[0]);
|
||||
let val = this.expandName(parts[0]);
|
||||
val = (typeof val == "undefined" || val === null) ? '' : '' + val;
|
||||
// If a second expression existed, test that one
|
||||
if (typeof parts[1] != "undefined") {
|
||||
// Expand the second value
|
||||
var checkVal = '' + this.expandName(parts[1]);
|
||||
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
|
||||
if (checkVal.charAt(0) == '/') {
|
||||
@ -298,7 +282,7 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
return val == checkVal;
|
||||
}
|
||||
return et2_evalBool(val);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
@ -306,15 +290,15 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
* @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
|
||||
*/
|
||||
et2_arrayMgr.prototype.openPerspective = function (_owner, _root, _row) {
|
||||
openPerspective(_owner, _root, _row) {
|
||||
// Get the root node
|
||||
var root = typeof _root == "string" ? this.data[_root] :
|
||||
let root = typeof _root == "string" ? this.data[_root] :
|
||||
(_root == null ? this.data : _root);
|
||||
if (typeof root == "undefined" && typeof _root == "string")
|
||||
root = this.getEntry(_root);
|
||||
// Create a new content array manager with the given root
|
||||
var constructor = this.readOnly ? et2_readonlysArrayMgr : et2_arrayMgr;
|
||||
var mgr = new constructor(root, this);
|
||||
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
|
||||
@ -326,20 +310,16 @@ var et2_arrayMgr = /** @class */ (function () {
|
||||
mgr.perspectiveData.row = _row;
|
||||
}
|
||||
return mgr;
|
||||
};
|
||||
et2_arrayMgr.compiledExpressions = {};
|
||||
return et2_arrayMgr;
|
||||
}());
|
||||
exports.et2_arrayMgr = et2_arrayMgr;
|
||||
}
|
||||
}
|
||||
et2_arrayMgr.compiledExpressions = {};
|
||||
/**
|
||||
* @augments et2_arrayMgr
|
||||
*/
|
||||
var et2_readonlysArrayMgr = /** @class */ (function (_super) {
|
||||
__extends(et2_readonlysArrayMgr, _super);
|
||||
function et2_readonlysArrayMgr() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.readOnly = true;
|
||||
return _this;
|
||||
export class et2_readonlysArrayMgr extends et2_arrayMgr {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.readOnly = true;
|
||||
}
|
||||
/**
|
||||
* Find out if the given ID is readonly, according to the array data
|
||||
@ -350,8 +330,8 @@ var et2_readonlysArrayMgr = /** @class */ (function (_super) {
|
||||
* @param _parent
|
||||
* @returns
|
||||
*/
|
||||
et2_readonlysArrayMgr.prototype.isReadOnly = function (_id, _attr, _parent) {
|
||||
var entry = null;
|
||||
isReadOnly(_id, _attr, _parent) {
|
||||
let entry = null;
|
||||
if (_id != null) {
|
||||
if (_id.indexOf('$') >= 0 || _id.indexOf('@') >= 0) {
|
||||
_id = this.expandName(_id);
|
||||
@ -359,7 +339,7 @@ var et2_readonlysArrayMgr = /** @class */ (function (_super) {
|
||||
// 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!)
|
||||
var mgr = this;
|
||||
let mgr = this;
|
||||
while (mgr.getParentMgr() && jQuery.isEmptyObject(mgr.data)) {
|
||||
mgr = mgr.getParentMgr();
|
||||
}
|
||||
@ -381,7 +361,7 @@ var et2_readonlysArrayMgr = /** @class */ (function (_super) {
|
||||
// Otherwise return the default value
|
||||
entry = this.getEntry("__ALL__");
|
||||
return entry !== null && (typeof entry != "undefined");
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Override parent to handle cont and row_cont.
|
||||
*
|
||||
@ -391,12 +371,10 @@ var et2_readonlysArrayMgr = /** @class */ (function (_super) {
|
||||
* @param {string} ident Key for searching into the array.
|
||||
* @returns {*}
|
||||
*/
|
||||
et2_readonlysArrayMgr.prototype.expandName = function (ident) {
|
||||
expandName(ident) {
|
||||
return this.perspectiveData.owner.getArrayMgr('content').expandName(ident);
|
||||
};
|
||||
return et2_readonlysArrayMgr;
|
||||
}(et2_arrayMgr));
|
||||
exports.et2_readonlysArrayMgr = et2_readonlysArrayMgr;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new set of array managers
|
||||
*
|
||||
@ -408,15 +386,15 @@ exports.et2_readonlysArrayMgr = et2_readonlysArrayMgr;
|
||||
* existing array managers.
|
||||
* @param _row is the row for which the array managers will be opened.
|
||||
*/
|
||||
function et2_arrayMgrs_expand(_owner, _mgrs, _data, _row) {
|
||||
export function et2_arrayMgrs_expand(_owner, _mgrs, _data, _row) {
|
||||
// Create a copy of the given _mgrs associative array
|
||||
var result = {};
|
||||
let result = {};
|
||||
// Merge the given data associative array into the existing array managers
|
||||
for (var key in _mgrs) {
|
||||
for (let key in _mgrs) {
|
||||
result[key] = _mgrs[key];
|
||||
if (typeof _data[key] != "undefined") {
|
||||
// Open a perspective for the given data row
|
||||
var rowData = {};
|
||||
let rowData = {};
|
||||
rowData[_row] = _data[key];
|
||||
result[key] = _mgrs[key].openPerspective(_owner, rowData, _row);
|
||||
}
|
||||
@ -424,5 +402,4 @@ function et2_arrayMgrs_expand(_owner, _mgrs, _data, _row) {
|
||||
// Return the resulting managers object
|
||||
return result;
|
||||
}
|
||||
exports.et2_arrayMgrs_expand = et2_arrayMgrs_expand;
|
||||
//# sourceMappingURL=et2_core_arrayMgr.js.map
|
Reference in New Issue
Block a user