feat: class improvements

This commit is contained in:
Jannat Patel
2023-04-27 22:29:45 +05:30
parent e6621ad866
commit b5240f0eec
7 changed files with 223 additions and 79 deletions

View File

@@ -1,24 +1,16 @@
frappe.ready(() => {
$("#submit-student").click((e) => {
submit_student(e);
$(".btn-add-student").click((e) => {
show_student_modal(e);
});
$(".remove-student").click((e) => {
remove_student(e);
});
$(".class-course").click((e) => {
update_course(e);
});
if ($("#live-class-form").length) {
make_live_class_form();
}
if ($(".add-students").length) {
make_add_students_section();
}
$("#open-class-modal").click((e) => {
e.preventDefault();
$("#live-class-modal").modal("show");
@@ -27,6 +19,14 @@ frappe.ready(() => {
$("#create-live-class").click((e) => {
create_live_class(e);
});
$(".btn-add-course").click((e) => {
show_course_modal(e);
});
$(".btn-remove-course").click((e) => {
remove_course(e);
});
});
const submit_student = (e) => {
@@ -77,17 +77,6 @@ const remove_student = (e) => {
);
};
const update_course = (e) => {
frappe.call({
method: "lms.lms.doctype.lms_class.lms_class.update_course",
args: {
course: $(e.currentTarget).data("course"),
value: $(e.currentTarget).children("input").prop("checked") ? 1 : 0,
class_name: $(".class-details").data("class"),
},
});
};
const create_live_class = (e) => {
let class_name = $(".class-details").data("class");
frappe.call({
@@ -353,3 +342,110 @@ const make_add_students_section = () => {
$(".add-students .form-section:last").removeClass("empty-section");
$(".add-students .frappe-control").removeClass("hide-control");
};
const show_course_modal = () => {
let course_modal = new frappe.ui.Dialog({
title: "Add Course",
fields: [
{
fieldtype: "Link",
options: "LMS Course",
label: __("Course"),
fieldname: "course",
reqd: 1,
},
],
primary_action_label: __("Add"),
primary_action(values) {
frappe.call({
method: "frappe.client.insert",
args: {
doc: {
doctype: "Class Course",
course: values.course,
parenttype: "LMS Class",
parentfield: "courses",
parent: $(".class-details").data("class"),
},
},
callback(r) {
frappe.show_alert(
{
message: __("Course Added"),
indicator: "green",
},
3
);
window.location.reload();
},
});
course_modal.hide();
},
});
course_modal.show();
};
const remove_course = (e) => {
frappe.call({
method: "lms.lms.doctype.lms_class.lms_class.remove_course",
args: {
course: $(e.target).data("course"),
parent: $(".class-details").data("class"),
},
callback(r) {
frappe.show_alert(
{
message: __("Course Removed"),
indicator: "green",
},
3
);
window.location.reload();
},
});
};
const show_student_modal = () => {
let student_modal = new frappe.ui.Dialog({
title: "Add Student",
fields: [
{
fieldtype: "Link",
options: "User",
label: __("Student"),
fieldname: "student",
reqd: 1,
filters: {
ignore_user_type: 1,
},
},
],
primary_action_label: __("Add"),
primary_action(values) {
frappe.call({
method: "frappe.client.insert",
args: {
doc: {
doctype: "Class Student",
student: values.student,
parenttype: "LMS Class",
parentfield: "students",
parent: $(".class-details").data("class"),
},
},
callback(r) {
frappe.show_alert(
{
message: __("Student Added"),
indicator: "green",
},
3
);
window.location.reload();
},
});
student_modal.hide();
},
});
student_modal.show();
};