From 851e68ef406f0a901a064029efde131be49b9184 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Thu, 24 Sep 2020 12:22:35 +0000 Subject: [PATCH] [FIX-IMP] survey: add check on master tab As survey session only works correctly when current tab is the master tab on the bus, an error message is shown to user when this is not the case. The user should close all other tabs on the same hostname before taking the survey. Task ID: 2345468 closes odoo/odoo#58989 X-original-commit: d5a1c104278e942f7fe332457c622a51dd647cfc Signed-off-by: Thibault Delavallee (tde) --- addons/survey/static/src/js/survey_form.js | 33 ++++++++++++++++++++++ addons/survey/views/survey_templates.xml | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js index 4ee30dd0f23..5f178b40175 100644 --- a/addons/survey/static/src/js/survey_form.js +++ b/addons/survey/static/src/js/survey_form.js @@ -852,10 +852,20 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ * @private */ _initSessionManagement: function () { + var self = this; if (this.options.surveyToken && this.options.sessionInProgress) { this.call('bus_service', 'addChannel', this.options.surveyToken); this.call('bus_service', 'startPolling'); + if (!this._checkIsMasterTab()) { + this.shouldReloadMasterTab = true; + this.masterTabCheckInterval = setInterval(function() { + if (self._checkIsMasterTab()) { + clearInterval(self.masterTabCheckInterval); + } + }, 2000); + } + this.call('bus_service', 'onNotification', this, this._onNotification); } }, @@ -977,6 +987,29 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ } }, + /** + * This method check if the current tab is the master tab at the bus level. + * If not, the survey could not receive next question notification anymore from session manager. + * We then ask the participant to close all other tabs on the same hostname before letting them continue. + * + * @private + */ + _checkIsMasterTab: function () { + var isMasterTab = this.call('bus_service', 'isMasterTab'); + var $errorModal = this.$('#MasterTabErrorModal'); + if (isMasterTab) { + // Force reload the page when survey is ready to be followed, to force restart long polling + if (this.shouldReloadMasterTab) { + window.location.reload(); + } + return true; + } else if (!$errorModal.modal._isShown){ + $errorModal.find('.text-danger').text(window.location.hostname); + $errorModal.modal('show'); + } + return false; + }, + // CONDITIONAL QUESTIONS MANAGEMENT TOOLS // ------------------------------------------------------------------------- diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index e42c863eaa7..103e982ad59 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -111,15 +111,15 @@ -