fix: quiz max attempts
This commit is contained in:
@@ -3,7 +3,6 @@ frappe.ready(() => {
|
||||
let self = this;
|
||||
|
||||
frappe.telemetry.capture("on_lesson_page", "lms");
|
||||
localStorage.removeItem($("#quiz-title").data("name"));
|
||||
|
||||
fetch_assignments();
|
||||
|
||||
|
||||
@@ -58,13 +58,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if quiz.name %}
|
||||
<div class="align-self-center">
|
||||
<button class="btn btn-primary btn-sm btn-add-question">
|
||||
{% if quiz.name %}
|
||||
<button class="btn btn-secondary btn-sm btn-add-question mr-2">
|
||||
{{ _("Add Question") }}
|
||||
</button>
|
||||
{% endif %}
|
||||
<button class="btn btn-primary btn-sm btn-save-quiz">
|
||||
{{ _("Save") }}
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -86,6 +89,19 @@
|
||||
<input type="text" class="field-input" id="quiz-title" {% if quiz.name %} value="{{ quiz.title }}" data-title="{{ quiz.title }}" {% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-group">
|
||||
<div class="field-label">
|
||||
{{ _("Max Attempts") }}
|
||||
</div>
|
||||
<div class="field-description">
|
||||
{{ _("Enter the maximum number of times a user can attempt this quiz") }}
|
||||
</div>
|
||||
<div>
|
||||
{% set max_attempts = quiz.max_attempts if quiz.name else 1 %}
|
||||
<input type="number" class="field-input" id="max-attempts" value="{{ max_attempts }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
frappe.ready(() => {
|
||||
$("#quiz-title").focusout((e) => {
|
||||
if ($("#quiz-title").val() != $("#quiz-title").data("title")) {
|
||||
save_quiz({ quiz_title: $("#quiz-title").val() });
|
||||
}
|
||||
$(".btn-save-quiz").click((e) => {
|
||||
save_quiz({
|
||||
quiz_title: $("#quiz-title").val(),
|
||||
max_attempts: $("#max-attempts").val(),
|
||||
});
|
||||
});
|
||||
|
||||
$(".question-row").click((e) => {
|
||||
@@ -14,26 +15,6 @@ frappe.ready(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const show_quiz_modal = () => {
|
||||
let quiz_dialog = new frappe.ui.Dialog({
|
||||
title: __("Create Quiz"),
|
||||
fields: [
|
||||
{
|
||||
fieldtype: "Data",
|
||||
label: __("Quiz Title"),
|
||||
fieldname: "quiz_title",
|
||||
reqd: 1,
|
||||
},
|
||||
],
|
||||
primary_action: (values) => {
|
||||
quiz_dialog.hide();
|
||||
save_quiz(values);
|
||||
},
|
||||
});
|
||||
|
||||
quiz_dialog.show();
|
||||
};
|
||||
|
||||
const show_question_modal = (values = {}) => {
|
||||
let fields = get_question_fields(values);
|
||||
|
||||
@@ -142,6 +123,7 @@ const save_quiz = (values) => {
|
||||
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") || "",
|
||||
},
|
||||
callback: (data) => {
|
||||
|
||||
@@ -20,7 +20,9 @@ def get_context(context):
|
||||
else:
|
||||
fields_arr = ["name", "question", "type"]
|
||||
|
||||
context.quiz = frappe.db.get_value("LMS Quiz", quizname, ["title", "name"], as_dict=1)
|
||||
context.quiz = frappe.db.get_value(
|
||||
"LMS Quiz", quizname, ["title", "name", "max_attempts"], 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