summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-03-21 15:30:58 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commiteaa66d11568b415b8d6b4c7a17a058b5ec1df4a6 (patch)
tree822fe86e984e69f989c3574936fe1792ae96fe9b /addons/web/static/src/js/fields
parente1eea38f2f940fbe252273a5a9d4d03474f81d0a (diff)
[REF] web: change internal representation of fields and view meta datas
* Data manager load_view returns a viewInfo object * ViewInfo contains: the arch, fields and fieldsInfo objects, and some extra informations * The fields come from the server and are frozen, without any view attributes (depend of the model). * The fieldsInfo contains every view attributes and informations.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js5
-rw-r--r--addons/web/static/src/js/fields/field_utils.js13
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js9
3 files changed, 18 insertions, 9 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 2cfe961037c..25c530d8fd4 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -88,8 +88,9 @@ var AbstractField = Widget.extend({
// such as the type, the comodel (relation), ...
this.field = record.fields[name];
- // the 'attrs' property contains the attributes of the xml 'field' tag
- this.attrs = record.fieldAttrs[name] || {};
+ // the 'attrs' property contains the attributes of the xml 'field' tag,
+ // the inner views...
+ this.attrs = record.fieldsInfo && record.fieldsInfo[name] || {};
// modifiers
this.modifiers = JSON.parse(this.attrs.modifiers || "{}");
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index bee1681a067..9c5afb71dd9 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -20,6 +20,8 @@ var session = require('web.session');
var time = require('web.time');
var utils = require('web.utils');
+var _t = core._t;
+
//------------------------------------------------------------------------------
// Formatting
//------------------------------------------------------------------------------
@@ -191,10 +193,13 @@ function formatMany2one(value) {
* @returns {string}
*/
function formatMany2Many(value) {
- var names = _.map(value.data, function (p) {
- return p.data.display_name;
- });
- return names.join(', ');
+ if (value.data.length === 0) {
+ return value.data.length + _t('0 records');
+ } else if (value.data.length === 1) {
+ return value.data.length + _t('1 record');
+ } else {
+ return value.data.length + _t(' records');
+ }
}
function formatMonetary(value, field, options) {
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 408b4c5a3ea..923e8400b1e 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -520,7 +520,7 @@ var FieldX2Many = AbstractField.extend({
this._super.apply(this, arguments);
this.operations = [];
this.isReadonly = this.mode === 'readonly';
- this.view = this.field.views.tree || this.field.views.kanban;
+ this.view = this.attrs.views.list || this.attrs.views.kanban;
this.activeActions = {};
var arch = this.view && this.view.arch;
if (arch) {
@@ -704,7 +704,7 @@ var FieldX2Many = AbstractField.extend({
_.extend(event.data, {
context: this.record.getContext({fieldName: this.name}),
domain: this.record.getDomain({fieldName: this.name}),
- form_view: this.field.views && this.field.views.form,
+ form_view: this.attrs.views && this.attrs.views.form,
readonly: this.mode === 'readonly',
string: this.string,
});
@@ -799,6 +799,7 @@ var FieldOne2Many = FieldX2Many.extend({
domain: this.record.getDomain({fieldName: this.name}),
context: this.record.getContext({fieldName: this.name}),
field: this.field,
+ attrs: this.attrs,
on_save: function (record) {
this._setValue({
operation: 'ADD',
@@ -867,7 +868,7 @@ var FieldMany2Many = FieldX2Many.extend({
context: this.record.getContext({fieldName: this.name}),
title: _t("Add: ") + this.string,
no_create: this.nodeOptions.no_create || !this.activeActions.create,
- fields_view: this.field.views.form,
+ fields_view: this.attrs.views.form,
on_selected: function (res_ids) {
var new_ids = _.difference(res_ids, self.value.res_ids);
if (new_ids.length) {
@@ -911,6 +912,8 @@ var FieldMany2ManyTags = AbstractField.extend({
'keydown .o_form_field_many2one input': '_onKeyDown',
}),
+ fetchSubFields: true,
+
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------