feat: show and hide quiz answers
This commit is contained in:
@@ -78,7 +78,7 @@
|
||||
<div class="field-parent">
|
||||
<div class="field-group">
|
||||
<div>
|
||||
<div class="field-label">
|
||||
<div class="field-label reqd">
|
||||
{{ _("Title") }}
|
||||
</div>
|
||||
<div class="field-description">
|
||||
@@ -102,6 +102,18 @@
|
||||
<input type="number" class="field-input" id="max-attempts" value="{{ max_attempts }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-group vertically-center">
|
||||
{% set show_answers = quiz.show_answers or not quiz.name %}
|
||||
<label for="show-answers" class="vertically-center mb-0">
|
||||
<input type="checkbox" id="show-answers" {% if show_answers %} checked {% endif %}>
|
||||
{{ _("Show Answers") }}
|
||||
</label>
|
||||
<label for="upcoming" class="vertically-center mb-0 ml-20">
|
||||
<input type="checkbox" id="show-submission-history" {% if quiz.show_submission_history %} checked {% endif %}>
|
||||
{{ _("Show Submission History") }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@@ -119,12 +119,19 @@ const edit_question = (e) => {
|
||||
};
|
||||
|
||||
const save_quiz = (values) => {
|
||||
validate_mandatory();
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_quiz.lms_quiz.save_quiz",
|
||||
args: {
|
||||
quiz_title: values.quiz_title,
|
||||
max_attempts: values.max_attempts,
|
||||
quiz: $("#quiz-form").data("name") || "",
|
||||
show_answers: $("#show-answers").is(":checked") ? 1 : 0,
|
||||
show_submission_history: $("#show-submission-history").is(
|
||||
":checked"
|
||||
)
|
||||
? 1
|
||||
: 0,
|
||||
},
|
||||
callback: (data) => {
|
||||
frappe.show_alert({
|
||||
@@ -138,6 +145,17 @@ const save_quiz = (values) => {
|
||||
});
|
||||
};
|
||||
|
||||
const validate_mandatory = () => {
|
||||
if (!$("#quiz-title").val()) {
|
||||
let error = $("p")
|
||||
.addClass("error-message")
|
||||
.text(__("Please enter a Quiz Title"));
|
||||
$(error).insertAfter("#quiz-title");
|
||||
$("#quiz-title").focus();
|
||||
throw "Title is mandatory";
|
||||
}
|
||||
};
|
||||
|
||||
const save_question = (values) => {
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_quiz.lms_quiz.save_question",
|
||||
|
||||
@@ -21,7 +21,10 @@ def get_context(context):
|
||||
fields_arr = ["name", "question", "type"]
|
||||
|
||||
context.quiz = frappe.db.get_value(
|
||||
"LMS Quiz", quizname, ["title", "name", "max_attempts"], as_dict=1
|
||||
"LMS Quiz",
|
||||
quizname,
|
||||
["title", "name", "max_attempts", "show_answers", "show_submission_history"],
|
||||
as_dict=1,
|
||||
)
|
||||
context.quiz.questions = frappe.get_all(
|
||||
"LMS Quiz Question", {"parent": quizname}, fields_arr, order_by="idx"
|
||||
|
||||
Reference in New Issue
Block a user