Expressions in the dataview-rows are now evaluated correctly

This commit is contained in:
Andreas Stöckel 2011-09-07 16:59:23 +00:00
parent f5c5df3299
commit b1223cb426
5 changed files with 65 additions and 20 deletions

View File

@ -13,7 +13,9 @@
"use strict";
/*egw:uses
et2_core_common;
et2_core_inheritance;
et2_core_phpExpressionCompiler;
*/
var et2_arrayMgr = Class.extend({
@ -147,6 +149,8 @@ var et2_arrayMgr = Class.extend({
return entry;
},
compiledExpressions: {},
/**
* Equivaltent to the boetemplate::expand_name function.
*
@ -159,13 +163,44 @@ var et2_arrayMgr = Class.extend({
// Check whether "$" occurs in the given identifier
var pos_var = _ident.indexOf('$');
if (pos_var >= 0)
if (pos_var >= 0 && this.perspectiveData.row != null)
{
console.log("blub", _ident, this.perspectiveData);
if (this.perspectiveData.row !== null)
// Get the content array for the current row
var row = this.perspectiveData.row;
var cont = this.data;
var row_cont = cont[row];
// 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
var proto = this.constructor.prototype;
if (typeof proto.compiledExpressions[_ident] == "undefined")
{
_ident.replace(/\$\{row\}/, this.perspectiveData.row);
console.log(_ident);
try
{
proto.compiledExpressions[_ident] = et2_compilePHPExpression(
_ident, ["row", "cont", "row_cont"]);
}
catch(e)
{
proto.compiledExpressions[_ident] = null;
et2_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.
if (proto.compiledExpressions[_ident])
{
try
{
_ident = proto.compiledExpressions[_ident](row, cont, row_cont);
}
catch(e)
{
et2_debug("error", e);
}
}
}
@ -288,7 +323,15 @@ var et2_readonlysArrayMgr = et2_arrayMgr.extend({
});
/**
* Creates a new set of array managers
* 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.
*/
function et2_arrayMgrs_expand(_owner, _mgrs, _data, _row)
{
@ -296,16 +339,17 @@ function et2_arrayMgrs_expand(_owner, _mgrs, _data, _row)
var result = {};
// Merge the given data associative array into the existing array managers
for (var key in _data)
for (var key in _mgrs)
{
if (typeof _mgrs[key] != "undefined")
result[key] = _mgrs[key];
if (typeof _data[key] != "undefined")
{
// Open a perspective for the given data row
var rowData = {};
rowData[_row] = _data[key];
result[key] = _mgrs[key].openPerspective(_owner,
_data[key], rowData);
result[key] = _mgrs[key].openPerspective(_owner, rowData, _row);
}
}

View File

@ -350,7 +350,7 @@
if (typeof part == "string")
{
// Escape all "'" and "\" chars and add the string to the parts array
parts.push("'" + part.replace(/'/g, "\\'").replace(/\\/g, "\\\\") + "'");
parts.push("'" + part.replace(/\\/g, "\\\\").replace(/'/g, "\\'") + "'");
}
else
{

View File

@ -51,7 +51,7 @@ var et2_dataview_dataProvider = Class.extend({
// All data rows are updated independently of all others - this allows
// user input between generation of the widgets.
//window.setTimeout(function() {_dataRow.updateData({"readonlys": {"__ALL__": true}});}, 0);
_dataRow.updateData({});
_dataRow.updateData({"content": {"ts_title": "Idx: " + _idx}});
},
unregisterDataRow: function(_dataRow) {

View File

@ -315,7 +315,8 @@ var et2_dataview_rowProvider = Class.extend({
"row": row[0],
"widgets": _widgets,
"root": _rootWidget,
"seperated": null
"seperated": null,
"mgrs": _rootWidget.getArrayMgrs()
};
// Create the row widget and insert the given widgets into the row
@ -328,7 +329,7 @@ var et2_dataview_rowProvider = Class.extend({
// Filter out all widgets which do not implement the et2_IDetachedDOM
// interface or do not support all attributes listed in the et2_IDetachedDOM
// interface. A warning is issued for all those widgets as they heavily
// degrade the performance of the widgets
// degrade the performance of the dataview
var seperated = rowTemplate.seperated =
this._seperateWidgets(variableAttributes);
@ -344,6 +345,10 @@ var et2_dataview_rowProvider = Class.extend({
getDataRow: function(_data, _row, _idx) {
// Create array managers with the given data merged in
var mgrs = et2_arrayMgrs_expand(rowWidget, this._template.mgrs,
_data, _idx);
// Insert the widgets into the row which do not provide the functions
// to set the _data directly
var rowWidget = null;
@ -353,10 +358,6 @@ var et2_dataview_rowProvider = Class.extend({
var rowWidget = new et2_dataview_rowTemplateWidget(this._rootWidget,
_row[0]);
// Create array managers with the given data merged in
var mgrs = et2_arrayMgrs_expand(rowWidget, this._rootWidget.getArrayMgrs(),
_data, _idx);
// Let the row widget create the widgets
rowWidget.createWidgets(mgrs, this._template.placeholders);
}
@ -371,7 +372,7 @@ var et2_dataview_rowProvider = Class.extend({
for (var j = 0; j < entry.data.length; j++)
{
var set = entry.data[i];
data[set.attribute] = set.expression + " for " + _idx; // TODO: Parsing of the expression
data[set.attribute] = mgrs["content"].expandName(set.expression);
}
// Retrieve all DOM-Nodes

View File

@ -65,7 +65,7 @@
<row class="$row_cont[info_cat] $row_cont[class]" valign="top">
<vbox>
<description value="Dynamic description tag:" />
<description value="${row}" />
<description value="$cont[$row][ts_title]" />
<button label="This is a button" />
</vbox>
<description value="test" />