[FIX] RECRUITMENT: #875
This commit is contained in:
@@ -246,10 +246,10 @@
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if perms.recruitment.change_candidate or request.user.employee_get in stage.stage_managers.all %}
|
||||
<button type="button" hx-get='{% url "send-mail" cand.id %}' title="{% trans " Send Mail" %}"
|
||||
hx-target="#objectDetailsModalTarget" hx-swap="innerHTML" class="oh-btn oh-btn--light"
|
||||
data-toggle="oh-modal-toggle" data-target="#objectDetailsModal"
|
||||
onclick="$('#objectDetailsModal').addClass('oh-modal--show')"
|
||||
<button type="button" hx-get='{% url "send-mail" cand.id %}' title="{% trans 'Send Mail' %}"
|
||||
hx-target="#objectCreateModalTarget" hx-swap="innerHTML" class="oh-btn oh-btn--light"
|
||||
data-toggle="oh-modal-toggle" data-target="#objectCreateModal"
|
||||
onclick="$('#objectCreateModal').addClass('oh-modal--show')"
|
||||
style="flex: 1 0 auto; width:20px;height: 40.68px; padding: 0;">
|
||||
<ion-icon name="mail-open-outline"></ion-icon>
|
||||
</button>
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
{% load i18n %}
|
||||
<button hidden id="previewHxButton" hx-post="{% url 'get-mail-preview' %}?candidate_id={{cand.id}}" hx-target="#preview"
|
||||
hx-include="#writeField"
|
||||
<button hidden id="previewHxButton" hx-post="{% url 'get-mail-preview' %}?{% if cand %}candidate_id={{cand.id}}&{% endif %}" hx-target="#preview"
|
||||
hx-include="#ack-form-{{cand.id}}"
|
||||
hx-on-htmx-before-request="if (!$('#template').val()) { event.preventDefault(); }">
|
||||
</button>
|
||||
<div id="ack-message-{{cand.id}}"></div>
|
||||
|
||||
<div class="oh-modal__dialog-header">
|
||||
<span class="oh-modal__dialog-title" id="sendMailModalLabel">
|
||||
<h5>{% trans 'Send Mail' %}</h5>
|
||||
<h5>{% if cand %}
|
||||
{% trans "Send Mail to" %} {{ cand.name }}
|
||||
{% else %}
|
||||
{% trans "Send Mail to Multiple Candidates" %}
|
||||
{% endif %}
|
||||
</h5>
|
||||
</span>
|
||||
<button class="oh-modal__close" aria-label="Close"><ion-icon name="close-outline"></ion-icon></button>
|
||||
</div>
|
||||
@@ -16,7 +21,10 @@
|
||||
<form onsubmit="$(this).closest('.oh-modal--show').removeClass('oh-modal--show')"
|
||||
hx-post='{% url "send-acknowledgement" %}' hx-swap="none" class="oh-general__tab-target oh-profile-section"
|
||||
id='ack-form-{{cand.id}}' hx-target="#ack-message-{{cand.id}}" hx-encoding="multipart/form-data">
|
||||
<input type="hidden" value="{{cand.id}}" name="id">
|
||||
{% if cand %}
|
||||
<input type="hidden" value="{{ cand.id }}" name="id">
|
||||
{% endif %}
|
||||
|
||||
<div class="modal-body">
|
||||
{% if cand %}
|
||||
<div class="oh-timeoff-modal__profile-content">
|
||||
@@ -81,8 +89,8 @@
|
||||
</span>
|
||||
</div>
|
||||
<div id="write" class="oh-tabs__view active">
|
||||
<textarea id="writeField" class="oh-input oh-input--textarea" hidden name="body" {% if not cand %}
|
||||
data-summernote {% endif %} required placeholder="Type something here..."></textarea>
|
||||
<textarea id="writeField" class="oh-input oh-input--textarea" hidden name="body"
|
||||
data-summernote required placeholder="Type something here..."></textarea>
|
||||
</div>
|
||||
<div id="preview" class="oh-tabs__view">
|
||||
<textarea id="previewField" class="oh-input oh-input--textarea" placeholder="preview..."></textarea>
|
||||
@@ -181,8 +189,8 @@
|
||||
data: { "candidate_id": "{{cand.id}}" },
|
||||
dataType: "Json",
|
||||
success: function (response) {
|
||||
$(`#ack-form-{{cand.id}} [name="body"]`).html(response.body).change();
|
||||
$(`#ack-form-{{cand.id}} [class="note-editable"]`).html(response.body);
|
||||
$(`#objectCreateModalTarget [name="body"]`).html(response.body).change();
|
||||
$(`#objectCreateModalTarget [class="note-editable"]`).html(response.body);
|
||||
$('#previewHxButton').click();
|
||||
}
|
||||
});
|
||||
@@ -205,5 +213,7 @@
|
||||
{% if form.instance.title %}
|
||||
setModalLabel("{{ form.instance.title|escapejs }}", "#viewTemplateModalLabel");
|
||||
{% endif %}
|
||||
initializeSummernote({{ cand.id }}, {{ searchWords| safe }});
|
||||
{% if cand %}
|
||||
initializeSummernote({{ cand.id }}, {{ searchWords| safe }});
|
||||
{% endif %}
|
||||
</script>
|
||||
|
||||
@@ -452,31 +452,47 @@ def get_template_hint(request, obj_id=None):
|
||||
@login_required
|
||||
def get_mail_preview(request):
|
||||
"""
|
||||
This method is used to return the mail template preview as an HTTP response.
|
||||
Returns the mail template preview as HTML.
|
||||
"""
|
||||
body = request.POST.get("body")
|
||||
candidate_id = request.GET.get("candidate_id")
|
||||
|
||||
if not body:
|
||||
return HttpResponse("No body provided", status=400)
|
||||
|
||||
template_bdy = template.Template(body)
|
||||
context = {}
|
||||
candidate_id = request.GET.get("candidate_id")
|
||||
candidate_ids = request.POST.getlist("candidates") # 875
|
||||
|
||||
if candidate_id:
|
||||
try:
|
||||
candidate_obj = Candidate.objects.get(id=candidate_id)
|
||||
context = {
|
||||
"instance": candidate_obj,
|
||||
"model_instance": candidate_obj,
|
||||
"self": request.user.employee_get,
|
||||
"request": request,
|
||||
}
|
||||
except Candidate.DoesNotExist:
|
||||
# Fetch one candidate for preview if provided
|
||||
candidate_obj = None
|
||||
if candidate_id or candidate_ids:
|
||||
ids = [candidate_id] if candidate_id else candidate_ids
|
||||
candidate_obj = Candidate.objects.filter(id__in=ids).first()
|
||||
if not candidate_obj:
|
||||
return HttpResponse("Candidate not found", status=404)
|
||||
|
||||
rendered_body = template_bdy.render(template.Context(context)) or " "
|
||||
# Build context
|
||||
context = {
|
||||
"instance": candidate_obj,
|
||||
"model_instance": candidate_obj,
|
||||
"self": getattr(request.user, "employee_get", None),
|
||||
"request": request,
|
||||
}
|
||||
|
||||
textarea_field = f'<div class="oh-input oh-input--textarea" style="border: solid .1px #dbd7d7;">{rendered_body}</div>'
|
||||
# Render template
|
||||
rendered_body = template.Template(body).render(template.Context(context)) or " "
|
||||
|
||||
# Add preview note if multiple candidates
|
||||
if candidate_ids and len(candidate_ids) > 1 and candidate_obj:
|
||||
rendered_body = (
|
||||
f"<p style='color:gray; font-size:13px;'>"
|
||||
f"Preview shown for {candidate_obj.name}. "
|
||||
f"Mail will be personalized for {len(candidate_ids)} candidates."
|
||||
f"</p>{rendered_body}"
|
||||
)
|
||||
|
||||
# Wrap in styled div
|
||||
textarea_field = (
|
||||
f'<div class="oh-input oh-input--textarea" '
|
||||
f'style="border: solid .1px #dbd7d7; padding:5px;">{rendered_body}</div>'
|
||||
)
|
||||
|
||||
return HttpResponse(textarea_field, content_type="text/html")
|
||||
|
||||
Reference in New Issue
Block a user