diff options
| author | Joseph Caburnay <jcb@odoo.com> | 2020-07-02 12:12:34 +0000 |
|---|---|---|
| committer | Joseph Caburnay <jcb@odoo.com> | 2020-07-15 11:39:43 +0000 |
| commit | d51b56e20ddc86ef29661e2a93510432e7666680 (patch) | |
| tree | 0c4877c0a252f1af0a2f745c526b8bac905046ab /addons/pos_restaurant/static/src | |
| parent | 4ed4ac54749dbf87df840109dfda3c9002c16fa3 (diff) | |
[FIX] pos_restaurant: idle timer not resetting properly
1. Idle timer is now reset also for touch events.
2. Using onWillUnmount and onMounted hooks to add event listener to
window for detecting activities is not possible in this situation
because setting the listener depends on a pos.config field
(iface_floorplan) which is only available after 'start' is finished.
(Remember that hooks are required to be set in the constructor.)
So instead of using those hooks, we replicate them by using a global
variable IDLE_TIMER_SETTER. This variable holds the bound method
_setIdleTimer and set it as callback to each event listener.
Then, before closing pos, we remove the listeners.
3. Close present temporary screen when going back to floor screen
after idle timer.
closes odoo/odoo#54498
X-original-commit: de1430d71890da24547fe24ba04dd28f59f77ee0
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/pos_restaurant/static/src')
| -rw-r--r-- | addons/pos_restaurant/static/src/js/Chrome.js | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/addons/pos_restaurant/static/src/js/Chrome.js b/addons/pos_restaurant/static/src/js/Chrome.js index cff845b2650..399a3887125 100644 --- a/addons/pos_restaurant/static/src/js/Chrome.js +++ b/addons/pos_restaurant/static/src/js/Chrome.js @@ -1,11 +1,13 @@ -odoo.define('pos_restaurant.chrome', function(require) { +odoo.define('pos_restaurant.chrome', function (require) { 'use strict'; const Chrome = require('point_of_sale.Chrome'); - const { onWillUnmount } = owl.hooks; const Registries = require('point_of_sale.Registries'); - const PosResChrome = Chrome => + const NON_IDLE_EVENTS = 'mousemove mousedown touchstart touchend touchmove click scroll keypress'.split(/\s+/); + let IDLE_TIMER_SETTER; + + const PosResChrome = (Chrome) => class extends Chrome { /** * @override @@ -49,13 +51,9 @@ odoo.define('pos_restaurant.chrome', function(require) { } } _setActivityListeners() { - const events = 'mousemove mousedown touchstart click scroll keypress'.split(' '); - const boundHandler = this._setIdleTimer.bind(this); - for (let eventName of events) { - this.el.addEventListener(eventName, boundHandler); - onWillUnmount(() => { - this.el.removeEventListener(eventName, boundHandler); - }); + IDLE_TIMER_SETTER = this._setIdleTimer.bind(this); + for (const event of NON_IDLE_EVENTS) { + window.addEventListener(event, IDLE_TIMER_SETTER); } } _setIdleTimer() { @@ -67,19 +65,31 @@ odoo.define('pos_restaurant.chrome', function(require) { } } _actionAfterIdle() { + if (this.tempScreen.isShown) { + this.trigger('close-temp-screen'); + } this.showScreen('FloorScreen', { floor: this.env.pos.table.floor }); } _shouldResetIdleTimer() { - return ( - this.env.pos.config.iface_floorplan && - this.mainScreen.name !== 'FloorScreen' && - !this.tempScreen.isShown - ); + return this.env.pos.config.iface_floorplan && this.mainScreen.name !== 'FloorScreen'; } __showScreen() { super.__showScreen(...arguments); this._setIdleTimer(); } + /** + * @override + * Before closing pos, we remove the event listeners set on window + * for detecting activities outside FloorScreen. + */ + async _closePos() { + if (IDLE_TIMER_SETTER) { + for (const event of NON_IDLE_EVENTS) { + window.removeEventListener(event, IDLE_TIMER_SETTER); + } + } + await super._closePos(); + } }; Registries.Component.extend(Chrome, PosResChrome); |
