diff --git a/school/public/css/style.css b/school/public/css/style.css index 31bcf871..a6bbcbe9 100644 --- a/school/public/css/style.css +++ b/school/public/css/style.css @@ -1487,3 +1487,32 @@ pre { .live-courses .course-home-headings { margin-bottom: 1.5rem; } + +@media (min-width: 768px) { + .lesson-pagination .custom-checkbox .empty-checkbox { + width: 1rem; + height: 1rem; + border-radius: 4px; + } +} + +@media (max-width: 767px) { + .lesson-pagination .custom-checkbox .empty-checkbox { + margin-bottom: 1rem; + border-radius: 4px; + } + + .lesson-pagination .custom-checkbox span { + display: inline-block; + width: 70%; + font-size: 10px; + } +} + +.lesson-pagination .custom-checkbox input:checked+.empty-checkbox { + background-size: 1rem; +} + +.no-discussions { + width: 80% !important; +} diff --git a/school/www/batch/learn.html b/school/www/batch/learn.html index ad1bca49..793ebd8b 100644 --- a/school/www/batch/learn.html +++ b/school/www/batch/learn.html @@ -79,27 +79,30 @@ {% if not course.is_mentor(frappe.session.user) and membership %} - - {% if course.get_progress(lesson.name) != "Complete" %} -
- Mark as Complete + {% set progress = course.get_progress(lesson.name) %} +
+
- {% else %} -
+ +
Mark as Incomplete
- {% endif %} {% endif %}
- {% if next_url %} - - {% elif course.enable_certification %} -
+ {% if course.enable_certification %} +
Get Certificate
{% endif %} diff --git a/school/www/batch/learn.js b/school/www/batch/learn.js index 8cfd46d1..c64f8510 100644 --- a/school/www/batch/learn.js +++ b/school/www/batch/learn.js @@ -8,7 +8,11 @@ frappe.ready(() => { enable_check(e); }) - $("#progress").click((e) => { + $(".mark-progress").click((e) => { + mark_progress(e); + }); + + $(".next").click((e) => { mark_progress(e); }); @@ -66,21 +70,37 @@ var mark_active_question = (e = undefined) => { } var mark_progress = (e) => { - var status = $(e.currentTarget).attr("data-progress"); - frappe.call({ - method: "school.lms.doctype.course_lesson.course_lesson.save_progress", - args: { - lesson: $(".title").attr("data-lesson"), - course: $(".title").attr("data-course"), - status: status - }, - callback: (data) => { - change_progress_indicators(status, e); - if (data.message == 100 && !$(".next").length && $("#certification").hasClass("hide")) { - $("#certification").removeClass("hide"); + /* Prevent default only for Next button anchor tag and not for progress checkbox */ + if ($(e.currentTarget).prop("nodeName") != "INPUT") + e.preventDefault(); + else + return + + const target = $(e.currentTarget).attr("data-progress") ? $(e.currentTarget) : $("input.mark-progress"); + const current_status = $(".lesson-progress").hasClass("hide") ? "Incomplete": "Complete"; + + let status = "Incomplete"; + if (target.prop("nodeName") == "INPUT" && target.prop("checked")) { + status = "Complete"; + } + + if (status != current_status) { + frappe.call({ + method: "school.lms.doctype.course_lesson.course_lesson.save_progress", + args: { + lesson: $(".title").attr("data-lesson"), + course: $(".title").attr("data-course"), + status: status + }, + callback: (data) => { + change_progress_indicators(status, e); + show_certificate_if_course_completed(data); + move_to_next_lesson(e); } - } - }) + }); + } + else + move_to_next_lesson(e); } var change_progress_indicators = (status, e) => { @@ -92,9 +112,23 @@ var change_progress_indicators = (status, e) => { $(".lesson-progress").addClass("hide"); $(".active-lesson .lesson-progress-tick").addClass("hide"); } - var label = status != "Complete" ? "Mark as Complete" : "Mark as Incomplete"; - var data_progress = status != "Complete" ? "Complete" : "Incomplete"; - $(e.currentTarget).text(label).attr("data-progress", data_progress); + if (status == "Incomplete" && !$(e.currentTarget).hasClass("next")) { + $(e.currentTarget).addClass("hide"); + $("input.mark-progress").prop("checked", false).closest(".custom-checkbox").removeClass("hide"); + } +} + +const show_certificate_if_course_completed = (data) => { + if (data.message == 100 && !$(".next").attr("data-next") && $("#certification").hasClass("hide")) { + $("#certification").removeClass("hide"); + $(".next").addClass("hide"); + } +} + +const move_to_next_lesson = (e) => { + if ($(e.currentTarget).hasClass("next") && $(e.currentTarget).attr("data-href")) { + window.location.href = $(e.currentTarget).attr("data-href"); + } } var quiz_summary = (e) => {