88
school/www/cohorts/join.html
Normal file
88
school/www/cohorts/join.html
Normal file
@@ -0,0 +1,88 @@
|
||||
{% extends "www/cohorts/base.html" %}
|
||||
|
||||
{% block title %}Join Course{% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
|
||||
<h2>Join Course</h2>
|
||||
|
||||
<p>
|
||||
Course: {{course.title}}
|
||||
</p>
|
||||
<p>
|
||||
Cohort: {{cohort.title}}
|
||||
</p>
|
||||
<p>
|
||||
Subgroup: {{subgroup.title}}
|
||||
</p>
|
||||
|
||||
{% if frappe.session.user == "Guest" %}
|
||||
|
||||
<div class="alert alert-warning">
|
||||
<p>
|
||||
Please login to be able to join the course.</p>
|
||||
|
||||
<p>
|
||||
If you don't already have an account, you can <a href="/login#signup">sign up for a new account</a>.
|
||||
</p>
|
||||
<a class="btn btn-primary" href="/login">Login to continue</a>
|
||||
</div>
|
||||
{% elif subgroup.has_student(frappe.session.user) %}
|
||||
<div class="alert alert-info">
|
||||
<p>You are already a student of this course.</p>
|
||||
<a class="btn btn-primary" href="#">Go to the course</a>
|
||||
</div>
|
||||
{% elif subgroup.has_join_request(frappe.session.user) %}
|
||||
<div class="alert alert-info">
|
||||
<p>We have received your request to join the course. You'll hear back from us soon.</p>
|
||||
</div>
|
||||
{% else %}
|
||||
|
||||
<a class="btn btn-primary" id="join">Join the course</a>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
console.log("ready!")
|
||||
$("#join").click(function() {
|
||||
var parts = window.location.pathname.split("/")
|
||||
var course = parts[2];
|
||||
var cohort = parts[4];
|
||||
var subgroup = parts[5];
|
||||
var invite_code = parts[6];
|
||||
|
||||
frappe.call('school.lms.api.join_cohort', {
|
||||
course: course,
|
||||
cohort: cohort,
|
||||
subgroup: subgroup,
|
||||
invite_code: invite_code
|
||||
})
|
||||
.then(r => {
|
||||
if (r.message.ok) {
|
||||
let d = new frappe.ui.Dialog({
|
||||
title: "Notification",
|
||||
primary_action_label: "Proceed",
|
||||
primary_action() {
|
||||
d.hide();
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
var message = "We've received your interest to join the course. We'll hear from us soon.";
|
||||
d.show();
|
||||
d.set_message(message);
|
||||
}
|
||||
else {
|
||||
frappe.msgprint(r.message.error);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
24
school/www/cohorts/join.py
Normal file
24
school/www/cohorts/join.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import frappe
|
||||
from . import utils
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
|
||||
course = utils.get_course(frappe.form_dict["course"])
|
||||
cohort = course and utils.get_cohort(course, frappe.form_dict["cohort"])
|
||||
subgroup = cohort and utils.get_subgroup(cohort, frappe.form_dict["subgroup"])
|
||||
if not subgroup:
|
||||
context.template = "www/404.html"
|
||||
return
|
||||
|
||||
invite_code = frappe.form_dict["invite_code"]
|
||||
if subgroup.invite_code != invite_code:
|
||||
context.template = "www/404.html"
|
||||
return
|
||||
|
||||
utils.add_nav(context, "All Courses", "/courses")
|
||||
utils.add_nav(context, course.title, "/courses/" + course.name)
|
||||
|
||||
context.course = course
|
||||
context.cohort = cohort
|
||||
context.subgroup = subgroup
|
||||
Reference in New Issue
Block a user