Skip to content

Commit

Permalink
Handle/respect typeendtoleave navigation option
Browse files Browse the repository at this point in the history
Rename 'OK' button 'End exam' on confirm-end-exam-modal
  • Loading branch information
stuwilmur authored and christianp committed Nov 9, 2023
1 parent 2e558fe commit aefdd3f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 23 deletions.
4 changes: 3 additions & 1 deletion bin/exam.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def __init__(self,name='Untitled Exam'):
'showresultspage': 'oncompletion',
'onleave': Event('onleave','none','You have not finished the current question'),
'preventleave': True,
'typeendtoleave': False,
'startpassword': '',
'allowAttemptDownload': False,
'downloadEncryptionKey': '',
Expand Down Expand Up @@ -192,7 +193,7 @@ def fromDATA(builder, data):

if haskey(data,'navigation'):
nav = data['navigation']
tryLoad(nav,['allowregen','navigatemode','reverse','browse','allowsteps','showfrontpage','showresultspage','preventleave','startpassword','allowAttemptDownload','downloadEncryptionKey'],exam.navigation)
tryLoad(nav,['allowregen','navigatemode','reverse','browse','allowsteps','showfrontpage','showresultspage','preventleave','typeendtoleave','startpassword','allowAttemptDownload','downloadEncryptionKey'],exam.navigation)
if 'onleave' in nav:
tryLoad(nav['onleave'],['action','message'],exam.navigation['onleave'])

