summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-03-13 16:40:14 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commiteb5d65cda78802a5c4287c3fcce4ed5658491371 (patch)
tree2cf77df1b236757721c1ef31100d104b0bbe28fb /addons/web/static
parentd4fdbad99a776052340d0ea941cac8e85cdfebc5 (diff)
[REF] web: factorize the special data cache saving code
The _fetchSpecialXXX methods all save values in the _specialDataCache variable associated to a given record and fieldName. This code is being regrouped in a private function now.
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 7797abfc3f6..a664344ddf5 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1421,11 +1421,13 @@ var BasicModel = AbstractModel.extend({
}
// avoid rpc if not necessary
- var specialDataCache = {context: context, domain: domain};
- if (_.isEqual(record._specialDataCache[fieldName], specialDataCache)) {
+ var hasChanged = this._saveSpecialDataCache(record, fieldName, {
+ context: context,
+ domain: domain,
+ });
+ if (!hasChanged) {
return $.when();
}
- record._specialDataCache[fieldName] = specialDataCache;
var self = this;
return this._rpc(field.relation, 'search_read')
@@ -1472,11 +1474,13 @@ var BasicModel = AbstractModel.extend({
var domain = record.getDomain({fieldName: fieldName});
// avoid rpc if not necessary
- var specialDataCache = {context: context, domain: domain};
- if (_.isEqual(record._specialDataCache[fieldName], specialDataCache)) {
+ var hasChanged = this._saveSpecialDataCache(record, fieldName, {
+ context: context,
+ domain: domain,
+ });
+ if (!hasChanged) {
return $.when();
}
- record._specialDataCache[fieldName] = specialDataCache;
return this._rpc(field.relation, "name_search")
.args(["", domain])
@@ -2141,6 +2145,25 @@ var BasicModel = AbstractModel.extend({
});
},
/**
+ * Allows to save a value in the specialData cache associated to a given
+ * record and fieldName. If the value in the cache was already the given
+ * one, nothing is done and the method indicates it by returning false
+ * instead of true.
+ *
+ * @private
+ * @param {Object} record - an element from the localData
+ * @param {string} fieldName - the name of the field
+ * @param {*} value - the cache value to save
+ * @returns {boolean} false if the value was already the given one
+ */
+ _saveSpecialDataCache: function (record, fieldName, value) {
+ if (_.isEqual(record._specialDataCache[fieldName], value)) {
+ return false;
+ }
+ record._specialDataCache[fieldName] = value;
+ return true;
+ },
+ /**
* Do a /search_read to get data for a list resource. This does a
* /search_read because the data may not be static (for ex, a list view).
*