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 {
margin-top: auto;
display: none;
}
.lms-card:hover + .live-class-panel {
display: block;
.lms-card .live-class-panel .btn {
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>
</li>
{% if is_moderator or is_student %}
{% if class_students | length and (is_moderator or is_student) %}
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#live-class">
{{ _("Live Class") }}
@@ -96,7 +96,7 @@
{{ StudentsSection(class_info, class_students) }}
</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">
{{ LiveClassSection(class_info, live_classes) }}
</div>
@@ -175,20 +175,10 @@
{% macro AddStudents() %}
<div class="mb-10">
<div class="mb-2">
{{ _("Add Student") }}
</div>
<form>
<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 class="add-students"></div>
<button class="btn btn-primary btn-sm ml-5" id="submit-student">
{{ _("Add") }}
</button>
</div>
{% endmacro %}
@@ -254,13 +244,19 @@
</div>
<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 }}">
{{ _("Start") }}
</a>
{% 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 }}">
{{ _("Edit") }}
</a>
@@ -268,15 +264,9 @@
<a class="btn btn-secondary btn-sm" href="{{ class.start_url }}">
{{ _("Delete") }}
</a>
{% endif %}
{% endif %} -->
</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>
{% endfor %}
</div>
@@ -284,5 +274,22 @@
{%- block script %}
{{ 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') }}
{% endblock %}

View File

@@ -15,6 +15,10 @@ frappe.ready(() => {
make_live_class_form();
}
if ($(".add-students").length) {
make_add_students_section();
}
$("#open-class-modal").click((e) => {
e.preventDefault();
$("#live-class-modal").modal("show");
@@ -23,27 +27,34 @@ frappe.ready(() => {
$("#create-live-class").click((e) => {
create_live_class(e);
});
setTimeout(() => {
console.log(locals.Doctype)
}, 10000);
});
const submit_student = (e) => {
e.preventDefault();
frappe.call({
method: "lms.lms.doctype.lms_class.lms_class.add_student",
args: {
email: $("#student-email").val(),
class_name: $(".class-details").data("class"),
},
callback: (data) => {
frappe.show_alert(
{
message: __("Student added successfully"),
indicator: "green",
},
3
);
window.location.reload();
},
});
if ($('input[data-fieldname="student_input"]').val()) {
frappe.call({
method: "lms.lms.doctype.lms_class.lms_class.add_student",
args: {
email: $('input[data-fieldname="student_input"]').val(),
class_name: $(".class-details").data("class"),
},
callback: (data) => {
frappe.show_alert(
{
message: __("Student added successfully"),
indicator: "green",
},
3
);
window.location.reload();
},
});
}
};
const remove_student = (e) => {
@@ -100,14 +111,14 @@ const create_live_class = (e) => {
$("#live-class-modal").modal("hide");
frappe.show_alert(
{
message: __("Live Class created successfully"),
message: __("Live Class added successfully"),
indicator: "green",
},
3
);
setTimeout(function () {
window.location.href = `/classes/${class_name}#live-class`;
}, 2000);
window.location.reload()
}, 1000);
},
});
};
@@ -168,3 +179,24 @@ const make_live_class_form = (e) => {
$("#live-class-form .form-section:last").removeClass("empty-section");
$("#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");
}