Expand Down Expand Up @@ -282,6 +283,7 @@ def toxml(self):
'showfrontpage': strcons_fix(self.navigation['showfrontpage']),
'showresultspage': strcons_fix(self.navigation['showresultspage']),
'preventleave': strcons_fix(self.navigation['preventleave']),
'typeendtoleave': strcons_fix(self.navigation['typeendtoleave']),
'startpassword': strcons(self.navigation['startpassword']),
'allowAttemptDownload': strcons_fix(self.navigation['allowAttemptDownload']),
'downloadEncryptionKey': strcons(self.navigation['downloadEncryptionKey'])
Expand Down
1 change: 1 addition & 0 deletions locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"extension.not found": "Couldn't load the extension <code>{{name}}</code>.",
"modal.confirm": "Confirm",
"modal.confirm end exam": "Write <code>{{endConfirmation}}</code> in the box to confirm:",
"modal.end exam button": "End exam",
"modal.alert": "Alert",
"modal.ok": "OK",
"modal.cancel": "Cancel",
Expand Down
29 changes: 20 additions & 9 deletions runtime/scripts/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
tryGetAttribute(settings,
xml,
'settings/navigation',
['allowregen','navigatemode','reverse','browse','allowsteps','showfrontpage','showresultspage','preventleave','startpassword','allowAttemptDownload','downloadEncryptionKey'],
['allowRegen','navigateMode','navigateReverse','navigateBrowse','allowSteps','showFrontPage','showResultsPage','preventLeave','startPassword','allowAttemptDownload','downloadEncryptionKey']);
['allowregen','navigatemode','reverse','browse','allowsteps','showfrontpage','showresultspage','preventleave','typeendtoleave','startpassword','allowAttemptDownload','downloadEncryptionKey'],
['allowRegen','navigateMode','navigateReverse','navigateBrowse','allowSteps','showFrontPage','showResultsPage','preventLeave','typeendtoleave','startPassword','allowAttemptDownload','downloadEncryptionKey']);
//get navigation events and actions
var navigationEventNodes = xml.selectNodes('settings/navigation/event');
for( var i=0; i<navigationEventNodes.length; i++ ) {
Expand Down Expand Up @@ -228,7 +228,7 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
}
var navigation = tryGet(data,'navigation');
if(navigation) {
tryLoad(navigation,['allowRegen','allowSteps','showFrontPage','showResultsPage','preventLeave','startPassword','allowAttemptDownload','downloadEncryptionKey','navigateMode'],settings);
tryLoad(navigation,['allowRegen','allowSteps','showFrontPage','showResultsPage','preventLeave','typeendtoleave','startPassword','allowAttemptDownload','downloadEncryptionKey','navigateMode'],settings);
tryLoad(navigation,['reverse','browse'],settings,['navigateReverse','navigateBrowse']);
var onleave = tryGet(navigation,'onleave');
settings.navigationEvents.onleave = ExamEvent.createFromJSON('onleave',onleave);
Expand Down Expand Up @@ -355,6 +355,7 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
* @property {boolean} shuffleQuestionGroups - randomize question group order?
* @property {number} numQuestions - number of questions in this sitting
* @property {boolean} preventLeave - prevent the browser from leaving the page while the exam is running?
* @property {boolean} typeendtoleave - require written confirmation before leaving the exam?
* @property {string} startPassword - password the student must enter before beginning the exam
* @property {boolean} allowRegen -can student re-randomise a question?
* @property {boolean} allowAttemptDownload - Can the student download their results as a CSV?
Expand Down Expand Up @@ -1213,12 +1214,22 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
message = R('control.not all questions submitted') + '<br/>' + message;
}
if(Numbas.display) {
Numbas.display.showConfirmEndExam(
message,
function() {
exam.end(true);
}
);
if (exam.settings.typeendtoleave) {
Numbas.display.showConfirmEndExam(
message,
function() {
exam.end(true);
}
);
}
else {
Numbas.display.showConfirm(
message,
function() {
exam.end(true);
}
);
}
} else {
exam.end(true);
}
Expand Down
4 changes: 4 additions & 0 deletions schema/exam_schema.7.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@
"title": "Confirm before leaving the exam while it's running?",
"type": "boolean"
},
"typeendtoleave": {
"title": "Require written confirmation before leaving the exam",
"type": "boolean"
},
"reverse": {
"title": "Allow move to previous question?",
"type": "boolean"
Expand Down
10 changes: 7 additions & 3 deletions tests/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,8 @@ Numbas.locale = {
"die.error": "Error",
"extension.not found": "Couldn't load the extension <code>{{name}}</code>.",
"modal.confirm": "Confirm",
"modal.confirm end exam": "Write '{{endConfirmation}}' in the box below to confirm.",
"modal.confirm end exam": "Write <code>{{endConfirmation}}</code> in the box to confirm:",
"modal.end exam button": "End exam",
"modal.alert": "Alert",
"modal.ok": "OK",
"modal.cancel": "Cancel",
Expand Down Expand Up @@ -1559,7 +1560,9 @@ Numbas.locale = {
"control.style options": "Display options",
"control.move to next question": "Move to the next question",
"control.show introduction": "Introduction",
"control.end confirmation": "end",
"control.confirm end.correct": "You may now end the exam.",
"control.confirm end.incorrect": "This is not the expected text.",
"control.confirm end.password": "end",
"display.answer widget.unknown widget type": "The answer widget type <code>{{name}}</code> is not recognised.",
"display.part.jme.error making maths": "Error making maths display",
"display.error making html": "Error making HTML in {{contextDescription}}: {{-message}}",
Expand Down Expand Up @@ -1934,7 +1937,8 @@ Numbas.locale = {
"worksheet.reconfigure": "Generate different sheets",
"worksheet.show sheet": "Preview the sheet with ID:",
"worksheet.answersheet show question content": "Show question content in answer sheets?"
}}
}
}
,
"en-school": {translation:
{
Expand Down
29 changes: 20 additions & 9 deletions tests/numbas-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -23269,8 +23269,8 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
tryGetAttribute(settings,
xml,
'settings/navigation',
['allowregen','navigatemode','reverse','browse','allowsteps','showfrontpage','showresultspage','preventleave','startpassword','allowAttemptDownload','downloadEncryptionKey'],
['allowRegen','navigateMode','navigateReverse','navigateBrowse','allowSteps','showFrontPage','showResultsPage','preventLeave','startPassword','allowAttemptDownload','downloadEncryptionKey']);
['allowregen','navigatemode','reverse','browse','allowsteps','showfrontpage','showresultspage','preventleave','typeendtoleave','startpassword','allowAttemptDownload','downloadEncryptionKey'],
['allowRegen','navigateMode','navigateReverse','navigateBrowse','allowSteps','showFrontPage','showResultsPage','preventLeave','typeendtoleave','startPassword','allowAttemptDownload','downloadEncryptionKey']);
//get navigation events and actions
var navigationEventNodes = xml.selectNodes('settings/navigation/event');
for( var i=0; i<navigationEventNodes.length; i++ ) {
Expand Down Expand Up @@ -23392,7 +23392,7 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
}
var navigation = tryGet(data,'navigation');
if(navigation) {
tryLoad(navigation,['allowRegen','allowSteps','showFrontPage','showResultsPage','preventLeave','startPassword','allowAttemptDownload','downloadEncryptionKey','navigateMode'],settings);
tryLoad(navigation,['allowRegen','allowSteps','showFrontPage','showResultsPage','preventLeave','typeendtoleave','startPassword','allowAttemptDownload','downloadEncryptionKey','navigateMode'],settings);
tryLoad(navigation,['reverse','browse'],settings,['navigateReverse','navigateBrowse']);
var onleave = tryGet(navigation,'onleave');
settings.navigationEvents.onleave = ExamEvent.createFromJSON('onleave',onleave);
Expand Down Expand Up @@ -23519,6 +23519,7 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
* @property {boolean} shuffleQuestionGroups - randomize question group order?
* @property {number} numQuestions - number of questions in this sitting
* @property {boolean} preventLeave - prevent the browser from leaving the page while the exam is running?
* @property {boolean} typeendtoleave - require written confirmation before leaving the exam?
* @property {string} startPassword - password the student must enter before beginning the exam
* @property {boolean} allowRegen -can student re-randomise a question?
* @property {boolean} allowAttemptDownload - Can the student download their results as a CSV?
Expand Down Expand Up @@ -24377,12 +24378,22 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
message = R('control.not all questions submitted') + '<br/>' + message;
}
if(Numbas.display) {
Numbas.display.showConfirmEndExam(
message,
function() {
exam.end(true);
}
);
if (exam.settings.typeendtoleave) {
Numbas.display.showConfirmEndExam(
message,
function() {
exam.end(true);
}
);
}
else {
Numbas.display.showConfirm(
message,
function() {
exam.end(true);
}
);
}
} else {
exam.end(true);
}
Expand Down
2 changes: 1 addition & 1 deletion themes/default/templates/modals.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h4 id="confirm-end-exam-modal-title" data-localise="modal.confirm"></h4>
</div>
<div class="modal-footer">
<button type="button" class="cancel btn btn-default" data-dismiss="modal" data-localise="modal.cancel"></button>
<button type="button" class="ok btn btn-primary" data-dismiss="modal" data-bind="disable: !confirmEndHandler.valid(), css: confirmEndHandler.feedback().buttonClass" data-localise="modal.ok"></button>
<button type="button" class="ok btn btn-primary" data-dismiss="modal" data-bind="disable: !confirmEndHandler.valid(), css: confirmEndHandler.feedback().buttonClass" data-localise="modal.end exam button"></button>
</div>
</div>
</div>
Expand Down

0 comments on commit aefdd3f

Please sign in to comment.