Skip to content

Commit 80d1aa6

Browse files
committed
MOBILE-1577 quiz: Prevent submit quiz if essay has attachments
1 parent be865e6 commit 80d1aa6

File tree

8 files changed

+74
-4
lines changed

8 files changed

+74
-4
lines changed

www/addons/mod_quiz/controllers/player.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,14 @@ angular.module('mm.addons.mod_quiz')
201201
function loadSummary() {
202202
$scope.showSummary = true;
203203
$scope.summaryQuestions = [];
204+
204205
return $mmaModQuiz.getAttemptSummary(attempt.id, $scope.preflightData, offline, true, true).then(function(questions) {
205206
$scope.summaryQuestions = questions;
206207
$scope.canReturn = attempt.state == $mmaModQuiz.ATTEMPT_IN_PROGRESS && !attempt.finishedOffline;
208+
$scope.preventSubmitMessages = $mmaModQuiz.getPreventSubmitMessages(questions);
207209

208210
attempt.dueDateWarning = $mmaModQuiz.getAttemptDueDateWarning(quiz, attempt);
209211

210-
// Remove all answers stored since the questions aren't rendered anymore.
211-
$mmUtil.emptyObject($scope.answers);
212-
213212
// Log summary as viewed.
214213
$mmaModQuiz.logViewAttemptSummary(attempt.id);
215214
}).catch(function(message) {

www/addons/mod_quiz/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"attemptnumber": "Attempt",
55
"attemptquiznow": "Attempt quiz now",
66
"attemptstate": "State",
7+
"cannotsubmitquizdueto": "This quiz cannot be submitted due to the following reasons:",
78
"comment": "Comment",
89
"completedon": "Completed on",
910
"confirmclose": "Once you submit, you will no longer be able to change your answers for this attempt.",

www/addons/mod_quiz/services/quiz.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,28 @@ angular.module('mm.addons.mod_quiz')
749749
}
750750
};
751751

752+
/**
753+
* Given a list of questions, check if the quiz can be submitted.
754+
* Will return an array with the messages to prevent the submit. Empty array if quiz can be submitted.
755+
*
756+
* @module mm.addons.mod_quiz
757+
* @ngdoc method
758+
* @name $mmaModQuiz#getPreventSubmitMessages
759+
* @param {Object[]} questions Questions.
760+
* @return {String[]} List of prevent submit messages. Empty array if quiz can be submitted.
761+
*/
762+
self.getPreventSubmitMessages = function(questions) {
763+
var messages = [];
764+
angular.forEach(questions, function(question) {
765+
var message = $mmQuestionDelegate.getPreventSubmitMessage(question);
766+
if (message) {
767+
message = $translate.instant(message);
768+
messages.push($translate.instant('mm.question.questionmessage', {$a: question.slot, $b: message}));
769+
}
770+
});
771+
return messages;
772+
};
773+
752774
/**
753775
* Get cache key for Quiz data WS calls.
754776
*

www/addons/mod_quiz/templates/player.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ <h2>{{ 'mma.mod_quiz.summaryofattempt' | translate }}</h2>
6464
{{ attempt.dueDateWarning }}
6565
</div>
6666
<mm-timer ng-if="endTime" class="item item-text-wrap" end-time="endTime" finished="timeUp()" timer-text="{{ 'mma.mod_quiz.timeleft' | translate }}"></mm-timer>
67-
<div class="item" ng-if="!attempt.finishedOffline">
67+
<div class="item item-text-wrap" ng-if="preventSubmitMessages.length">
68+
<p class="item-heading">{{ 'mma.mod_quiz.cannotsubmitquizdueto' | translate }}</p>
69+
<p ng-repeat="message in preventSubmitMessages">{{message}}</p>
70+
<a class="button button-block" ng-href="{{moduleUrl}}" mm-browser>{{ 'mm.core.openinbrowser' | translate }}</a>
71+
</div>
72+
<div class="item" ng-if="!attempt.finishedOffline && !preventSubmitMessages.length">
6873
<a class="button button-block" ng-click="finishAttempt()">{{ 'mma.mod_quiz.submitallandfinish' | translate }}</a>
6974
</div>
7075
</div>

www/addons/qtype/essay/handlers.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ angular.module('mm.addons.qtype_essay')
3636
return 'manualgraded';
3737
};
3838

39+
/**
40+
* Check if a question can be submitted.
41+
* If a question cannot be submitted it should return a message explaining why (translated or not).
42+
*
43+
* @module mm.core.question
44+
* @ngdoc method
45+
* @name $mmQuestionDelegate#getPreventSubmitMessage
46+
* @param {Object} question Question.
47+
* @return {String} Prevent submit message. Undefined or empty if cannot be submitted.
48+
*/
49+
self.getPreventSubmitMessage = function(question) {
50+
var questionEl = angular.element(question.html)[0];
51+
52+
if (questionEl.querySelector('div[id*=filemanager]')) {
53+
// The question allows attachments. Since the app cannot attach files yet we will prevent submitting the question.
54+
return 'mm.question.errorattachmentsnotsupported';
55+
}
56+
};
57+
3958
/**
4059
* Check if a response is complete.
4160
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"notanswered": "Not answered",
1414
"notyetanswered": "Not yet answered",
1515
"partiallycorrect": "Partially correct",
16+
"questionmessage": "Question {{$a}}: {{$b}}",
1617
"requiresgrading": "Requires grading",
1718
"unknown": "Cannot determine status"
1819
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ angular.module('mm.core.question')
130130
}
131131
};
132132

133+
/**
134+
* Check if a question can be submitted.
135+
* If a question cannot be submitted it should return a message explaining why (translated or not).
136+
*
137+
* @module mm.core.question
138+
* @ngdoc method
139+
* @name $mmQuestionDelegate#getPreventSubmitMessage
140+
* @param {Object} question Question.
141+
* @return {String} Prevent submit message. Undefined or empty if cannot be submitted.
142+
*/
143+
self.getPreventSubmitMessage = function(question) {
144+
var type = 'qtype_' + question.type,
145+
handler = enabledHandlers[type];
146+
if (typeof handler != 'undefined' && handler.getPreventSubmitMessage) {
147+
return handler.getPreventSubmitMessage(question);
148+
}
149+
};
150+
133151
/**
134152
* Check if a response is complete.
135153
*

www/core/scss/styles.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ em {
7474
@extend h2;
7575
}
7676

77+
.item.item-text-wrap .item-heading {
78+
overflow: visible;
79+
white-space: normal;
80+
}
81+
7782
// More options for grids.
7883
.col-65 {
7984
@include flex(0, 0, 65%);

0 commit comments

Comments
 (0)