From 037b7063e27164adf9ff680c34f8f9baa3baaf65 Mon Sep 17 00:00:00 2001 From: Aaron Bohy <aab@odoo.com> Date: Mon, 22 Aug 2016 15:17:47 +0200 Subject: [PATCH] [REF] web: process views arch in data manager A refactoring of the js views is in progress. Those new views are used in web studio, and this change is part of it. This is necessary to allow web studio to correctly fetch data from the server when rendering a preview. Note: this is necessary for special widgets (status bar, selection, radio widgets) --- .../static/src/js/framework/data_manager.js | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/framework/data_manager.js b/addons/web/static/src/js/framework/data_manager.js index f2aa602ab417..55a4b4da15be 100644 --- a/addons/web/static/src/js/framework/data_manager.js +++ b/addons/web/static/src/js/framework/data_manager.js @@ -6,6 +6,12 @@ var Model = require('web.DataModel'); var session = require('web.session'); var utils = require('web.utils'); +function traverse(tree, f) { + if (f(tree)) { + _.each(tree.children, function(c) { traverse(c, f); }); + } +} + return core.Class.extend({ init: function () { this.Filters = new Model('ir.filters'); @@ -208,19 +214,46 @@ return core.Class.extend({ */ _postprocess_fvg: function (fields_view) { var self = this; + + // Parse and process arch var doc = $.parseXML(fields_view.arch).documentElement; + var fields = fields_view.fields; fields_view.arch = utils.xml_to_json(doc, (doc.nodeName.toLowerCase() !== 'kanban')); + traverse(fields_view.arch, function(node) { + if (typeof node === 'string') { + return false; + } + if (node.tag === 'field') { + fields[node.attrs.name].__attrs = node.attrs; + if (fields[node.attrs.name].type === 'many2one') { // FIXME: this shouldn't be done here + if (node.attrs.widget === 'statusbar' || node.attrs.widget === 'radio') { + fields[node.attrs.name].__fetch_status = true; + } else if (node.attrs.widget === 'selection') { + fields[node.attrs.name].__fetch_selection = true; + } + } + if (node.attrs.widget === 'many2many_checkboxes') { + fields[node.attrs.name].__fetch_many2manys = true; + } + return false; + } + return node.tag !== 'arch'; + }); + + // Special case for id's if ('id' in fields_view.fields) { - // Special case for id's var id_field = fields_view.fields.id; id_field.original_type = id_field.type; id_field.type = 'id'; } + + // Process inner views (one2manys) _.each(fields_view.fields, function(field) { _.each(field.views || {}, function(view) { self._postprocess_fvg(view); }); }); + return fields_view; }, -- GitLab