Skip to content

Commit

Permalink
Fixed issue #16452: When admin previews surveys timer is not reset in…
Browse files Browse the repository at this point in the history
… between runs (#1476)

On preview mode, set the 'resetQuestionTimers' js flag from server side, so timer.js can pick it and unset the localstorage (so, timer gets reset)
  • Loading branch information
gabrieljenik committed Jul 11, 2020
1 parent 15b441a commit 6e447fe
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions application/controllers/survey/index.php
Expand Up @@ -593,6 +593,11 @@ public function action()
initFieldArray($surveyid, $_SESSION['survey_'.$surveyid]['fieldmap']);
}

// Reset the question timers in preview
if (!$isSurveyActive || $previewmode) {
resetQuestionTimers();
}

sendCacheHeaders();

//Send local variables to the appropriate survey type
Expand Down
10 changes: 9 additions & 1 deletion application/helpers/frontend_helper.php
Expand Up @@ -1943,7 +1943,7 @@ function killSurveySession($iSurveyID)

/**
* Resets all question timers by expiring the related cookie - this needs to be called before any output is done
* @todo Make cookie survey ID aware
* @todo Deprecated - Question timers no longer use cookies
*/
function resetTimers()
{
Expand All @@ -1952,6 +1952,14 @@ function resetTimers()
Yii::app()->request->cookies['limesurvey_timers'] = $cookie;
}

/**
* Sets the 'resetQuestionTimers' flag, so timer.js can pick it and unset the localstorage
*/
function resetQuestionTimers()
{
Yii::app()->clientScript->registerScript('resetQuestionTimers', "LSvar.bResetQuestionTimers=true;", LSYii_ClientScript::POS_BEGIN);
}

/**
* Set the public survey language
* Control if language exist in this survey, else set to survey default language
Expand Down
4 changes: 4 additions & 0 deletions assets/packages/questions/timer/src/timeclass.js
Expand Up @@ -296,6 +296,10 @@ export default class TimerConstructor {
this.intervalObject = null;
this.warning = 0;
this.timersessionname = 'timer_question_' + this.option.questionid;

// Unser timer in local storage if the reset timers flag is set
if (LSvar.bResetQuestionTimers) this._unsetTimerInLocalStorage();

this.timeLeft = this._getTimerFromLocalStorage() || this.option.timer;
this.disable_next = $("#disablenext-" + this.timersessionname).val();
this.disable_prev = $("#disableprev-" + this.timersessionname).val();
Expand Down
6 changes: 5 additions & 1 deletion assets/packages/questions/timer/timer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/packages/questions/timer/timer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e447fe

Please sign in to comment.