summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_controller.js
diff options
context:
space:
mode:
authorRobot Odoo <xmo+roboto@odoo.com>2019-04-02 15:46:39 +0200
committerGitHub <noreply@github.com>2019-04-02 15:46:39 +0200
commit9aea7ae1627e7af10fb03677142ccfc5333f654e (patch)
tree1233647e18260747f3fd315f79f4cae8b06bc0f6 /addons/web/static/src/js/views/basic/basic_controller.js
parenta82dbe4d680149b9bf15b7a122c6f8bd1b3582fa (diff)
parent8ea5a40417c2da2e82db66ad36fbf1e8e78bbe11 (diff)
[MERGE] web,*: list view improvements
This branch brings several improvements related to the list view: - grouped list views are now editable - 'expand' attribute can be used to open by default the first level groups - if there are a lot of groups, a pager is displayed (instead of having all groups in the same page) - when grouped on a many2one field, custom buttons (on the many2one comodel) can be inserted in each group's header - we can edit several records in a row in editable list views - editable lists do not flicker anymore when switching a row to edit mode - we can navigate through the cells in list views with the arrows (in readonly) Co-authored-by: Aaron Bohy aab@odoo.com Co-authored-by: David Monjoie dmo@odoo.com Co-authored-by: Martin Geubelle mge@odoo.com Co-authored-by: Ravi Gadhia rga@odoo.com Task 1915702 closes odoo/odoo#31756 Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_controller.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js76
1 files changed, 48 insertions, 28 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index 19d2fd57892..064f7b84a52 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -148,25 +148,28 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
*/
renderPager: function ($node, options) {
var self = this;
- var data = this.model.get(this.handle, {raw: true});
- this.pager = new Pager(this, data.count, data.offset + 1, data.limit, options);
+ var params = this._getPagerParams();
+ this.pager = new Pager(this, params.size, params.current_min, params.limit, options);
this.pager.on('pager_changed', this, function (newState) {
- var self = this;
this.pager.disable();
- data = this.model.get(this.handle, {raw: true});
+ var data = this.model.get(this.handle, {raw: true});
var limitChanged = (data.limit !== newState.limit);
- this.reload({limit: newState.limit, offset: newState.current_min - 1})
- .then(function () {
- // Reset the scroll position to the top on page changed only
- if (!limitChanged) {
- self.trigger_up('scrollTo', {top: 0});
- }
- })
- .then(this.pager.enable.bind(this.pager));
+ var reloadParams;
+ if (data.groupedBy && data.groupedBy.length) {
+ reloadParams = {groupsLimit: newState.limit, groupsOffset: newState.current_min - 1};
+ } else {
+ reloadParams = {limit: newState.limit, offset: newState.current_min - 1};
+ }
+ this.reload(reloadParams).then(function () {
+ // reset the scroll position to the top on page changed only
+ if (!limitChanged) {
+ self.trigger_up('scrollTo', {top: 0});
+ }
+ }).then(this.pager.enable.bind(this.pager));
});
- return this.pager.appendTo($node).then(function() {
- self._updatePager(); // to force proper visibility
+ return this.pager.appendTo($node).then(function () {
+ self._updatePager(); // to force proper visibility
});
},
/**
@@ -413,6 +416,22 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
});
},
/**
+ * Return the params (current_min, limit and size) to pass to the pager,
+ * according to the current state.
+ *
+ * @private
+ * @returns {Object}
+ */
+ _getPagerParams: function () {
+ var state = this.model.get(this.handle, {raw: true});
+ var isGrouped = state.groupedBy && state.groupedBy.length;
+ return {
+ current_min: (isGrouped ? state.groupsOffset : state.offset) + 1,
+ limit: isGrouped ? state.groupsLimit : state.limit,
+ size: isGrouped ? state.groupsCount : state.count,
+ };
+ },
+ /**
* Returns the new sidebar env
*
* @private
@@ -426,6 +445,16 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
};
},
/**
+ * Determine whether or not the pager must be displayed (probably depending
+ * on the current state). Controllers must override this to implement their
+ * own logic.
+ *
+ * @private
+ */
+ _isPagerVisible: function () {
+ return true;
+ },
+ /**
* Helper function to display a warning that some fields have an invalid
* value. This is used when a save operation cannot be completed.
*
@@ -533,23 +562,14 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
}
},
/**
- * Helper method, to make sure the information displayed by the pager is up
- * to date.
+ * Update the pager with the current state.
+ *
+ * @private
*/
_updatePager: function () {
if (this.pager) {
- var data = this.model.get(this.handle, {raw: true});
- this.pager.updateState({
- current_min: data.offset + 1,
- size: data.count,
- });
- var isRecord = data.type === 'record';
- var hasData = !!data.count;
- var isGrouped = data.groupedBy ? !!data.groupedBy.length : false;
- var isNew = this.model.isNew(this.handle);
- var isPagerVisible = isRecord ? !isNew : (hasData && !isGrouped);
-
- this.pager.do_toggle(isPagerVisible);
+ this.pager.updateState(this._getPagerParams());
+ this.pager.do_toggle(this._isPagerVisible());
}
},