summaryrefslogtreecommitdiff
path: root/addons/survey/static/src/js
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2020-09-24 09:18:11 +0000
committerDavid Beguin <dbe@odoo.com>2020-09-28 16:34:09 +0000
commit13250dfd0ab140b4e60ec3f30832999a867426fc (patch)
tree77111b3d0594622f5bf5fb94dd995cfe24a9548e /addons/survey/static/src/js
parentd92e61e89f468c2db2fbd68b2f0d6b36c77f1065 (diff)
[FIX] survey: ensure to retrieve the participant's answer when restarting
In order to avoid making it possible to follow the same survey multiple times at the same time, a survey cookie is added with the survey token and answer token. When starting the survey, if the cookie contains a valid answer token for that survey token, the survey session is reloaded where the participant left it. When the user finished the survey, the cookie is deleted to allow to retake the survey later, if possible. Note: A participant can still open multiple tabs with the same survey, but it will be linked to the same survey answer. So if the user tries to submit another answer, the late answer will overwrite the previous one. Task ID: 2345468 closes odoo/odoo#58720 X-original-commit: c97c266313aff864f8c397fb1b42f792f9650e5e Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/survey/static/src/js')
-rw-r--r--addons/survey/static/src/js/survey_form.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js
index 661127221c8..d48523e8324 100644
--- a/addons/survey/static/src/js/survey_form.js
+++ b/addons/survey/static/src/js/survey_form.js
@@ -7,6 +7,7 @@ var time = require('web.time');
var core = require('web.core');
var Dialog = require('web.Dialog');
var dom = require('web.dom');
+var utils = require('web.utils');
var _t = core._t;
@@ -35,6 +36,12 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
self.options = self.$target.find('form').data();
self.readonly = self.options.readonly;
self.selectedAnswers = self.options.selectedAnswers;
+
+ // Add Survey cookie to retrieve the survey if you quit the page and restart the survey.
+ if (!utils.get_cookie('survey_' + self.options.surveyToken)) {
+ utils.set_cookie('survey_' + self.options.surveyToken, self.options.answerToken, 60*60*24);
+ }
+
// Init fields
if (!self.options.isStartScreen && !self.readonly) {
self._initTimer();
@@ -422,6 +429,7 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
var selectorsToFadeout = ['.o_survey_form_content'];
if (options.isFinish) {
selectorsToFadeout.push('.breadcrumb', '.o_survey_timer');
+ utils.set_cookie('survey_' + self.options.surveyToken, '', -1); // delete cookie
}
self.$(selectorsToFadeout.join(',')).fadeOut(this.fadeInOutDelay, function () {
resolveFadeOut();