fix: add student section

This commit is contained in:
Jannat Patel
2023-03-13 15:47:51 +05:30
parent 170b1b0dcc
commit 0593a9fb30
3 changed files with 94 additions and 48 deletions

View File

@@ -2003,9 +2003,16 @@ select {
.live-class-panel { .live-class-panel {
margin-top: auto; margin-top: auto;
display: none;
} }
.lms-card:hover + .live-class-panel { .lms-card .live-class-panel .btn {
display: block; visibility: hidden;
} }
.lms-card:hover .live-class-panel .btn {
visibility: visible;
}
.add-students .text-primary.link-option {
visibility: hidden;
}

View File

@@ -75,7 +75,7 @@
</a> </a>
</li> </li>
{% if is_moderator or is_student %} {% if class_students | length and (is_moderator or is_student) %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#live-class"> <a class="nav-link" data-toggle="tab" href="#live-class">
{{ _("Live Class") }} {{ _("Live Class") }}
@@ -96,7 +96,7 @@
{{ StudentsSection(class_info, class_students) }} {{ StudentsSection(class_info, class_students) }}
</div> </div>
{% if is_moderator or is_student %} {% if class_students | length and (is_moderator or is_student) %}
<div class="tab-pane" id="live-class" role="tabpanel" aria-labelledby="live-class"> <div class="tab-pane" id="live-class" role="tabpanel" aria-labelledby="live-class">
{{ LiveClassSection(class_info, live_classes) }} {{ LiveClassSection(class_info, live_classes) }}
</div> </div>
@@ -175,20 +175,10 @@
{% macro AddStudents() %} {% macro AddStudents() %}
<div class="mb-10"> <div class="mb-10">
<div class="mb-2"> <div class="add-students"></div>
{{ _("Add Student") }} <button class="btn btn-primary btn-sm ml-5" id="submit-student">
</div> {{ _("Add") }}
<form> </button>
<div class="control-input-wrapper mb-2 w-50">
<div class="control-input">
<input type="text" autocomplete="off" class="input-with-feedback form-control" id="student-email"
spellcheck="false">
</div>
</div>
<button class="btn btn-primary btn-sm" id="submit-student">
{{ _("Add") }}
</button>
</form>
</div> </div>
{% endmacro %} {% endmacro %}
@@ -254,13 +244,19 @@
</div> </div>
<div class="live-class-panel"> <div class="live-class-panel">
{% if class.owner == frappe.session.user and class.date == frappe.utils.getdate() %} {% if class.owner == frappe.session.user %}
<a class="btn btn-secondary btn-sm mr-2" href="{{ class.start_url }}"> <a class="btn btn-secondary btn-sm mr-2" href="{{ class.start_url }}">
{{ _("Start") }} {{ _("Start") }}
</a> </a>
{% endif %} {% endif %}
{% if class.owner == frappe.session.user %} {% if is_student %}
<a class="btn btn-secondary btn-sm mt-auto" href="{{ class.join_url }}">
{{ _("Join Class") }}
</a>
{% endif %}
<!-- {% if class.owner == frappe.session.user %}
<a class="btn btn-secondary btn-sm mr-2" href="{{ class.start_url }}"> <a class="btn btn-secondary btn-sm mr-2" href="{{ class.start_url }}">
{{ _("Edit") }} {{ _("Edit") }}
</a> </a>
@@ -268,15 +264,9 @@
<a class="btn btn-secondary btn-sm" href="{{ class.start_url }}"> <a class="btn btn-secondary btn-sm" href="{{ class.start_url }}">
{{ _("Delete") }} {{ _("Delete") }}
</a> </a>
{% endif %} {% endif %} -->
</div> </div>
{% if is_student and class.date == frappe.utils.getdate() %}
<a class="btn btn-secondary btn-sm mt-auto" href="{{ class.join_url }}">
{{ _("Join Class") }}
</a>
{% endif %}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
@@ -284,5 +274,22 @@
{%- block script %} {%- block script %}
{{ super() }} {{ super() }}
{% if is_moderator %}
<script>
frappe.boot.user = {
"can_create": [],
"can_select": ["User"],
"can_read": ["User"]
};
frappe.router = {
slug (name) {
return name.toLowerCase().replace(/ /g, "-");
}
}
</script>
{% endif %}
{{ include_script('controls.bundle.js') }} {{ include_script('controls.bundle.js') }}
{% endblock %} {% endblock %}

View File

@@ -15,6 +15,10 @@ frappe.ready(() => {
make_live_class_form(); make_live_class_form();
} }
if ($(".add-students").length) {
make_add_students_section();
}
$("#open-class-modal").click((e) => { $("#open-class-modal").click((e) => {
e.preventDefault(); e.preventDefault();
$("#live-class-modal").modal("show"); $("#live-class-modal").modal("show");
@@ -23,27 +27,34 @@ frappe.ready(() => {
$("#create-live-class").click((e) => { $("#create-live-class").click((e) => {
create_live_class(e); create_live_class(e);
}); });
setTimeout(() => {
console.log(locals.Doctype)
}, 10000);
}); });
const submit_student = (e) => { const submit_student = (e) => {
e.preventDefault(); e.preventDefault();
frappe.call({ if ($('input[data-fieldname="student_input"]').val()) {
method: "lms.lms.doctype.lms_class.lms_class.add_student", frappe.call({
args: { method: "lms.lms.doctype.lms_class.lms_class.add_student",
email: $("#student-email").val(), args: {
class_name: $(".class-details").data("class"), email: $('input[data-fieldname="student_input"]').val(),
}, class_name: $(".class-details").data("class"),
callback: (data) => { },
frappe.show_alert( callback: (data) => {
{ frappe.show_alert(
message: __("Student added successfully"), {
indicator: "green", message: __("Student added successfully"),
}, indicator: "green",
3 },
); 3
window.location.reload(); );
}, window.location.reload();
}); },
});
}
}; };
const remove_student = (e) => { const remove_student = (e) => {
@@ -100,14 +111,14 @@ const create_live_class = (e) => {
$("#live-class-modal").modal("hide"); $("#live-class-modal").modal("hide");
frappe.show_alert( frappe.show_alert(
{ {
message: __("Live Class created successfully"), message: __("Live Class added successfully"),
indicator: "green", indicator: "green",
}, },
3 3
); );
setTimeout(function () { setTimeout(function () {
window.location.href = `/classes/${class_name}#live-class`; window.location.reload()
}, 2000); }, 1000);
}, },
}); });
}; };
@@ -168,3 +179,24 @@ const make_live_class_form = (e) => {
$("#live-class-form .form-section:last").removeClass("empty-section"); $("#live-class-form .form-section:last").removeClass("empty-section");
$("#live-class-form .frappe-control").removeClass("hide-control"); $("#live-class-form .frappe-control").removeClass("hide-control");
}; };
const make_add_students_section = () => {
this.field_group = new frappe.ui.FieldGroup({
fields: [
{
fieldname: "student_input",
fieldtype: "Link",
options: "User",
label: "Add Student",
filters: {
ignore_user_type: 1
}
}
],
body: $(".add-students").get(0)
});
this.field_group.make();
$(".add-students .form-section:last").removeClass("empty-section");
$(".add-students .frappe-control").removeClass("hide-control");
}