|
14 | 14 | // limitations under the License. |
15 | 15 |
|
16 | 16 | import { Injectable, Injector } from '@angular/core'; |
| 17 | +import { CoreSites } from '@providers/sites'; |
17 | 18 | import { CoreTextUtilsProvider } from '@providers/utils/text'; |
18 | 19 | import { CoreDomUtilsProvider } from '@providers/utils/dom'; |
19 | 20 | import { CoreUtilsProvider } from '@providers/utils/utils'; |
@@ -68,11 +69,11 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler { |
68 | 69 |
|
69 | 70 | if (element.querySelector('div[id*=filemanager]')) { |
70 | 71 | // The question allows attachments. Since the app cannot attach files yet we will prevent submitting the question. |
71 | | - return 'core.question.errorattachmentsnotsupported'; |
| 72 | + return 'core.question.errorattachmentsnotsupportedinsite'; |
72 | 73 | } |
73 | 74 |
|
74 | 75 | if (this.questionHelper.hasDraftFileUrls(element.innerHTML)) { |
75 | | - return 'core.question.errorinlinefilesnotsupported'; |
| 76 | + return 'core.question.errorinlinefilesnotsupportedinsite'; |
76 | 77 | } |
77 | 78 | } |
78 | 79 |
|
@@ -139,13 +140,21 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler { |
139 | 140 | * @param siteId Site ID. If not defined, current site. |
140 | 141 | * @return Return a promise resolved when done if async, void if sync. |
141 | 142 | */ |
142 | | - prepareAnswers(question: any, answers: any, offline: boolean, siteId?: string): void | Promise<any> { |
| 143 | + async prepareAnswers(question: any, answers: any, offline: boolean, siteId?: string): Promise<void> { |
143 | 144 | const element = this.domUtils.convertToElement(question.html); |
144 | 145 |
|
145 | 146 | // Search the textarea to get its name. |
146 | 147 | const textarea = <HTMLTextAreaElement> element.querySelector('textarea[name*=_answer]'); |
147 | 148 |
|
148 | 149 | if (textarea && typeof answers[textarea.name] != 'undefined') { |
| 150 | + if (this.questionHelper.hasDraftFileUrls(question.html) && question.responsefileareas) { |
| 151 | + // Restore draftfile URLs. |
| 152 | + const site = await CoreSites.instance.getSite(siteId); |
| 153 | + |
| 154 | + answers[textarea.name] = this.textUtils.restoreDraftfileUrls(site.getURL(), answers[textarea.name], |
| 155 | + question.html, this.questionHelper.getResponseFileAreaFiles(question, 'answer')); |
| 156 | + } |
| 157 | + |
149 | 158 | // Add some HTML to the text if needed. |
150 | 159 | answers[textarea.name] = this.textUtils.formatHtmlLines(answers[textarea.name]); |
151 | 160 | } |
|
0 commit comments