summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorAlexandre Kühn <alex.e.kuhn@gmail.com>2018-01-09 12:04:21 +0100
committerAlexandre Kühn <alexkuhn@users.noreply.github.com>2018-01-12 16:12:49 +0100
commit41fe7f9d1113d026b226b136b4477aaaf9f1f638 (patch)
treebcaf1204fdcc6a54fc497c23b1ec227d414cddfd /addons/web/static/src
parent7813a8e714f268983b0be88827ae1c8ad887e6c7 (diff)
[FIX] web: contexts on field widgets + enforce bin_size for binary
Field widgets now have a key 'context' that let them extend the context of the dataPoint (e.g. list). In particular, widgets on binary fields enforce the contextual item {bin_size: True}, so that the server gives the size of the binary field as its value, instead of its content. This change on binary fields reduces network load when accessing a view with binary fields.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/core/utils.js3
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js5
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js1
-rw-r--r--addons/web/static/src/js/services/data_manager.js4
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js43
5 files changed, 48 insertions, 8 deletions
diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js
index b9f5a7c9689..091c6448561 100644
--- a/addons/web/static/src/js/core/utils.js
+++ b/addons/web/static/src/js/core/utils.js
@@ -31,9 +31,6 @@ var utils = {
* @return {string} bin_size (human-readable)
*/
binaryToBinsize: function (value) {
- if (!value) {
- return this.human_size(0);
- }
if (!this.is_bin_size(value)) {
// Computing approximate size out of base64 encoded string
// http://en.wikipedia.org/wiki/Base64#MIME
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 2534f8ae90a..8bb9afca065 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -45,6 +45,11 @@ var AbstractField = Widget.extend({
},
/**
+ * fields can extend the context, e.g. binary fields add {bin_size: true}
+ */
+ context: null,
+
+ /**
* An object representing fields to be fetched by the model eventhough not present in the view
* This object contains "field name" as key and an object as value.
* That value object must contain the key "type"
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 09406b43711..aab0e42c318 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -1080,6 +1080,7 @@ var AbstractFieldBinary = AbstractField.extend({
},
'click .o_clear_file_button': 'on_clear',
}),
+ context: { bin_size: true },
init: function (parent, name, record) {
this._super.apply(this, arguments);
this.fields = record.fields;
diff --git a/addons/web/static/src/js/services/data_manager.js b/addons/web/static/src/js/services/data_manager.js
index 9b11f3a54a7..6e39ede94e8 100644
--- a/addons/web/static/src/js/services/data_manager.js
+++ b/addons/web/static/src/js/services/data_manager.js
@@ -387,6 +387,10 @@ return core.Class.extend({
attrs.fieldDependencies = attrs.Widget.prototype.fieldDependencies;
}
+ if (attrs.Widget.prototype.context) {
+ attrs.context = attrs.Widget.prototype.context;
+ }
+
return attrs;
},
/**
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 a94e2fe9454..a6979776c99 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -33,7 +33,7 @@ odoo.define('web.BasicModel', function (require) {
* isOpen: {boolean},
* loadMoreOffset: {integer},
* limit: {integer},
- * model: {string,
+ * model: {string},
* offset: {integer},
* openGroupByDefault: {boolean},
* orderedBy: {Object[]},
@@ -1854,7 +1854,7 @@ var BasicModel = AbstractModel.extend({
model: record.model,
method: 'read',
args: [[record.res_id], fieldNames],
- context: _.extend({}, record.getContext(), {bin_size: true}),
+ context: record.getContext(),
})
.then(function (result) {
if (result.length === 0) {
@@ -3040,10 +3040,33 @@ var BasicModel = AbstractModel.extend({
* the resource in the localData object.
*
* @param {Object} params
+ * @param {Object} [params.aggregateValues={}]
+ * @param {Object} [params.context={}] context of the action
+ * @param {integer} [params.count=0] number of record being manipulated
+ * @param {Object|Object[]} [params.data={}|[]] data of the record
+ * @param {*[]} [params.domain=[]]
+ * @param {Object} params.fields contains the description of each field
* @param {Object} [params.fieldsInfo={}] contains the fieldInfo of each field
- * @param {Array} [params.fieldNames] the name of fields to load, the list
+ * @param {Object[]} [params.fieldNames] the name of fields to load, the list
* of all fields by default
- * @param {Object} params.fields contains the description of each field
+ * @param {string[]} [params.groupedBy=[]]
+ * @param {boolean} [params.isOpen]
+ * @param {integer} params.limit max number of records shown on screen (pager size)
+ * @param {string} params.modelName
+ * @param {integer} [params.offset]
+ * @param {boolean} [params.openGroupByDefault]
+ * @param {Object[]} [params.orderedBy=[]]
+ * @param {integer[]} [params.orderedResIDs]
+ * @param {string} [params.parentID] model name ID of the parent model
+ * @param {Object} [params.rawContext]
+ * @param {[type]} [params.ref]
+ * @param {string} [params.relationField]
+ * @param {integer|null} [params.res_id] actual id of record in the server
+ * @param {integer[]} [params.res_ids] context in which the data point is used, from a list of res_id
+ * @param {boolean} [params.static=false]
+ * @param {string} [params.type='record'|'list']
+ * @param {[type]} [params.value]
+ * @param {string} [params.viewType] the type of the view, e.g. 'list' or 'form'
* @returns {Object} the resource created
*/
_makeDataPoint: function (params) {
@@ -3069,13 +3092,23 @@ var BasicModel = AbstractModel.extend({
id: {type: 'integer'},
}, params.fields);
+ // datapoint context is extended by fields widgets
+ var context = _.extend({}, params.context);
+ if (params.fieldsInfo && params.viewType) {
+ _.each(params.fieldsInfo[params.viewType], function (field) {
+ if (field.context) {
+ _.extend(context, field.context);
+ }
+ });
+ }
+
var dataPoint = {
_cache: type === 'list' ? {} : undefined,
_changes: null,
_domains: {},
_rawChanges: {},
aggregateValues: params.aggregateValues || {},
- context: params.context || {},
+ context: context,
count: params.count || res_ids.length,
data: data,
domain: params.domain || [],