summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_view.js112
1 files changed, 65 insertions, 47 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js
index b4df9c8e09e..ad15931c6c6 100644
--- a/addons/web/static/src/js/views/basic/basic_view.js
+++ b/addons/web/static/src/js/views/basic/basic_view.js
@@ -182,6 +182,20 @@ var BasicView = AbstractView.extend({
return this._super.apply(this, arguments);
},
/**
+ * Traverses the arch and calls '_processNode' on each of its nodes.
+ *
+ * @private
+ * @param {Object} arch a parsed arch
+ * @param {Object} fv the fieldsView Object, in which _processNode can
+ * access and add information (like the fields' attributes in the arch)
+ */
+ _processArch: function (arch, fv) {
+ var self = this;
+ utils.traverse(arch, function (node) {
+ return self._processNode(node, fv);
+ });
+ },
+ /**
* Processes a field node, in particular, put a flag on the field to give
* special directives to the BasicModel.
*
@@ -314,50 +328,6 @@ var BasicView = AbstractView.extend({
return attrs;
},
/**
- * Visits all nodes in the arch and processes each fields.
- *
- * @private
- * @param {string} viewType
- * @param {Object} arch
- * @param {Object} fields
- * @returns {Object} fieldsInfo
- */
- _processFields: function (viewType, arch, fields) {
- var self = this;
- var fieldsInfo = Object.create(null);
- utils.traverse(arch, function (node) {
- if (typeof node === 'string') {
- return false;
- }
- if (!_.isObject(node.attrs.modifiers)) {
- node.attrs.modifiers = node.attrs.modifiers ? JSON.parse(node.attrs.modifiers) : {};
- }
- if (!_.isObject(node.attrs.options) && node.tag === 'button') {
- node.attrs.options = node.attrs.options ? JSON.parse(node.attrs.options) : {};
- }
- if (node.tag === 'field') {
- fieldsInfo[node.attrs.name] = self._processField(viewType,
- fields[node.attrs.name], node.attrs ? _.clone(node.attrs) : {});
-
- if (fieldsInfo[node.attrs.name].fieldDependencies) {
- var deps = fieldsInfo[node.attrs.name].fieldDependencies;
- for (var dependency_name in deps) {
- var dependency_dict = {name: dependency_name, type: deps[dependency_name].type};
- if (!(dependency_name in fieldsInfo)) {
- fieldsInfo[dependency_name] = _.extend({}, dependency_dict, {options: deps[dependency_name].options || {}});
- }
- if (!(dependency_name in fields)) {
- fields[dependency_name] = dependency_dict;
- }
- }
- }
- return false;
- }
- return node.tag !== 'arch';
- });
- return fieldsInfo;
- },
- /**
* Overrides to process the fields, and generate fieldsInfo which contains
* the description of the fields in view, with their attrs in the arch.
*
@@ -373,13 +343,61 @@ var BasicView = AbstractView.extend({
var fv = this._super.apply(this, arguments);
viewType = viewType || this.viewType;
- var viewFields = this._processFields(viewType, fv.arch, fv.viewFields);
- fv.fieldsInfo = {};
- fv.fieldsInfo[viewType] = viewFields;
fv.type = viewType;
+ fv.fieldsInfo = Object.create(null);
+ fv.fieldsInfo[viewType] = Object.create(null);
+
+ this._processArch(fv.arch, fv);
return fv;
},
+ /**
+ * Processes a node of the arch (mainly nodes with tagname 'field'). Can
+ * be overriden to handle other tagnames.
+ *
+ * @private
+ * @param {Object} node
+ * @param {Object} fv the fieldsView
+ * @param {Object} fv.fieldsInfo
+ * @param {Object} fv.fieldsInfo[viewType] fieldsInfo of the current viewType
+ * @param {Object} fv.viewFields the result of a fields_get extend with the
+ * fields returned with the fields_view_get for the current viewType
+ * @param {string} fv.viewType
+ * @returns {boolean} false iff subnodes must not be visited.
+ */
+ _processNode: function (node, fv) {
+ if (typeof node === 'string') {
+ return false;
+ }
+ if (!_.isObject(node.attrs.modifiers)) {
+ node.attrs.modifiers = node.attrs.modifiers ? JSON.parse(node.attrs.modifiers) : {};
+ }
+ if (!_.isObject(node.attrs.options) && node.tag === 'button') {
+ node.attrs.options = node.attrs.options ? JSON.parse(node.attrs.options) : {};
+ }
+ if (node.tag === 'field') {
+ var viewType = fv.type;
+ var fieldsInfo = fv.fieldsInfo[viewType];
+ var fields = fv.viewFields;
+ fieldsInfo[node.attrs.name] = this._processField(viewType,
+ fields[node.attrs.name], node.attrs ? _.clone(node.attrs) : {});
+
+ if (fieldsInfo[node.attrs.name].fieldDependencies) {
+ var deps = fieldsInfo[node.attrs.name].fieldDependencies;
+ for (var dependency_name in deps) {
+ var dependency_dict = {name: dependency_name, type: deps[dependency_name].type};
+ if (!(dependency_name in fieldsInfo)) {
+ fieldsInfo[dependency_name] = _.extend({}, dependency_dict, {options: deps[dependency_name].options || {}});
+ }
+ if (!(dependency_name in fields)) {
+ fields[dependency_name] = dependency_dict;
+ }
+ }
+ }
+ return false;
+ }
+ return node.tag !== 'arch';
+ },
});
return BasicView;