diff --git a/lms/lms/doctype/course_lesson/course_lesson.json b/lms/lms/doctype/course_lesson/course_lesson.json index c38059ac..5d19f852 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.json +++ b/lms/lms/doctype/course_lesson/course_lesson.json @@ -10,9 +10,9 @@ "field_order": [ "chapter", "course", - "include_in_preview", "column_break_4", "title", + "include_in_preview", "index_label", "section_break_6", "body", @@ -75,7 +75,6 @@ "fetch_from": "chapter.course", "fieldname": "course", "fieldtype": "Link", - "hidden": 1, "label": "Course", "options": "LMS Course", "read_only": 1 @@ -83,7 +82,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-03-14 18:56:31.969801", + "modified": "2022-04-22 12:59:23.641915", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", diff --git a/lms/lms/web_form/lesson/lesson.js b/lms/lms/web_form/lesson/lesson.js index 4347f730..ad73a38c 100644 --- a/lms/lms/web_form/lesson/lesson.js +++ b/lms/lms/web_form/lesson/lesson.js @@ -1,16 +1,94 @@ frappe.ready(function() { - frappe.web_form.after_save = () => { - frappe.call({ + + frappe.web_form.after_load = () => { + add_file_upload_component(); + fetch_course(); + }; + + frappe.web_form.after_save = () => { + show_success_message(); + }; + + $(document).on("click", ".add-attachment", (e) => { + show_upload_modal(); + }); + + $(document).on("click", ".copy-link", (e) => { + frappe.utils.copy_to_clipboard($(e.currentTarget).data("link")); + $(".attachments").collapse("hide"); + }); + +}); + +const fetch_course = () => { + frappe.call({ method: "lms.lms.doctype.course_lesson.course_lesson.get_lesson_info", args: { - "chapter": frappe.web_form.doc.chapter + "chapter": frappe.web_form.doc.chapter }, callback: (data) => { - frappe.msgprint(__(`Lesson has been saved successfully. Go back to the chapter and add this lesson to the lessons table.`)); - setTimeout(() => { - window.location.href = `/courses/${data.message}`; - }, 3000); + this.course = data.message; } }); - }; -}); +} + +const show_upload_modal = () => { + new frappe.ui.FileUploader({ + folder: "Home/Attachments", + restrictions: { + allowed_file_types: ['image/*'] + }, + on_success: (file_doc) => { + $(".attachments").append(build_attachment_table(file_doc)); + let count = $(".attachment-count").data("count") + 1; + $(".attachment-count").data("count", count); + $(".attachment-count").html(__(`${count} attachments`)); + $(".attachments").removeClass("hide"); + }, + }); +}; + +const show_success_message = () => { + frappe.msgprint(__(`Lesson has been saved successfully. Go back to the chapter and add this lesson to the lessons table.`)); + setTimeout(() => { + window.location.href = `/courses/${this.course}`; + }, 2000); +}; + +const add_file_upload_component = () => { + $(get_attachment_controls_html()).insertBefore($(`[data-fieldname="include_in_preview"]`).first()); +}; + +const get_attachment_controls_html = () => { + return ` +
+ `; +}; + +const build_attachment_table = (file_doc) => { + return $(` +Create lessons for your course. You can add some additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.
| Content Type | Syntax |
| Video | {{ Video(\"url_of_source\") }} |
| YouTube Video | {{ YouTubeVideo(\"unique_embed_id\") }} |
| Exercise | {{ Exercise(\"exercise_name\") }} |
| Quiz | {{ Quiz(\"lms_quiz_name\") }} |
| Assignment | {{ Assignment(\"id-filetype\") }} |
Create lessons for your course. For adding content, use markdown syntax. You can add some additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.
\n| \n Content Type\n | \n\n Syntax \n | \n
| Assignment | \n{{ Assignment(\"id-filetype\") }} | \n
| Quiz | \n{{ Quiz(\"lms_quiz_name\") }} | \n
| YouTube Video | \n{{ YouTubeVideo(\"unique_embed_id\") }} | \n
Note: You can also attach videos from Vimeo by including the iframe embed of the video to the lesson.
\n