@@ -2,13 +2,19 @@
|
||||
{% block title %} Subgroup {{subgroup.title}} - {{ course.title }} {% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
<h2>{{subgroup.title}} <span class="badge badge-secondary">Subgroup</span></h2>
|
||||
<h2 id="page-title"
|
||||
data-subgroup="{{subgroup.name}}"
|
||||
data-title="{{subgroup.title}}"
|
||||
>{{subgroup.title}} <span class="badge badge-secondary">Subgroup</span></h2>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
{{ render_navitem("Mentors", "/mentors", stats.mentors, page=="mentors")}}
|
||||
{{ render_navitem("Students", "/students", stats.students, page=="students")}}
|
||||
{% if is_mentor or is_admin %}
|
||||
{{ render_navitem("Join Requests", "/join-requests", stats.join_requests, page=="join-requests")}}
|
||||
{% endif %}
|
||||
{% if is_admin %}
|
||||
{{ render_navitem("Admin", "/admin", stats.join_requests, page=="admin")}}
|
||||
{{ render_navitem("Admin", "/admin", -1, page=="admin")}}
|
||||
{% endif %}
|
||||
</ul>
|
||||
<div class="my-5">
|
||||
@@ -18,15 +24,24 @@
|
||||
{{ render_mentors() }}
|
||||
{% elif page == "students" %}
|
||||
{{ render_students() }}
|
||||
{% elif page == "admin" %}
|
||||
{% elif page == "join-requests" %}
|
||||
{{ render_join_requests() }}
|
||||
{% elif page == "admin" %}
|
||||
{{ render_admin() }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% macro render_info() %}
|
||||
{% if is_admin %}
|
||||
{% endif %}
|
||||
{% macro render_admin() %}
|
||||
<div style="background: white; padding: 20px;">
|
||||
<h5>Add a new mentor</h5>
|
||||
<form id="add-mentor-form">
|
||||
<div class="form-group">
|
||||
<input type="email" class="form-control" id="mentor-email" aria-describedby="emailHelp" placeholder="E-mail address">
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" id="add-mentor">Add Mentor</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_mentors() %}
|
||||
@@ -202,6 +217,24 @@ $(function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("#add-mentor").click(function() {
|
||||
var subgroup = $("#page-title").data("subgroup");
|
||||
var title = $("#page-title").data("title");
|
||||
var email = $("#mentor-email").val();
|
||||
frappe.call("school.lms.api.add_mentor_to_subgroup", {
|
||||
subgroup: subgroup,
|
||||
email: email
|
||||
})
|
||||
.then(r => {
|
||||
if (r.message.ok) {
|
||||
frappe.msgprint(`Successfully added ${email} as mentor to ${title}`);
|
||||
}
|
||||
else {
|
||||
frappe.msgprint(r.message.error);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -13,9 +13,12 @@ def get_context(context):
|
||||
return
|
||||
|
||||
page = frappe.form_dict.get("page")
|
||||
is_admin = subgroup.is_manager(frappe.session.user) or "System Manager" in frappe.get_roles()
|
||||
is_mentor = subgroup.is_mentor(frappe.session.user)
|
||||
is_admin = cohort.is_admin(frappe.session.user) or "System Manager" in frappe.get_roles()
|
||||
|
||||
if page not in ["mentors", "students", "admin"] or (page == "admin" and not is_admin):
|
||||
if (page not in ["mentors", "students", "join-requests", "admin"]
|
||||
or (page == "join-requests" and not (is_mentor or is_admin))
|
||||
or (page == "admin" and not is_admin)):
|
||||
frappe.local.flags.redirect_location = subgroup.get_url() + "/mentors"
|
||||
raise frappe.Redirect
|
||||
|
||||
@@ -30,6 +33,7 @@ def get_context(context):
|
||||
context.stats = get_stats(subgroup)
|
||||
context.page = page
|
||||
context.is_admin = is_admin
|
||||
context.is_mentor = is_mentor
|
||||
|
||||
def get_stats(subgroup):
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user