From 0c71ee3931cce143f9181269712f23fdf350df41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Fri, 12 Aug 2011 17:02:21 +0000 Subject: [PATCH] Added correct handling of namespaces for the getValues function --- etemplate/js/et2_box.js | 2 +- etemplate/js/et2_contentArrayMgr.js | 28 ++++++++++- etemplate/js/et2_widget.js | 56 ++++++++++++++------- etemplate/js/test/et2_test_expressions.json | 6 ++- etemplate/js/test/et2_test_expressions.xet | 6 ++- 5 files changed, 74 insertions(+), 24 deletions(-) diff --git a/etemplate/js/et2_box.js b/etemplate/js/et2_box.js index 2f9f385106..2e849d9f47 100644 --- a/etemplate/js/et2_box.js +++ b/etemplate/js/et2_box.js @@ -40,5 +40,5 @@ var et2_box = et2_baseWidget.extend({ }); -et2_register_widget(et2_box, ["hbox", "vbox"]); +et2_register_widget(et2_box, ["hbox", "vbox", "box"]); diff --git a/etemplate/js/et2_contentArrayMgr.js b/etemplate/js/et2_contentArrayMgr.js index fd615e0970..ded34ada3c 100644 --- a/etemplate/js/et2_contentArrayMgr.js +++ b/etemplate/js/et2_contentArrayMgr.js @@ -64,6 +64,32 @@ et2_contentArrayMgr.prototype.getValueForID = function(_id) return null; } +/** + * 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_contentArrayMgr.prototype.getPath = function(_path) +{ + if (typeof _path == "undefined") + { + _path = []; + } + + if (this.perspectiveData.key != null) + { + _path.push(this.perspectiveData.key); + } + + if (this.parentMgr != null) + { + 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 @@ -201,7 +227,7 @@ et2_contentArrayMgr.prototype.openPerspective = function(_owner, _root, _col, _r // Set the root key if (typeof _root == "string") { - mgr.perspectiveData.key == _root; + mgr.perspectiveData.key = _root; } // Set the _col and _row parameter diff --git a/etemplate/js/et2_widget.js b/etemplate/js/et2_widget.js index 8351a5870d..2980e997d7 100644 --- a/etemplate/js/et2_widget.js +++ b/etemplate/js/et2_widget.js @@ -477,34 +477,52 @@ var et2_widget = Class.extend({ * Fetches all input element values and returns them in an associative * array. Widgets which introduce namespacing can use the internal _target * parameter to add another layer. - * - * @param _target is used internally and should no be supplied. */ - getValues: function(_target) { - if (typeof _target == "undefined") - { - _target = {}; - } + getValues: function() { + var result = {}; - // Add the value of this element to the result object - if (this.implements(et2_IInput)) - { - if (typeof _target[this.id] != "undefined") + // Iterate over the widget tree + this.iterateOver(function(_widget) { + + // Get the path to the node we have to store the value at + var path = _widget.getContentMgr().getPath(); + + // Set the _target variable to that node + var _target = result; + for (var i = 0; i < path.length; i++) + { + // Create a new object for not-existing path nodes + if (typeof _target[path[i]] == "undefined") + { + _target[path[i]] = {}; + } + + // Check whether the path node is really an object + if (_target[path[i]] instanceof Object) + { + _target = _target[path[i]]; + } + else + { + et2_debug("error", "ID collision while writing at path " + + "node '" + path[i] + "'"); + } + } + + // Check whether the entry is really undefined + if (typeof _target[_widget.id] != "undefined") { et2_debug("error", "Overwriting value of '" + this.id + "', id exists twice!"); } - _target[this.id] = this.getValue(); - } + // Store the value of the widget and reset its dirty flag, + _target[_widget.id] = _widget.getValue(); + _widget.resetDirty(); - // Store the values of the children in the target array - for (var i = 0; i < this._children.length; i++) - { - this._children[i].getValues(_target); - } + }, this, et2_IInput); - return _target; + return result; }, /** diff --git a/etemplate/js/test/et2_test_expressions.json b/etemplate/js/test/et2_test_expressions.json index 373d549874..55cbb8a2b6 100644 --- a/etemplate/js/test/et2_test_expressions.json +++ b/etemplate/js/test/et2_test_expressions.json @@ -1,7 +1,9 @@ var expression_test_data = { "test": { - "display_text": "true" + "display_text": "true", + "textbox": "And this is the inner textbox." }, - "display_text": "false" + "display_text": "false", + "textbox": "This is the outer textbox." }; diff --git a/etemplate/js/test/et2_test_expressions.xet b/etemplate/js/test/et2_test_expressions.xet index eb796e1a03..28f38df615 100644 --- a/etemplate/js/test/et2_test_expressions.xet +++ b/etemplate/js/test/et2_test_expressions.xet @@ -1,6 +1,10 @@ +