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 @@ -