diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-10-01 07:42:45 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-10-21 12:26:12 +0000 |
| commit | 52f67d87d16662970aad9ac46a88bd045eafae82 (patch) | |
| tree | fc3d497245dc9ba47666db1d6197c39a75013af4 /addons/web/static/src/js | |
| parent | 3a7bb6aefdeedd8745187f3d71efbf2abf891d6e (diff) | |
[FIX] web: web_client o_content is scrollable, not action manager
Go on a kanban view with a scroll bar
scroll all the way down
Open a record in form view
Use the breadcrumb to go back to the kanban
Before this commit, the kanban was re-opened
but the position were we were before opening the record was lost
This was due to 40dd121938552d3f88289d2e5fcd1d57a0dd01bb
which refactors the dom, puting the action manager on top of controllers
After this commit, when re-opening the kanban, we end up at the same position
we left it at
OPW 2074077
closes odoo/odoo#39120
X-original-commit: c0d48878c452b256859f067186567c126d8de27e
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/chrome/abstract_web_client.js | 43 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/web_client.js | 43 |
2 files changed, 37 insertions, 49 deletions
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 cd1109a98ce..7f07531dae2 100644 --- a/addons/web/static/src/js/chrome/abstract_web_client.js +++ b/addons/web/static/src/js/chrome/abstract_web_client.js @@ -312,6 +312,24 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi }, //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Returns the left and top scroll positions of the main scrolling area + * (i.e. the '.o_content' div in desktop). + * + * @returns {Object} with keys left and top + */ + getScrollPosition: function () { + var scrollingEl = this.action_manager.el.getElementsByClassName('o_content')[0]; + return { + left: scrollingEl ? scrollingEl.scrollLeft : 0, + top: scrollingEl ? scrollingEl.scrollTop : 0, + }; + }, + + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- @@ -401,14 +419,15 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi } }, /** - * This function must be implemented to provide to the caller the current - * scroll position (left and top) of the webclient. + * Provides to the caller the current scroll position (left and top) of the + * main scrolling area of the webclient. * - * @abstract + * @private * @param {OdooEvent} ev * @param {function} ev.data.callback */ _onGetScrollPosition: function (ev) { + ev.data.callback(this.getScrollPosition()); }, /** * Loads an action from the database given its ID. @@ -432,11 +451,10 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi this.do_push_state(_.extend(e.data.state, {'cids': $.bbq.getState().cids})); }, /** - * This function must be implemented by actual webclient to scroll either to - * a given offset or to a target element (given a selector). + * Scrolls either to a given offset or to a target element (given a selector). * It must be called with: trigger_up('scrollTo', options). * - * @abstract + * @private * @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 @@ -444,6 +462,19 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi * scroll to */ _onScrollTo: function (ev) { + var scrollingEl = this.action_manager.el.getElementsByClassName('o_content')[0]; + if (!scrollingEl) { + return; + } + var offset = {top: ev.data.top, left: ev.data.left || 0}; + if (!offset.top) { + offset = dom.getPosition(document.querySelector(ev.data.selector)); + // Substract the position of the scrolling element + offset.top -= dom.getPosition(scrollingEl).top; + } + + scrollingEl.scrollTop = offset.top; + scrollingEl.scrollLeft = offset.left; }, /** * @private diff --git a/addons/web/static/src/js/chrome/web_client.js b/addons/web/static/src/js/chrome/web_client.js index e79f7d84289..e12f22fcf05 100644 --- a/addons/web/static/src/js/chrome/web_client.js +++ b/addons/web/static/src/js/chrome/web_client.js @@ -238,49 +238,6 @@ return AbstractWebClient.extend({ _openMenu: function (action, options) { return this.do_action(action, options); }, - - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * Returns the left and top scroll positions of the main scrolling area - * (i.e. the action manager in desktop). - * - * @returns {Object} with keys left and top - */ - getScrollPosition: function () { - return { - left: this.action_manager.el.scrollLeft, - top: this.action_manager.el.scrollTop, - }; - }, - - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - - /** - * @override - * @private - */ - _onGetScrollPosition: function (ev) { - ev.data.callback(this.getScrollPosition()); - }, - /** - * @override - * @private - */ - _onScrollTo: function (ev) { - var offset = {top: ev.data.top, left: ev.data.left || 0}; - if (!offset.top) { - offset = dom.getPosition(document.querySelector(ev.data.selector)); - // Substract the position of the action_manager as it is the scrolling part - offset.top -= dom.getPosition(this.action_manager.el).top; - } - this.action_manager.el.scrollTop = offset.top; - this.action_manager.el.scrollLeft = offset.left; - }, }); }); |
