Skip to content

Commit 0f34307

Browse files
committed
MOBILE-1577 quiz: Handle all kind of essay questions
1 parent 31f092b commit 0f34307

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

www/addons/qtype/essay/directive.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,21 @@ angular.module('mm.addons.qtype_essay')
3030
templateUrl: 'addons/qtype/essay/template.html',
3131
link: function(scope) {
3232
var questionEl = $mmQuestionHelper.directiveInit(scope, $log),
33-
question = scope.question,
3433
textarea;
3534

3635
if (questionEl) {
3736
questionEl = questionEl[0] || questionEl; // Convert from jqLite to plain JS if needed.
3837

3938
// First search the textarea.
40-
textarea = questionEl.querySelector('textarea[id*=answer_id]');
39+
textarea = questionEl.querySelector('textarea[name*=_answer]');
40+
scope.allowsAttachments = !!questionEl.querySelector('div[id*=filemanager]');
41+
scope.isMonospaced = !!questionEl.querySelector('.qtype_essay_monospaced');
4142

4243
if (!textarea) {
43-
// Textarea not found, we're probably in review. Search the answer and the attachments.
44-
if (questionEl.querySelector('.qtype_essay_response')) {
45-
scope.answer = $mmUtil.getContentsOfElement(angular.element(questionEl), '.qtype_essay_response');
46-
scope.attachments = $mmQuestionHelper.getQuestionAttachmentsFromHtml(
47-
$mmUtil.getContentsOfElement(angular.element(questionEl), '.attachments'));
48-
} else {
49-
// Answer not found. Abort.
50-
$log.warn('Aborting because couldn\'t find textarea or answer.', question.name);
51-
return $mmQuestionHelper.showDirectiveError(scope);
52-
}
44+
// Textarea not found, we might be in review. Search the answer and the attachments.
45+
scope.answer = $mmUtil.getContentsOfElement(angular.element(questionEl), '.qtype_essay_response');
46+
scope.attachments = $mmQuestionHelper.getQuestionAttachmentsFromHtml(
47+
$mmUtil.getContentsOfElement(angular.element(questionEl), '.attachments'));
5348
} else {
5449
// Textarea found.
5550
var input = questionEl.querySelector('input[type="hidden"][name*=answerformat]'),

www/addons/qtype/essay/template.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
<label class="item item-input" ng-if="textarea">
66
<!-- "Format" hidden input -->
77
<input ng-if="formatInput" type="hidden" name="{{formatInput.name}}" value="{{formatInput.value}}" >
8-
<textarea class="mm-question-textarea" placeholder="{{ 'mm.question.answer' | translate }}" name="{{textarea.name}}" aria-multiline="true">{{textarea.value}}</textarea>
8+
<textarea class="mm-question-textarea" ng-class='{"mm-monospaced": isMonospaced}' placeholder="{{ 'mm.question.answer' | translate }}" name="{{textarea.name}}" aria-multiline="true">{{textarea.value}}</textarea>
99
</label>
10-
<div class="item item-text-wrap" ng-if="!textarea">
11-
<p><mm-format-text watch="true">{{answer}}</mm-format-text></p>
10+
<div class="item item-text-wrap" ng-if="allowsAttachments">
11+
<p class="mm-question-warning">{{ 'mm.question.errorattachmentsnotsupported' | translate }}</p>
12+
</div>
13+
<div class="item item-text-wrap" ng-if="!textarea && (answer || (!attachments.length && !allowsAttachments))">
14+
<p><mm-format-text watch="true" ng-class='{"mm-monospaced": isMonospaced}'>{{answer}}</mm-format-text></p>
1215
</div>
1316
<div class="item" ng-if="!textarea && attachments && attachments.length">
1417
<mm-file ng-repeat="attachment in attachments" file="attachment" component="{{component}}" component-id="{{componentId}}"></mm-file>

www/core/components/question/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"certainty": "Certainty",
55
"complete": "Complete",
66
"correct": "Correct",
7+
"errorattachmentsnotsupported": "The application doesn't support attaching files to answers yet.",
78
"errorquestionnotsupported": "This type of question isn't supported by the app in your site: {{$a}}.",
89
"feedback": "Feedback",
910
"howtodraganddrop": "Tap to select then tap to drop.",

www/core/components/question/scss/styles.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $mm-question-incorrect-color: #b94a48 !default;
44
$mm-question-state-correct-color: #cfc !default;
55
$mm-question-state-partial-color: #ffa !default;
66
$mm-question-state-incorrect-color: #fcc !default;
7+
$mm-question-warning-color: #c00 !default;
78

89
.mm-question-textarea {
910
width: 100%;
@@ -97,3 +98,7 @@ li.mm-question-answer-incorrect,
9798
background-color: $mm-question-state-incorrect-color;
9899
}
99100
}
101+
102+
.mm-question-warning, p.mm-question-warning, .item .mm-question-warning {
103+
color: $mm-question-warning-color;
104+
}

www/core/components/question/services/helper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ angular.module('mm.core.question')
411411
* @ngdoc method
412412
* @name $mmQuestionHelper#getQuestionAttachmentsFromHtml
413413
* @param {String} html HTML code to search in.
414-
* @return {[type]} [description]
414+
* @return {Object[]} Attachments.
415415
*/
416416
self.getQuestionAttachmentsFromHtml = function(html) {
417417
var el = angular.element('<div></div>'),
@@ -422,6 +422,9 @@ angular.module('mm.core.question')
422422
el.html(html);
423423
el = el[0];
424424

425+
// Remove the filemanager (area to attach files to a question).
426+
$mmUtil.removeElement(el, 'div[id*=filemanager]');
427+
425428
// Search the anchors.
426429
anchors = el.querySelectorAll('a');
427430
angular.forEach(anchors, function(anchor) {

www/core/scss/styles.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ mm-timer {
389389
}
390390
}
391391

392+
.mm-monospaced {
393+
font-family: Andale Mono,Monaco,Courier New,DejaVu Sans Mono,monospace;
394+
}
395+
392396
/**
393397
* This CSS uses adjacent selectors instead of general sibling (~) selectors
394398
* for ion radio that are broken in iOS 9 UIWebView.

0 commit comments

Comments
 (0)