diff options
Diffstat (limited to 'addons/web/static/src/js/widgets')
| -rw-r--r-- | addons/web/static/src/js/widgets/domain_selector.js | 6 | ||||
| -rw-r--r-- | addons/web/static/src/js/widgets/model_field_selector.js | 70 |
2 files changed, 45 insertions, 31 deletions
diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js index f7c67aa37cb..ba1ac9e77c9 100644 --- a/addons/web/static/src/js/widgets/domain_selector.js +++ b/addons/web/static/src/js/widgets/domain_selector.js @@ -301,6 +301,12 @@ var DomainSelector = DomainTree.extend({ } return this._super(domain); }, + setDomain: function (domain) { + if (Domain.prototype.arrayToString(domain) === Domain.prototype.arrayToString(this.getDomain())) { + return $.when(); + } + return this._redraw(domain); + }, _postRender: function () { this._super.apply(this, arguments); diff --git a/addons/web/static/src/js/widgets/model_field_selector.js b/addons/web/static/src/js/widgets/model_field_selector.js index 907368920ac..9c843937c90 100644 --- a/addons/web/static/src/js/widgets/model_field_selector.js +++ b/addons/web/static/src/js/widgets/model_field_selector.js @@ -2,11 +2,20 @@ odoo.define("web.ModelFieldSelector", function (require) { "use strict"; var core = require("web.core"); -var Model = require("web.DataModel"); var Widget = require("web.Widget"); var _t = core._t; +/** + * Field Selector Cache - TODO Should be improved to use external cache ? + * - Stores fields per model used in field selector + * @see ModelFieldSelector._getModelFieldsFromCache + */ +var modelFieldsCache = { + cache: {}, + cacheDefs: {}, +}; + /// The ModelFieldSelector widget can be used to select a particular field chain from a given model. var ModelFieldSelector = Widget.extend({ template: "FieldSelector", @@ -32,7 +41,7 @@ var ModelFieldSelector = Widget.extend({ }, // Handle a direct change in the debug input - "change input": function() { + "change input": function () { var userChain = this.$input.val(); if (!this.options.followRelations) { var fields = userChain.split("."); @@ -208,7 +217,7 @@ var ModelFieldSelector = Widget.extend({ /// @return a deferred which is resolved once the last page is shown _prefill: function () { this.pages = []; - return this._pushPageData(this.model).then((function() { + return this._pushPageData(this.model).then((function () { return (this.chain ? processChain.call(this, this.chain.split(".").reverse()) : $.when()); }).bind(this)); @@ -234,7 +243,7 @@ var ModelFieldSelector = Widget.extend({ if (this.model === model && this.options.fields) { def = $.when(sortFields(this.options.fields)); } else { - def = fieldsCache.getFields(model, this.options.filters); + def = this._getModelFieldsFromCache(model, this.options.filters); } return def.then((function (fields) { this.pages.push(fields); @@ -294,35 +303,34 @@ var ModelFieldSelector = Widget.extend({ name: name, }); }, -}); - -/// Field Selector Cache -/// -/// * Stores fields per model used in field selector -/// * Apply filters on the fly -var fieldsCache = { - cache: {}, - cacheDefs: {}, - getFields: function (model, filters) { - return (this.cacheDefs[model] ? this.cacheDefs[model] : this.updateCache(model)).then((function () { - return this.filter(model, filters); - }).bind(this)); - }, - updateCache: function (model) { - this.cacheDefs[model] = new Model(model).call("fields_get", [ - false, - ["store", "searchable", "type", "string", "relation", "selection", "related"], - ]).then((function (fields) { - this.cache[model] = sortFields(fields); + /** + * The _getFieldsFromCache method searches the cache for the given model + * fields, according to the given filter. If the cache does not know about + * the model, the cache is updated. + * + * @param {string} model + * @param {Object} filters @see ModelFieldSelector.init.options.filters + * + * @returns {Object[]} a list of the model fields info, sorted by field + * non-technical name + */ + _getModelFieldsFromCache: function (model, filters) { + var def = modelFieldsCache.cacheDefs[model]; + if (!def) { + def = modelFieldsCache.cacheDefs[model] = this.performModelRPC(model, "fields_get", [ + false, + ["store", "searchable", "type", "string", "relation", "selection", "related"], + ]).then((function (fields) { + modelFieldsCache.cache[model] = sortFields(fields); + }).bind(this)); + } + return def.then((function () { + return _.filter(modelFieldsCache.cache[model], function (f) { + return !filters.searchable || f.searchable; + }); }).bind(this)); - return this.cacheDefs[model]; }, - filter: function (model, filters) { - return _.filter(this.cache[model], function (f) { - return !filters.searchable || f.searchable; - }); - }, -}; +}); function sortFields(fields) { return _.chain(fields) |
