From 5b94799c820fb1d2ac530fd67f29cfd70722cb5b Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Tue, 23 Aug 2016 13:49:15 +0200 Subject: [IMP] web: allow to clear the cache in data manager Sometimes, we need better control on the cache. For example, if a view or an action has been changed, it is required to make sure that the correct data is loaded. --- addons/web/static/src/js/framework/data_manager.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'addons/web/static/src/js/framework/data_manager.js') diff --git a/addons/web/static/src/js/framework/data_manager.js b/addons/web/static/src/js/framework/data_manager.js index 29d6d585f6a..f2aa602ab41 100644 --- a/addons/web/static/src/js/framework/data_manager.js +++ b/addons/web/static/src/js/framework/data_manager.js @@ -9,6 +9,10 @@ var utils = require('web.utils'); return core.Class.extend({ init: function () { this.Filters = new Model('ir.filters'); + this._init_cache(); + }, + + _init_cache: function () { this._cache = { actions: {}, fields_views: {}, @@ -18,6 +22,14 @@ return core.Class.extend({ }; }, + /** + * Invalidates the whole cache + * Suggestion: could be refined to invalidate some part of the cache + */ + invalidate: function () { + this._init_cache(); + }, + /** * Loads an action from its id or xmlid. * -- cgit v1.2.3 From 037b7063e27164adf9ff680c34f8f9baa3baaf65 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 22 Aug 2016 15:17:47 +0200 Subject: [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) --- addons/web/static/src/js/framework/data_manager.js | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/framework/data_manager.js') diff --git a/addons/web/static/src/js/framework/data_manager.js b/addons/web/static/src/js/framework/data_manager.js index f2aa602ab41..55a4b4da15b 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; }, -- cgit v1.2.3