summaryrefslogtreecommitdiff
path: root/addons/survey/static/src/js
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2020-04-03 14:11:44 +0000
committerAurélien Warnon <awa@odoo.com>2020-04-08 07:33:14 +0000
commitf4803d548bf034489cd459949eebbac2a704e669 (patch)
tree577767d80dc7bfdb76d33c1290712afce418a402 /addons/survey/static/src/js
parente3b5b20b39ddd6faefb8edada3b0c42d769376c7 (diff)
[FIX] survey: fix survey timer related issues
This commit fixes timer related issues on survey flows, for both regulars surveys and survey sessions. The timer was unreliable in its completion by a whole second, which had not a big impact at the user level but could make some tests fail (randomly). Side changes from this commit: - Reduced delays in the survey session tests to speed up testing - Removed some timer flickering on survey views LINKS Task 2230526 Runbot error ID 535 closes odoo/odoo#49178 X-original-commit: 15c72aec71d42624685fb0fc9df25279c7855310 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_session_manage.js5
-rw-r--r--addons/survey/static/src/js/survey_timer.js27
2 files changed, 18 insertions, 14 deletions
diff --git a/addons/survey/static/src/js/survey_session_manage.js b/addons/survey/static/src/js/survey_session_manage.js
index 897aab6d7b3..79d53a2db91 100644
--- a/addons/survey/static/src/js/survey_session_manage.js
+++ b/addons/survey/static/src/js/survey_session_manage.js
@@ -26,6 +26,7 @@ publicWidget.registry.SurveySessionManage = publicWidget.Widget.extend({
*/
start: function () {
var self = this;
+ this.fadeInOutTime = 500;
return this._super.apply(this, arguments).then(function () {
// general survey props
self.surveyId = self.$el.data('surveyId');
@@ -304,7 +305,7 @@ publicWidget.registry.SurveySessionManage = publicWidget.Widget.extend({
var resolveFadeOut;
var fadeOutPromise = new Promise(function (resolve, reject) { resolveFadeOut = resolve; });
- this.$el.fadeOut(500, function () {
+ this.$el.fadeOut(this.fadeInOutTime, function () {
resolveFadeOut();
});
@@ -323,7 +324,7 @@ publicWidget.registry.SurveySessionManage = publicWidget.Widget.extend({
var $renderedTemplate = $(results[1]);
self.$el.replaceWith($renderedTemplate);
self.attachTo($renderedTemplate);
- self.$el.fadeIn(500, function () {
+ self.$el.fadeIn(self.fadeInOutTime, function () {
self._startTimer();
});
} else {
diff --git a/addons/survey/static/src/js/survey_timer.js b/addons/survey/static/src/js/survey_timer.js
index d0a38c88324..2bfd78fedf8 100644
--- a/addons/survey/static/src/js/survey_timer.js
+++ b/addons/survey/static/src/js/survey_timer.js
@@ -25,17 +25,16 @@ publicWidget.registry.SurveyTimerWidget = publicWidget.Widget.extend({
* @override
*/
start: function () {
- var superDef = this._super.apply(this, arguments);
-
- this.countDownDate = moment.utc(this.timer).add(this.timeLimitMinutes, 'minutes');
- if (this.timeLimitMinutes <= 0 || this.countDownDate.diff(moment.utc(), 'seconds') < 0) {
- this.trigger_up('time_up');
- } else {
- this._updateTimer(this);
- this.surveyTimerInterval = setInterval(this._updateTimer.bind(this), 1000);
- }
-
- return superDef;
+ var self = this;
+ return this._super.apply(this, arguments).then(function () {
+ self.countDownDate = moment.utc(self.timer).add(self.timeLimitMinutes, 'minutes');
+ if (self.timeLimitMinutes <= 0 || self.countDownDate.diff(moment.utc(), 'seconds') < 0) {
+ self.trigger_up('time_up');
+ } else {
+ self._updateTimer();
+ self.surveyTimerInterval = setInterval(self._updateTimer.bind(self), 1000);
+ }
+ });
},
// -------------------------------------------------------------------------
@@ -49,9 +48,13 @@ publicWidget.registry.SurveyTimerWidget = publicWidget.Widget.extend({
/**
* This function is responsible for the visual update of the timer DOM every second.
* When the time runs out, it triggers a 'time_up' event to notify the parent widget.
+ *
+ * We use a diff in millis and not a second, that we round to the nearest second.
+ * Indeed, a difference of 999 millis is interpreted as 0 second by moment, which is problematic
+ * for our use case.
*/
_updateTimer: function () {
- var timeLeft = this.countDownDate.diff(moment.utc(), 'seconds');
+ var timeLeft = Math.round(this.countDownDate.diff(moment.utc(), 'milliseconds') / 1000);
if (timeLeft >= 0) {
var timeLeftMinutes = parseInt(timeLeft / 60);