summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-03-21 11:04:48 +0100
committerChristophe Simonis <chs@odoo.com>2018-03-21 11:04:48 +0100
commitb51f2d38c247dce9afc04c29774a77d773e3f393 (patch)
tree1133e0dd4c082543d1f361fb7ec160ac0b2cccc6 /addons/web/static/src/js/fields
parentc7dff653d56910fd46e4dcf745c2c6088ce9fc58 (diff)
parent500e3f497057c5d00ae5cc34da7012c6f31f81d4 (diff)
[MERGE] forward port branch saas-11.2 up to 500e3f49705
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js5
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js29
2 files changed, 28 insertions, 6 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 3b55efbc826..3a5a1537387 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -2062,8 +2062,9 @@ var FieldToggleBoolean = AbstractField.extend({
* @private
*/
_render: function () {
- var className = this.value ? 'o_toggle_button_success' : 'text-muted';
- this.$('i').addClass('fa fa-circle ' + className);
+ this.$('i')
+ .toggleClass('o_toggle_button_success', !!this.value)
+ .toggleClass('text-muted', !this.value);
var title = this.value ? this.attrs.options.active : this.attrs.options.inactive;
this.$el.attr('title', title);
},
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index ecd7dd688e6..8f5ffd65fac 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -878,10 +878,15 @@ var FieldX2Many = AbstractField.extend({
this.pager = new Pager(this, this.value.count, this.value.offset + 1, this.value.limit, {
single_page_hidden: true,
withAccessKey: false,
+ validate: function () {
+ var isList = self.view.arch.tag === 'tree';
+ // TODO: we should have some common method in the basic renderer...
+ return isList ? self.renderer.unselectRow() : $.when();
+ },
});
this.pager.on('pager_changed', this, function (new_state) {
- this.trigger_up('load', {
- id: this.value.id,
+ self.trigger_up('load', {
+ id: self.value.id,
limit: new_state.limit,
offset: new_state.current_min - 1,
on_success: function (value) {
@@ -930,6 +935,7 @@ var FieldX2Many = AbstractField.extend({
* did not agree to discard.
*/
_saveLine: function (recordID) {
+ var self = this;
var def = $.Deferred();
var fieldNames = this.renderer.canBeSaved(recordID);
if (fieldNames.length) {
@@ -941,7 +947,9 @@ var FieldX2Many = AbstractField.extend({
} else {
this.renderer.setRowMode(recordID, 'readonly').done(def.resolve.bind(def));
}
- return def;
+ return def.then(function () {
+ self.pager.updateState({ size: self.value.count });
+ });
},
/**
* Parses the 'columnInvisibleFields' attribute to search for the domains
@@ -1178,7 +1186,20 @@ var FieldOne2Many = FieldX2Many.extend({
return this._super.apply(this, arguments).then(function () {
if (ev && ev.target === self && ev.data.changes && self.view.arch.tag === 'tree') {
if (ev.data.changes[self.name].operation === 'CREATE') {
- var index = self.editable === 'top' ? 0 : self.value.data.length - 1;
+ var index = 0;
+ if (self.editable !== 'top') {
+ index = self.value.data.length - 1;
+ // we consider that a new record, created in the bottom,
+ // does not count as a record worth mentioning in the
+ // pager, at least not until the line has been saved.
+ // We prevent the pager from increasing its size, which
+ // means that the pager is not displayed when we just
+ // reach the limit. For example, if limit is 3, if we
+ // have 3 records, and we click on add, we will see the
+ // 4 records on the same page, but we do not want a
+ // pager.
+ self.pager.updateState({ size: self.value.count - 1});
+ }
var newID = self.value.data[index].id;
self.renderer.editRecord(newID);
}