Skip to content

Commit

Permalink
react to a "disable duration" change from the LTI tool
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Oct 10, 2023
1 parent 11ba812 commit e6bcaa1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion runtime/scripts/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,10 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
}
var data = this.store.getDurationExtension();
if(data) {
if(data.disabled) {
this.changeDuration(0);
return;
}
var extension = 0;
switch(data.units) {
case 'minutes':
Expand All @@ -956,6 +960,15 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
changeDuration: function(duration) {
var diff = duration - this.settings.duration;
this.settings.duration = duration;

if(diff != 0) {
if( this.settings.duration > 0 ) {
this.events.trigger('showTiming');
} else {
this.events.trigger('hideTiming');
}
}

this.timeRemaining += diff;
if(this.stopwatch) {
this.stopwatch.end = new Date(this.stopwatch.end.getTime() + diff*1000);
Expand All @@ -972,7 +985,7 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
var duration = this.settings.duration;
this.displayDuration = duration>0 ? Numbas.timing.secsToDisplayTime( duration ) : '';
this.events.trigger('updateDisplayDuration', duration);
this.display && this.display.showTiming();
this.display && (duration > 0 ? this.display.showTiming() : this.display.hideTiming());
this.events.trigger('showTiming');
},

Expand Down
2 changes: 2 additions & 0 deletions runtime/scripts/scorm-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ SCORMStorage.prototype = /** @lends Numbas.storage.SCORMStorage.prototype */ {
getDurationExtension: function() {
var duration_extension = pipwerks.SCORM.get('numbas.duration_extension.amount');
var duration_extension_units = pipwerks.SCORM.get('numbas.duration_extension.units');
var disable_duration = pipwerks.SCORM.get('numbas.disable_duration') == 'true';
return {
disabled: disable_duration,
amount: duration_extension,
units: duration_extension_units
}
Expand Down
2 changes: 1 addition & 1 deletion themes/default/files/scripts/exam-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ Numbas.queueScript('exam-display',['display-base','math','util','timing'],functi
showTiming: function()
{
this.duration(this.exam.settings.duration);
this.displayTime(Numbas.timing.secsToDisplayTime(this.exam.timeRemaining));
this.displayTime(Numbas.timing.secsToDisplayTime(Math.max(0, this.exam.timeRemaining)));
this.timeSpent(Numbas.timing.secsToDisplayTime(this.exam.timeSpent));
},
/** Initialise the question list display.
Expand Down

0 comments on commit e6bcaa1

Please sign in to comment.