summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_controller.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2019-03-13 15:42:52 +0000
committerAaron Bohy <aab@odoo.com>2019-04-02 11:55:57 +0000
commit2be28d4d033b5930e5a16ff02407315a116e9043 (patch)
tree0561dbbf8c127d0aea94c6766c6815fe1d1f2d83 /addons/web/static/src/js/views/basic/basic_controller.js
parent5895d23cbd26beb3bc3c83cc760b3cdbb64b0e85 (diff)
[IMP] web,board: enable pagination in grouped lists
With this rev., when there are a lot of groups in a grouped list view, groups are displayed under several pages, whereas they were all displayed in the same page before. This is especially interesting with the new 'expand' attribute, to ensure that we don't read records for a large number of groups. By default, the groups limit is set to 80 (like records), and to 10 is the 'expand' attribute is set to true. This limit can be overriden with the 'groups_limit' attribute. Part of task 1915702
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());
}
},