fix: quiz dialog display

This commit is contained in:
Jannat Patel
2023-06-16 13:08:49 +05:30
parent 43e89d9dc2
commit 35c080fcc2

View File

@@ -65,7 +65,7 @@ const parse_string_to_lesson = () => {
lesson_blocks.push({ lesson_blocks.push({
type: "quiz", type: "quiz",
data: { data: {
quiz: quiz, quiz: [quiz],
}, },
}); });
} else if (block.includes("{{ Video")) { } else if (block.includes("{{ Video")) {
@@ -118,7 +118,9 @@ const parse_lesson_to_string = (data) => {
if (block.type == "youtube") { if (block.type == "youtube") {
lesson_content += `{{ YouTubeVideo("${block.data.youtube}") }}\n`; lesson_content += `{{ YouTubeVideo("${block.data.youtube}") }}\n`;
} else if (block.type == "quiz") { } else if (block.type == "quiz") {
lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`; block.data.quiz.forEach((quiz) => {
lesson_content += `{{ Quiz("${quiz}") }}\n`;
});
} else if (block.type == "upload") { } else if (block.type == "upload") {
let url = block.data.file_url; let url = block.data.file_url;
lesson_content += block.data.is_video lesson_content += block.data.is_video
@@ -291,11 +293,10 @@ class Quiz {
get_fields() { get_fields() {
let fields = [ let fields = [
{ {
fieldname: "quiz_information", fieldname: "start_section",
fieldtype: "HTML", fieldtype: "Section Break",
label: __("Create New"), label: __(
options: __( "To create a new quiz, click on the button below. Once you have created the new quiz you can come back to this lesson and add it from here."
"Click to create a new quiz to add to this lesson."
), ),
}, },
{ {
@@ -307,17 +308,17 @@ class Quiz {
}, },
}, },
{ {
fieldname: "quiz_list_section", fieldname: "quiz_information",
fieldtype: "Section Break", fieldtype: "HTML",
options: __("OR"),
}, },
{ {
fieldname: "quiz_list_information", fieldname: "quiz_list_section",
fieldtype: "HTML", fieldtype: "Section Break",
label: __("Quiz List"), label: __("Select a exisitng quiz to add to this lesson."),
options: __("Select a quiz to add to this lesson."),
}, },
]; ];
let break_index = Math.ceil(self.quiz_list.length / 2); let break_index = Math.ceil(self.quiz_list.length / 2) + 4;
self.quiz_list.forEach((quiz) => { self.quiz_list.forEach((quiz) => {
fields.push({ fields.push({
@@ -339,7 +340,7 @@ class Quiz {
render() { render() {
this.wrapper = document.createElement("div"); this.wrapper = document.createElement("div");
if (this.data && this.data.quiz) { if (this.data && this.data.quiz) {
$(this.wrapper).html(this.render_quiz(this.data.quiz)); $(this.wrapper).html(this.render_quiz());
} else { } else {
this.render_quiz_dialog(); this.render_quiz_dialog();
} }
@@ -359,7 +360,7 @@ class Quiz {
/* self.quiz = values.quiz; /* self.quiz = values.quiz;
$(self.wrapper).html(self.render_quiz(self.quiz)); */ $(self.wrapper).html(self.render_quiz(self.quiz)); */
}, },
secondary_action_label: __("Create New"), secondary_action_label: __("Create New Quiz"),
secondary_action: () => { secondary_action: () => {
window.location.href = `/quizzes`; window.location.href = `/quizzes`;
}, },
@@ -375,31 +376,35 @@ class Quiz {
/* If quiz is selected and is not already in the lesson then render it. /* If quiz is selected and is not already in the lesson then render it.
If quiz is in the lesson and is unselected then unrender it */ If quiz is in the lesson and is unselected then unrender it */
this.quiz_to_render = [];
Object.keys(values).forEach((key) => { Object.keys(values).forEach((key) => {
if (values[key] === 1 && !self.quiz_in_lesson.includes(key)) { if (values[key] === 1 && !self.quiz_in_lesson.includes(key)) {
self.quiz_in_lesson.push(key); self.quiz_in_lesson.push(key);
this.quiz = key; this.quiz_to_render.push(key);
$(this.wrapper).html(this.render_quiz(key));
} else if (values[key] == 0 && self.quiz_in_lesson.includes(key)) {
self.quiz_in_lesson.splice(self.quiz_in_lesson.indexOf(key), 1);
$(this.wrapper).html(this.render_quiz(key));
} }
}); });
$(this.wrapper).html(this.render_quiz());
} }
render_quiz(quiz) { render_quiz() {
return `<div class="common-card-style p-2 my-2 bold-heading"> let html = ``;
Quiz: ${quiz} let quiz_list = this.data.quiz || this.quiz_to_render;
</div>`; quiz_list.forEach((quiz) => {
html += `<div class="common-card-style p-2 my-2 bold-heading">
Quiz: ${quiz}
</div>`;
});
return html;
} }
validate(savedData) { validate(savedData) {
return !savedData.quiz || !savedData.quiz.trim() ? false : true; return !savedData.quiz || !savedData.quiz.length ? false : true;
} }
save(block_content) { save(block_content) {
return { return {
quiz: this.data.quiz || this.quiz, quiz: this.data.quiz || this.quiz_to_render,
}; };
} }
} }