diff --git a/src/addon/mod/quiz/providers/quiz.ts b/src/addon/mod/quiz/providers/quiz.ts index a99e3a2cd..0c5d3599d 100644 --- a/src/addon/mod/quiz/providers/quiz.ts +++ b/src/addon/mod/quiz/providers/quiz.ts @@ -1576,12 +1576,12 @@ export class AddonModQuizProvider { for (let i = 0; i < result.questions.length; i++) { const question = result.questions[i]; - if (!question.displayoptions) { - // Site doesn't return displayoptions, stop. + if (!question.settings) { + // Site doesn't return settings, stop. break; } - question.displayoptions = this.utils.objectToKeyValueMap(question.displayoptions, 'name', 'value'); + question.settings = this.textUtils.parseJSON(question.settings, null); } return result; diff --git a/src/addon/qtype/calculated/providers/handler.ts b/src/addon/qtype/calculated/providers/handler.ts index 20b174edf..22423edb4 100644 --- a/src/addon/qtype/calculated/providers/handler.ts +++ b/src/addon/qtype/calculated/providers/handler.ts @@ -56,14 +56,14 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler { * @return Whether units are in a separate field. */ hasSeparateUnitField(question: any): boolean { - if (!question.displayoptions) { + if (!question.settings) { const element = this.domUtils.convertToElement(question.html); return !!(element.querySelector('select[name*=unit]') || element.querySelector('input[type="radio"]')); } - return question.displayoptions.showunits === AddonQtypeCalculatedHandler.UNITRADIO || - question.displayoptions.showunits === AddonQtypeCalculatedHandler.UNITSELECT; + return question.settings.unitdisplay === AddonQtypeCalculatedHandler.UNITRADIO || + question.settings.unitdisplay === AddonQtypeCalculatedHandler.UNITSELECT; } /** @@ -85,7 +85,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler { return 0; } - if (!question.displayoptions) { + if (!question.settings) { if (this.hasSeparateUnitField(question)) { return this.isValidValue(answers['unit']) ? 1 : 0; } @@ -94,7 +94,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler { return -1; } - if (question.displayoptions.showunits != AddonQtypeCalculatedHandler.UNITINPUT && parsedAnswer.unit) { + if (question.settings.unitdisplay != AddonQtypeCalculatedHandler.UNITINPUT && parsedAnswer.unit) { // There should be no units or be outside of the input, not valid. return 0; } @@ -104,8 +104,8 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler { return 0; } - if (question.displayoptions.showunits == AddonQtypeCalculatedHandler.UNITINPUT && - question.displayoptions.unitgradingtype == AddonQtypeCalculatedHandler.UNITGRADED && + if (question.settings.unitdisplay == AddonQtypeCalculatedHandler.UNITINPUT && + question.settings.unitgradingtype == AddonQtypeCalculatedHandler.UNITGRADED && !this.isValidValue(parsedAnswer.unit)) { // Unit not supplied inside the input and it's required. return 0; @@ -191,7 +191,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler { let unitsLeft = false; let match = null; - if (!question.displayoptions) { + if (!question.settings) { // We don't know if units should be before or after so we check both. match = answer.match(new RegExp('^' + regexString)); if (!match) { @@ -199,7 +199,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler { match = answer.match(new RegExp(regexString + '$')); } } else { - unitsLeft = question.displayoptions.unitsleft == '1'; + unitsLeft = question.settings.unitsleft == '1'; regexString = unitsLeft ? regexString + '$' : '^' + regexString; match = answer.match(new RegExp(regexString)); diff --git a/src/addon/qtype/essay/providers/handler.ts b/src/addon/qtype/essay/providers/handler.ts index 41ae1592b..39d29d9a1 100644 --- a/src/addon/qtype/essay/providers/handler.ts +++ b/src/addon/qtype/essay/providers/handler.ts @@ -74,10 +74,10 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler { * @return Allowed options. */ protected getAllowedOptions(question: any): {text: boolean, attachments: boolean} { - if (question.displayoptions) { + if (question.settings) { return { - text: question.displayoptions.responseformat != 'noinline', - attachments: question.displayoptions.attachments != '0', + text: question.settings.responseformat != 'noinline', + attachments: question.settings.attachments != '0', }; } else { const element = this.domUtils.convertToElement(question.html); @@ -162,11 +162,11 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler { const attachments = CoreFileSession.instance.getFiles(component, questionComponentId); if (!allowedOptions.text) { - return attachments && attachments.length >= Number(question.displayoptions.attachmentsrequired) ? 1 : 0; + return attachments && attachments.length >= Number(question.settings.attachmentsrequired) ? 1 : 0; } - return (hasTextAnswer || question.displayoptions.responserequired == '0') && - (attachments && attachments.length > Number(question.displayoptions.attachmentsrequired)) ? 1 : 0; + return (hasTextAnswer || question.settings.responserequired == '0') && + (attachments && attachments.length > Number(question.settings.attachmentsrequired)) ? 1 : 0; } /** diff --git a/src/core/question/classes/base-question-component.ts b/src/core/question/classes/base-question-component.ts index 160ffa50c..92820067c 100644 --- a/src/core/question/classes/base-question-component.ts +++ b/src/core/question/classes/base-question-component.ts @@ -107,8 +107,8 @@ export class CoreQuestionBaseComponent { this.question.select = selectModel; // Check which one should be displayed first: the select or the input. - if (this.question.displayoptions) { - this.question.selectFirst = this.question.displayoptions.unitsleft == '1'; + if (this.question.settings) { + this.question.selectFirst = this.question.settings.unitsleft == '1'; } else { const input = questionEl.querySelector('input[type="text"][name*=answer]'); this.question.selectFirst = @@ -165,8 +165,8 @@ export class CoreQuestionBaseComponent { } // Check which one should be displayed first: the options or the input. - if (this.question.displayoptions) { - this.question.optionsFirst = this.question.displayoptions.unitsleft == '1'; + if (this.question.settings) { + this.question.optionsFirst = this.question.settings.unitsleft == '1'; } else { const input = questionEl.querySelector('input[type="text"][name*=answer]'); this.question.optionsFirst = @@ -216,11 +216,11 @@ export class CoreQuestionBaseComponent { const textarea = questionEl.querySelector('textarea[name*=_answer]'); const answerDraftIdInput = questionEl.querySelector('input[name*="_answer:itemid"]'); - if (this.question.displayoptions) { - this.question.allowsAttachments = this.question.displayoptions.attachments != '0'; - this.question.allowsAnswerFiles = this.question.displayoptions.responseformat == 'editorfilepicker'; - this.question.isMonospaced = this.question.displayoptions.responseformat == 'monospaced'; - this.question.isPlainText = this.question.isMonospaced || this.question.displayoptions.responseformat == 'plain'; + if (this.question.settings) { + this.question.allowsAttachments = this.question.settings.attachments != '0'; + this.question.allowsAnswerFiles = this.question.settings.responseformat == 'editorfilepicker'; + this.question.isMonospaced = this.question.settings.responseformat == 'monospaced'; + this.question.isPlainText = this.question.isMonospaced || this.question.settings.responseformat == 'plain'; } else { this.question.allowsAttachments = !!questionEl.querySelector('div[id*=filemanager]'); this.question.allowsAnswerFiles = !!answerDraftIdInput; @@ -282,8 +282,11 @@ export class CoreQuestionBaseComponent { }; } - this.question.attachmentsMaxFiles = Number(this.question.displayoptions.attachments); - this.question.attachmentsAcceptedTypes = this.question.displayoptions.filetypeslist; + if (this.question.settings) { + this.question.attachmentsMaxFiles = Number(this.question.settings.attachments); + this.question.attachmentsAcceptedTypes = this.question.settings.filetypeslist && + this.question.settings.filetypeslist.join(','); + } if (fileManagerUrl) { const params = CoreUrlUtils.instance.extractUrlParams(fileManagerUrl);