Merge pull request #655 from pateljannat/append-student-email
fix: Append student email to batch
This commit is contained in:
@@ -396,15 +396,6 @@ def get_timetable_details(timetable):
|
||||
return timetable
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def send_email_to_students(batch, subject, reply_to, message):
|
||||
frappe.only_for("Moderator")
|
||||
students = frappe.get_all("Batch Student", {"parent": batch}, pluck="student")
|
||||
frappe.sendmail(
|
||||
recipients=students, subject=subject, reply_to=reply_to, message=message
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def is_milestone_complete(idx, batch):
|
||||
previous_rows = frappe.get_all(
|
||||
|
||||
@@ -2478,4 +2478,8 @@ select {
|
||||
|
||||
.questions-table .row-index {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.text-color {
|
||||
color: var(--text-color);
|
||||
}
|
||||
@@ -75,14 +75,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if is_moderator %}
|
||||
<div class="mt-4">
|
||||
<button class="btn btn-secondary btn-sm btn-email">
|
||||
{{ _("Email to Students") }}
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if batch_info.custom_component %}
|
||||
<div class="mt-4">
|
||||
{{ batch_info.custom_component }}
|
||||
@@ -140,6 +132,15 @@
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#emails">
|
||||
{{ _("Emails") }}
|
||||
<span class="course-list-count">
|
||||
{{ batch_emails | length }}
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if batch_students | length and (is_moderator or is_student) %}
|
||||
@@ -192,6 +193,10 @@
|
||||
<div class="tab-pane" id="assessments" role="tabpanel" aria-labelledby="assessments">
|
||||
{{ AssessmentsSection(batch_info) }}
|
||||
</div>
|
||||
|
||||
<div class="tab-pane" id="emails" role="tabpanel" aria-labelledby="emails">
|
||||
{{ EmailsSection() }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if batch_students | length and (is_moderator or is_student or is_evaluator) %}
|
||||
@@ -376,6 +381,41 @@
|
||||
</article>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro EmailsSection() %}
|
||||
<div class="my-4">
|
||||
<button class="btn btn-secondary btn-sm btn-email">
|
||||
{{ _("Email to Students") }}
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
{% for email in batch_emails %}
|
||||
<div class="frappe-card mb-5">
|
||||
<div class="flex justify-between m-1">
|
||||
<span class="text-color flex">
|
||||
<span class="margin-right">
|
||||
{% set member = frappe.db.get_value("User", email.sender, ["full_name", "username", "name", "user_image"], as_dict=1) %}
|
||||
{{ widgets.Avatar(member=member, avatar_class="avatar-small") }}
|
||||
</span>
|
||||
<span>
|
||||
{{ member.full_name }}
|
||||
<div class="text-muted">
|
||||
<span class="frappe-timestamp" data-timestamp="{{ email.communication_date }}" title="{{ communication_date }}">
|
||||
{{ frappe.utils.pretty_date(email.communication_date) }}
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="ml-10">
|
||||
{{ email.content }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro AssessmentList(assessments) %}
|
||||
{% if assessments | length %}
|
||||
<div class="form-grid">
|
||||
|
||||
@@ -831,12 +831,33 @@ const email_to_students = () => {
|
||||
|
||||
const send_email = (values) => {
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_batch.lms_batch.send_email_to_students",
|
||||
method: "frappe.client.get_list",
|
||||
args: {
|
||||
batch: $(".class-details").data("batch"),
|
||||
doctype: "Batch Student",
|
||||
parent: "LMS Batch",
|
||||
fields: ["student"],
|
||||
filters: {
|
||||
parent: $(".class-details").data("batch"),
|
||||
},
|
||||
},
|
||||
callback: (data) => {
|
||||
send_email_to_students(data.message, values);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const send_email_to_students = (students, values) => {
|
||||
students = students.map((row) => row.student);
|
||||
frappe.call({
|
||||
method: "frappe.core.doctype.communication.email.make",
|
||||
args: {
|
||||
recipients: students.join(", "),
|
||||
cc: values.reply_to,
|
||||
subject: values.subject,
|
||||
reply_to: values.reply_to,
|
||||
message: values.message,
|
||||
content: values.message,
|
||||
doctype: "LMS Batch",
|
||||
name: $(".class-details").data("batch"),
|
||||
send_email: 1,
|
||||
},
|
||||
callback: (r) => {
|
||||
this.email_dialog.hide();
|
||||
@@ -844,6 +865,9 @@ const send_email = (values) => {
|
||||
message: __("Email sent successfully"),
|
||||
indicator: "green",
|
||||
});
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -71,6 +71,13 @@ def get_context(context):
|
||||
)
|
||||
context.course_name_list = [course.course for course in context.batch_courses]
|
||||
context.assessments = get_assessments(batch_name)
|
||||
context.batch_emails = frappe.get_all(
|
||||
"Communication",
|
||||
filters={"reference_doctype": "LMS Batch", "reference_name": batch_name},
|
||||
fields=["subject", "content", "recipients", "cc", "communication_date", "sender"],
|
||||
order_by="communication_date desc",
|
||||
)
|
||||
|
||||
context.batch_students = get_class_student_details(
|
||||
batch_students, batch_courses, context.assessments
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user