From 4e204ed2233ccd36b2eb7d3e56bfa741b9cb3e14 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 8 Mar 2018 14:57:43 +0100 Subject: [IMP] web: restore scroll position This rev. improves the way the scroll position is restored when coming back to a view (e.g. open a kanban view, scroll, click on a record to open it in a form view, go back to kanban using the breadcrumbs): - generalize the scroll position handling from web_enterprise to web to make it available in the community webclient as well - also restore left scroll position, not only top (especially useful for grouped Kanban views with a lot of columns) - handle the case where the scrolling area is a sub element of the view (e.g. the grouped Kanban view in mobile). Task 34037 Co-authored-by: Mohammed Shekha Co-authored-by: Ankit Sathvara --- .../static/src/js/chrome/abstract_web_client.js | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'addons/web/static/src/js/chrome/abstract_web_client.js') diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js index 9fe38adbde6..87219284e4d 100644 --- a/addons/web/static/src/js/chrome/abstract_web_client.js +++ b/addons/web/static/src/js/chrome/abstract_web_client.js @@ -88,6 +88,8 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, { } }); }, + getScrollPosition: '_onGetScrollPosition', + scrollTo: '_onScrollTo', }, init: function (parent) { this.client_options = {}; @@ -373,6 +375,16 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, { this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky); } }, + /** + * This function must be implemented to provide to the caller the current + * scroll position (left and top) of the webclient. + * + * @abstract + * @param {OdooEvent} ev + * @param {function} ev.data.callback + */ + _onGetScrollPosition: function (ev) { + }, /** * Loads an action from the database given its ID. * @@ -394,6 +406,20 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, { _onPushState: function (e) { this.do_push_state(e.data.state); }, + /** + * This function must be implemented by actual webclient to scroll either to + * a given offset or to a target element (given a selector). + * It must be called with: trigger_up('scrollTo', options). + * + * @abstract + * @param {OdooEvent} ev + * @param {integer} [ev.data.top] the number of pixels to scroll from top + * @param {integer} [ev.data.left] the number of pixels to scroll from left + * @param {string} [ev.data.selector] the selector of the target element to + * scroll to + */ + _onScrollTo: function (ev) { + }, /** * Displays a visual effect (for example, a rainbowman0 * -- cgit v1.2.3