+
+ {% if live_classes | length %}
{% for class in live_classes %}
@@ -280,6 +309,9 @@
{% endfor %}
+ {% else %}
+
{{ _("No Live Classes") }}
+ {% endif %}
{% endmacro %}
@@ -303,4 +335,4 @@
{% endif %}
{{ include_script('controls.bundle.js') }}
-{% endblock %}
+{% endblock %}
\ No newline at end of file
diff --git a/lms/www/classes/class.js b/lms/www/classes/class.js
index ac266856..686f99c7 100644
--- a/lms/www/classes/class.js
+++ b/lms/www/classes/class.js
@@ -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) => {
+ $(".btn-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({
@@ -334,22 +323,133 @@ const get_timezones = () => {
];
};
-const make_add_students_section = () => {
- this.field_group = new frappe.ui.FieldGroup({
+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,
+ },
+ {
+ fieldtype: "HTML",
+ fieldname: "instructions",
+ label: __("Instructions"),
+ options: __("Select a course to add to this class."),
+ },
+ ],
+ 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();
+ setTimeout(() => {
+ $(".modal-body").css("min-height", "200px");
+ $(".modal-body input").focus();
+ }, 1000);
+};
+
+const remove_course = (e) => {
+ frappe.confirm("Are you sure you want to remove this course?", () => {
+ frappe.call({
+ method: "lms.lms.doctype.lms_class.lms_class.remove_course",
+ args: {
+ course: $(e.currentTarget).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: [
{
- fieldname: "student_input",
fieldtype: "Link",
options: "User",
- label: "Add Student",
+ label: __("Student"),
+ fieldname: "student",
+ reqd: 1,
filters: {
ignore_user_type: 1,
},
},
+ {
+ fieldtype: "HTML",
+ fieldname: "instructions",
+ label: __("Instructions"),
+ options: __(
+ "Please ensure a user account exists for the student before adding them to the class. Only users can be enrolled as students."
+ ),
+ },
],
- body: $(".add-students").get(0),
+ 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();
+ },
});
- this.field_group.make();
- $(".add-students .form-section:last").removeClass("empty-section");
- $(".add-students .frappe-control").removeClass("hide-control");
+ student_modal.show();
+ setTimeout(() => {
+ $(".modal-body").css("min-height", "200px");
+ $(".modal-body input").focus();
+ }, 1000);
};
diff --git a/lms/www/classes/class.py b/lms/www/classes/class.py
index ab06a34e..edc7b6eb 100644
--- a/lms/www/classes/class.py
+++ b/lms/www/classes/class.py
@@ -32,11 +32,17 @@ def get_context(context):
)
context.class_courses = frappe.get_all(
- "Class Course", {"parent": class_name}, pluck="course"
+ "Class Course",
+ {"parent": class_name},
+ ["name", "course", "title"],
+ order_by="creation desc",
)
class_students = frappe.get_all(
- "Class Student", {"parent": class_name}, ["student", "student_name", "username"]
+ "Class Student",
+ {"parent": class_name},
+ ["student", "student_name", "username"],
+ order_by="creation desc",
)
for student in class_students:
diff --git a/lms/www/classes/index.html b/lms/www/classes/index.html
index 69b62d2f..26c6a9b7 100644
--- a/lms/www/classes/index.html
+++ b/lms/www/classes/index.html
@@ -6,50 +6,79 @@
{% block page_content %}
- {% if is_moderator %}
-
- {% endif %}
-
{{ _("All Classes") }}
- {% if classes %}
- {{ ClassCards(classes) }}
+ {{ Header() }}
+ {% if past_classes | length or upcoming_classes | length %}
+ {{ ClassTabs(past_classes, upcoming_classes) }}
{% else %}
-
-

-
-
{{ _("No Classes") }}
-
{{ _("Nothing to see here.") }}
-
-
+ {{ EmptyState() }}
{% endif %}
{% endblock %}
-{%- block script %}
- {{ super() }}
- {{ include_script('controls.bundle.js') }}
+{% macro Header() %}
+
+{% endmacro %}
+
+{% macro ClassTabs(past_classes, upcoming_classes) %}
+
+
+
+
+
+
+
+ {{ ClassCards(upcoming_classes) }}
+
+
+
+ {{ ClassCards(past_classes) }}
+
+
+
+
+{% endmacro %}
{% macro ClassCards(classes) %}
{% for class in classes %}
{% set course_count = frappe.db.count("Class Course", {"parent": class.name}) %}
- {% set student_count = frappe.db.count("Class Student", {"parent": class.name}) %}
+ {% set student_count = frappe.db.count("Class Student", {"parent": class.name}) %}
-
+
{{ class.title }}
-
+
+
{% endfor %}
{% endmacro %}
+
+{% macro EmptyState() %}
+
+

+
+
{{ _("No Classes") }}
+
{{ _("Nothing to see here.") }}
+
+
+{% endmacro %}
+
+{%- block script %}
+ {{ super() }}
+ {{ include_script('controls.bundle.js') }}
+ {% if is_moderator %}
+
+ {% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/lms/www/classes/index.py b/lms/www/classes/index.py
index 90875fc0..4e387678 100644
--- a/lms/www/classes/index.py
+++ b/lms/www/classes/index.py
@@ -6,8 +6,19 @@ from lms.lms.utils import has_course_moderator_role
def get_context(context):
context.no_cache = 1
context.is_moderator = has_course_moderator_role()
- context.classes = frappe.get_all(
+ classes = frappe.get_all(
"LMS Class",
- {"end_date": [">=", getdate()]},
- ["name", "title", "start_date", "end_date"],
+ fields=["name", "title", "start_date", "end_date", "paid_class", "seat_count"],
)
+
+ past_classes, upcoming_classes = [], []
+ for class_ in classes:
+ print(class_.start_date)
+ if getdate(class_.start_date) < getdate():
+ past_classes.append(class_)
+ else:
+ upcoming_classes.append(class_)
+
+ context.past_classes = sorted(past_classes, key=lambda d: d.start_date)
+
+ context.upcoming_classes = sorted(upcoming_classes, key=lambda d: d.start_date)
diff --git a/lms/www/courses/create.html b/lms/www/courses/create.html
index fcc21299..3fff7c13 100644
--- a/lms/www/courses/create.html
+++ b/lms/www/courses/create.html
@@ -64,7 +64,7 @@
{{ _("Short Introduction") }}
- {{ _("A one line breif description") }}
+ {{ _("A one line brief description") }}
diff --git a/lms/www/jobs/index.html b/lms/www/jobs/index.html
index 54971584..da82e70f 100644
--- a/lms/www/jobs/index.html
+++ b/lms/www/jobs/index.html
@@ -7,7 +7,7 @@
{% if allow_posting %}
-
{{ _("Post a Job") }}
+
{{ _("Post a Job") }}
{% endif %}
{{ _("{0}").format(title) }}
diff --git a/lms/www/jobs/job.html b/lms/www/jobs/job.html
index e148e218..9e1db41c 100644
--- a/lms/www/jobs/job.html
+++ b/lms/www/jobs/job.html
@@ -35,10 +35,10 @@
{% set application_link = job.application_link if frappe.session.user != 'Guest' else '/login?redirect-to=/jobs/' + job.name %}