diff options
| author | David Beguin <dbe@odoo.com> | 2020-09-24 12:22:35 +0000 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2020-10-02 11:43:18 +0000 |
| commit | c8ce021349e89c113f2323c8402ed65ff4921f3d (patch) | |
| tree | b0fbcce52ba596c8a3b0097a35a0d0dfcb88c8bc /addons/survey | |
| parent | 44e88e55f86e9496cfe0261a23c3b98b9aa59f70 (diff) | |
[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#58987
X-original-commit: d5a1c104278e942f7fe332457c622a51dd647cfc
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/survey')
| -rw-r--r-- | addons/survey/static/src/js/survey_form.js | 33 | ||||
| -rw-r--r-- | 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 @@ </form> <!-- Modal used to display error message, i.c.o. ajax error --> - <div role="dialog" class="modal fade" id="AJAXErrorModal" > + <div role="dialog" class="modal fade" id="MasterTabErrorModal" > <div class="modal-dialog"> <div class="modal-content"> <header class="modal-header"> <h4 class="modal-title">A problem has occured</h4> <button type="button" class="close" data-dismiss="modal" aria-label="Close">&times;</button> </header> - <main class="modal-body"><p>Something went wrong while contacting survey server. <strong class="text-danger">Your answers have probably not been recorded.</strong> Try refreshing.</p></main> - <footer class="modal-footer"><button type="button" class="btn btn-primary" data-dismiss="modal">Close</button></footer> + <main class="modal-body"><p>To take this survey, please close all other tabs on <strong class="text-danger"></strong>.</p></main> + <footer class="modal-footer"><button type="button" class="btn btn-primary" data-dismiss="modal">Continue here</button></footer> </div> </div> </div> |
