From 4869ca9a49e10ce5f9166cf29d418780101aea30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Mon, 22 Aug 2011 15:58:47 +0000 Subject: [PATCH] Implemented hiding grid columns and rows, fixed bug with et2_template::isInTree returning false in the wrong places and thus not all values being transmitted back to the server --- etemplate/js/et2_arrayMgr.js | 5 +- etemplate/js/et2_common.js | 8 +++ etemplate/js/et2_grid.js | 55 ++++++++++++++++--- etemplate/js/et2_template.js | 9 +-- etemplate/js/et2_widget.js | 4 +- etemplate/js/test/et2_test_grid.xet | 48 ++++++++++++++++ .../js/test/et2_test_timesheet_edit.json | 3 +- etemplate/js/test/test.css | 8 +++ 8 files changed, 123 insertions(+), 17 deletions(-) diff --git a/etemplate/js/et2_arrayMgr.js b/etemplate/js/et2_arrayMgr.js index 6882b62f8f..ecf2470b6c 100644 --- a/etemplate/js/et2_arrayMgr.js +++ b/etemplate/js/et2_arrayMgr.js @@ -214,7 +214,10 @@ var et2_arrayMgr = Class.extend({ return val == checkVal; } - return val != '' && (typeof val != "string" || val.toLowerCase() != "false"); + et2_debug("log", "Parse bool expression: ", _expression, val); + + return et2_evalBool(val); +// return val != '' && (typeof val != "string" || val.toLowerCase() != "false"); }, openPerspective: function(_owner, _root, _col, _row) diff --git a/etemplate/js/et2_common.js b/etemplate/js/et2_common.js index af63134f8c..a202863882 100644 --- a/etemplate/js/et2_common.js +++ b/etemplate/js/et2_common.js @@ -90,6 +90,14 @@ var et2_typeDefaults = { function et2_evalBool(_val) { + if (typeof _val == "string") + { + if (_val == "false") + { + return false; + } + } + return _val ? true : false; } diff --git a/etemplate/js/et2_grid.js b/etemplate/js/et2_grid.js index 140f274364..477fa8409a 100644 --- a/etemplate/js/et2_grid.js +++ b/etemplate/js/et2_grid.js @@ -71,6 +71,7 @@ var et2_grid = et2_DOMWidget.extend({ "widget": null, "colData": _colData[x], "rowData": _rowData[y], + "disabled": _colData[x].disabled || _rowData[y].disabled, "colSpan": 1, "autoColSpan": false, "rowSpan": 1, @@ -89,7 +90,8 @@ var et2_grid = et2_DOMWidget.extend({ "width": "auto", "class": "", "align": "", - "span": "1" + "span": "1", + "disabled": false }; }, @@ -98,7 +100,8 @@ var et2_grid = et2_DOMWidget.extend({ "height": "auto", "class": "", "valign": "", - "span": "1" + "span": "1", + "disabled": false }; }, @@ -128,6 +131,8 @@ var et2_grid = et2_DOMWidget.extend({ // Parse the columns tag et2_filteredNodeIterator(columns, function(node, nodeName) { var colDataEntry = this._getColDataEntry(); + colDataEntry["disabled"] = this.getArrayMgr("content") + .parseBoolExpression(et2_readAttrWithDefault(node, "disabled", "")); if (nodeName == "column") { colDataEntry["width"] = et2_readAttrWithDefault(node, "width", "auto"); @@ -145,6 +150,8 @@ var et2_grid = et2_DOMWidget.extend({ // Parse the rows tag et2_filteredNodeIterator(rows, function(node, nodeName) { var rowDataEntry = this._getRowDataEntry(); + rowDataEntry["disabled"] = this.getArrayMgr("content") + .parseBoolExpression(et2_readAttrWithDefault(node, "disabled", "")); if (nodeName == "row") { rowDataEntry["height"] = et2_readAttrWithDefault(node, "height", "auto"); @@ -383,6 +390,7 @@ var et2_grid = et2_DOMWidget.extend({ { var row = _cells[y]; var tr = $j(document.createElement("tr")).appendTo(this.tbody); + var row_hidden = true; // Create the cells. x is incremented by the colSpan value of the // cell. @@ -396,10 +404,21 @@ var et2_grid = et2_DOMWidget.extend({ // Create the cell var td = $j(document.createElement("td")).appendTo(tr); + if (cell.disabled) + { + td.hide(); + //td.css("border", "2px solid red"); + } + else + { + row_hidden = false; + } + // Add the entry for the widget to the management array this.managementArray.push({ "cell": td[0], - "widget": cell.widget + "widget": cell.widget, + "disabled": cell.disabled }); // Set the span values of the cell @@ -431,6 +450,11 @@ var et2_grid = et2_DOMWidget.extend({ x++; } } + + if (row_hidden) + { + tr.hide(); + } } }, @@ -483,7 +507,8 @@ var et2_grid = et2_DOMWidget.extend({ "widget": widget, "td": null, "colSpan": srcCell.colSpan, - "rowSpan": srcCell.rowSpan + "rowSpan": srcCell.rowSpan, + "disabled": srcCell.disabled } } } @@ -523,11 +548,25 @@ var et2_grid = et2_DOMWidget.extend({ return null; }, - set_id: function(_value) { - this._super.apply(this, arguments); + isInTree: function(_sender) { + var vis = true; - // Check whether a namespace exists for this element - this.checkCreateNamespace(); + if (typeof _sender != "undefined" && _sender != this) + { + vis = false; + + // Check whether the _sender object exists inside the management array + for (var i = 0; i < this.managementArray.length; i++) + { + if (this.managementArray[i].widget == _sender) + { + vis = !(this.managementArray[i].disabled); + break; + } + } + } + + return this._super(this, vis); } }); diff --git a/etemplate/js/et2_template.js b/etemplate/js/et2_template.js index 1820b12d2a..595beec143 100644 --- a/etemplate/js/et2_template.js +++ b/etemplate/js/et2_template.js @@ -54,6 +54,7 @@ var et2_template = et2_DOMWidget.extend({ this.proxiedTemplate = null; this.isProxied = false; + this.isProxy = false; this.div = document.createElement("div"); @@ -85,7 +86,7 @@ var et2_template = et2_DOMWidget.extend({ // Reset the "ignore" flag and manually copy the id tmpl.options.id = this.id; this.proxiedTemplate.id = tmpl.id; - this.proxiedTemplate.isProxied = true; + this.proxiedTemplate.isProxy = true; // Disallow adding any new node to this template this.supportedWidgetClasses = []; @@ -109,7 +110,7 @@ var et2_template = et2_DOMWidget.extend({ this.proxiedTemplate.loadingFinished(); return false; } - else if (!this.isProxied) + else if (!this.isProxied && !this.isProxy) { this.setParentDOMNode(parentNode); } @@ -134,8 +135,8 @@ var et2_template = et2_DOMWidget.extend({ return this.div; }, - isInTree: function() { - return this._super(!this.isProxied); + isInTree: function(_sender) { + return this._super(this, !this.isProxied); } }); diff --git a/etemplate/js/et2_widget.js b/etemplate/js/et2_widget.js index 5dd8a29bed..d8a7335a1f 100644 --- a/etemplate/js/et2_widget.js +++ b/etemplate/js/et2_widget.js @@ -346,7 +346,7 @@ var et2_widget = Class.extend({ * return this._super(inTree); * when calling this function the _vis parameter does not have to be supplied. */ - isInTree: function(_vis) { + isInTree: function(_sender, _vis) { if (typeof _vis == "undefined") { _vis = true; @@ -354,7 +354,7 @@ var et2_widget = Class.extend({ if (this._parent) { - return _vis && this._parent.isInTree(); + return _vis && this._parent.isInTree(this); } return _vis; diff --git a/etemplate/js/test/et2_test_grid.xet b/etemplate/js/test/et2_test_grid.xet index 2db9ab63a5..fd6800ed60 100644 --- a/etemplate/js/test/et2_test_grid.xet +++ b/etemplate/js/test/et2_test_grid.xet @@ -204,6 +204,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etemplate/js/test/et2_test_timesheet_edit.json b/etemplate/js/test/et2_test_timesheet_edit.json index aa4aabe071..9565db83e6 100644 --- a/etemplate/js/test/et2_test_timesheet_edit.json +++ b/etemplate/js/test/et2_test_timesheet_edit.json @@ -73,8 +73,7 @@ var timesheet_data = { "ts_owner":true, "tabs":{ "customfields":true - }, - "ts_description": true + } } } diff --git a/etemplate/js/test/test.css b/etemplate/js/test/test.css index 6cf975fe2a..691b46a50b 100644 --- a/etemplate/js/test/test.css +++ b/etemplate/js/test/test.css @@ -251,3 +251,11 @@ hr { margin: 10px 0px 10px 0px; } +/** + * grid widget + */ + +table.et2_grid { + border-collapse: collapse; +} +