[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) <tde@openerp.com>
This commit is contained in:
David Beguin
2020-10-02 12:12:07 +00:00
parent d27b07e565
commit 851e68ef40
2 changed files with 36 additions and 3 deletions
@@ -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
// -------------------------------------------------------------------------
+3 -3
View File
@@ -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">&amp;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>