[FIX] EMPLOYEE: #918
This commit is contained in:
@@ -23,8 +23,10 @@
|
||||
<div class="oh-main__titlebar oh-main__titlebar--right">
|
||||
{% if documents %}
|
||||
<form
|
||||
hx-get="{% url 'document-request-filter-view' %}"
|
||||
hx-get="{% url 'document-request-view' %}"
|
||||
hx-target="#view-container"
|
||||
hx-select="#view-container"
|
||||
hx-swap="outerHTML"
|
||||
id="filterForm"
|
||||
class="d-flex"
|
||||
onsubmit = "event.preventDefault()"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="oh-modal__dialog custom-dialog">
|
||||
<div class="oh-modal__dialog-header">
|
||||
<span class="oh-modal__dialog-title" id="viewFileModalLabel">{% trans "View File" %}</span>
|
||||
<button class="oh-modal__close" aria-label="Close">
|
||||
<button class="oh-modal__close" aria-label="Close" onclick="$('.filterButton').click()">
|
||||
<ion-icon name="close-outline" role="img" class="md hydrated" aria-label="close outline"></ion-icon>
|
||||
</button>
|
||||
</div>
|
||||
@@ -140,11 +140,22 @@
|
||||
</a>
|
||||
{% else %}
|
||||
{% comment %} # 918 {% endcomment %}
|
||||
<a type="submit" hx-confirm="{% trans 'Do you want to approve this request' %}"
|
||||
hx-get="{% url 'document-approve' document.id %}" hx-target="this" hx-swap="outerHTML"
|
||||
hx-vals='{ "refresh_url": "{% url 'document-request-filter-view' %}?{{pd}}&{{document_list.dynamic_name}}={{ document_list.list.number }}" }'
|
||||
<a
|
||||
hx-confirm="{% trans 'Do you want to approve this request' %}"
|
||||
hx-get="{% url 'document-approve' document.id %}"
|
||||
hx-target="this"
|
||||
hx-swap="outerHTML"
|
||||
hx-vals='{
|
||||
"refresh_url": "{% url "document-request-view" %}?{{ pd }}{% if pd %}&{% endif %}{{ document_list.dynamic_name }}={{ document_list.list.number }}",
|
||||
"hx_target": "#requestDocument{{ document.id }}",
|
||||
"hx_select": "#requestDocument{{ document.id }}",
|
||||
"hx_swap": "outerHTML"
|
||||
}'
|
||||
hx-on-htmx-after-request="reloadMessage(this);"
|
||||
title="{% trans 'Approve' %}" class="oh-btn oh-btn--success w-100" onclick="event.stopPropagation()">
|
||||
title="{% trans 'Approve' %}"
|
||||
class="oh-btn oh-btn--success w-100"
|
||||
onclick="event.stopPropagation();"
|
||||
>
|
||||
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,98 +1,73 @@
|
||||
{% load i18n %} {% load horillafilters %} {% load static %}
|
||||
<div class="d-flex justify-content-end">
|
||||
<div class="oh-btn-group mb-4">
|
||||
<a
|
||||
type="submit"
|
||||
hx-get="{% url 'file-upload' document.id %}"
|
||||
hx-target="#objectCreateModalTarget" data-toggle="oh-modal-toggle"
|
||||
data-target="#objectCreateModal"
|
||||
title="Upload file"
|
||||
class="oh-btn oh-btn--warning w-100"
|
||||
>
|
||||
<a type="submit" hx-get="{% url 'file-upload' document.id %}" hx-target="#objectCreateModalTarget"
|
||||
data-toggle="oh-modal-toggle" data-target="#objectCreateModal" title="Upload file"
|
||||
class="oh-btn oh-btn--warning w-100">
|
||||
<ion-icon name="attach-outline"></ion-icon>
|
||||
</a>
|
||||
{% if document.document %}
|
||||
{% if perms.horilla_document.change_documentrequest %}
|
||||
{% if document.status == "approved" %}
|
||||
<a class="oh-btn oh-btn--success w-100 oh-btn--disabled" title="{% trans 'Approved' %}">
|
||||
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
<a
|
||||
type="submit"
|
||||
hx-get="{% url 'document-approve' document.id %}"
|
||||
hx-target="#viewFile"
|
||||
title="{% trans 'Approve' %}"
|
||||
class="oh-btn oh-btn--success w-100"
|
||||
>
|
||||
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
|
||||
</a>
|
||||
{% if perms.horilla_document.change_documentrequest %}
|
||||
{% if document.status == "approved" %}
|
||||
<a class="oh-btn oh-btn--success w-100 oh-btn--disabled" title="{% trans 'Approved' %}">
|
||||
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
<a hx-get="{% url 'document-approve' document.id %}"
|
||||
hx-vals='{
|
||||
"refresh_url": "{% url "view-file" document.id %}",
|
||||
"hx_target": "#viewFile"
|
||||
}'
|
||||
hx-on-htmx-after-request="reloadMessage(this);"
|
||||
title="{% trans 'Approve' %}"
|
||||
class="oh-btn oh-btn--success w-100">
|
||||
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if document.status == "rejected" %}
|
||||
<a class="oh-btn oh-btn--danger w-100 oh-btn--disabled" title="{% trans 'Rejected' %}">
|
||||
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
<a type="submit" hx-get="{% url 'document-reject' document.id %}" hx-target="#rejectFileForm"
|
||||
data-target="#rejectFileModal" data-toggle="oh-modal-toggle" title="{% trans 'Reject' %}"
|
||||
class="oh-btn oh-btn--danger w-100">
|
||||
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if document.status == "rejected" %}
|
||||
<a class="oh-btn oh-btn--danger w-100 oh-btn--disabled" title="{% trans 'Rejected' %}">
|
||||
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
<a
|
||||
type="submit"
|
||||
hx-get="{% url 'document-reject' document.id %}"
|
||||
hx-target="#rejectFileForm"
|
||||
data-target="#rejectFileModal"
|
||||
data-toggle="oh-modal-toggle"
|
||||
title="{% trans 'Reject' %}"
|
||||
class="oh-btn oh-btn--danger w-100"
|
||||
>
|
||||
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<a
|
||||
href="data:{{ content_type }};base64,{{ file_content|base64_encode }}"
|
||||
class="oh-btn oh-btn--info w-100"
|
||||
download="{{document.title}}"
|
||||
title="{% trans 'Download' %}"
|
||||
><ion-icon class="me-1" name="download-outline"></ion-icon
|
||||
></a>
|
||||
<a href="data:{{ content_type }};base64,{{ file_content|base64_encode }}" class="oh-btn oh-btn--info w-100"
|
||||
download="{{document.title}}" title="{% trans 'Download' %}"><ion-icon class="me-1"
|
||||
name="download-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% if document.document %}
|
||||
<div class="modal-body" {% if document.status == "rejected" %} style="border: 5px solid red;"{% endif %}>
|
||||
<div class="modal-body" {% if document.status == "rejected" %} style="border: 5px solid red;" {% endif %}>
|
||||
<!-- Display the file content based on the file type -->
|
||||
{% if file_extension == 'pdf' or file_extension == 'txt' or file_extension == 'docx' or file_extension == 'xlsx' %}
|
||||
<embed
|
||||
src="data:{{ content_type }};base64,{{ file_content|base64_encode }}"
|
||||
type="{{ content_type }}"
|
||||
width="100%"
|
||||
height="500px"
|
||||
/>
|
||||
<embed src="data:{{ content_type }};base64,{{ file_content|base64_encode }}" type="{{ content_type }}" width="100%"
|
||||
height="500px" />
|
||||
{% elif file_extension == 'jpg' or file_extension == 'jpeg' or file_extension == 'png' or file_extension == 'webp' %}
|
||||
<div class="container">
|
||||
<img
|
||||
src="data:{{ content_type }};base64,{{ file_content|base64_encode }}"
|
||||
alt="File Preview"
|
||||
class="img-fluid"
|
||||
style="display: block; width: 100%;height: 500px;"
|
||||
/>
|
||||
</div>
|
||||
<div class="container">
|
||||
<img src="data:{{ content_type }};base64,{{ file_content|base64_encode }}" alt="File Preview" class="img-fluid"
|
||||
style="display: block; width: 100%;height: 500px;" />
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{% trans "File format not supported for preview." %}</p>
|
||||
<p>{% trans "File format not supported for preview." %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if document.status == 'rejected' %}
|
||||
<h2 class="oh-label"> <b>{% trans "Reject Reason: " %}</b></h2>
|
||||
<p class="ms-4">{{document.reject_reason}}</p>
|
||||
<h2 class="oh-label"> <b>{% trans "Reject Reason: " %}</b></h2>
|
||||
<p class="ms-4">{{document.reject_reason}}</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="oh-not-found">
|
||||
<img
|
||||
style="width: 150px; height: 150px;"
|
||||
src="{% static 'images/ui/document.png' %}"
|
||||
class="oh-404__image mb-4"
|
||||
alt="Page not found. 404."
|
||||
/>
|
||||
<h3 class="oh-404__subtitle">
|
||||
{% trans "No Document to view." %}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="oh-not-found">
|
||||
<img style="width: 150px; height: 150px;" src="{% static 'images/ui/document.png' %}" class="oh-404__image mb-4"
|
||||
alt="Page not found. 404." />
|
||||
<h3 class="oh-404__subtitle">
|
||||
{% trans "No Document to view." %}
|
||||
</h3>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -459,15 +459,16 @@ def shift_tab(request, emp_id):
|
||||
@manager_can_enter("horilla_documents.view_documentrequest")
|
||||
def document_request_view(request):
|
||||
"""
|
||||
This function is used to view documents requests of employees.
|
||||
This function is used to view and filter document requests of employees.
|
||||
|
||||
Parameters:
|
||||
request (HttpRequest): The HTTP request object.
|
||||
|
||||
Returns: return document_request template
|
||||
Returns:
|
||||
Render 'documents/document_requests.html' with documents and filters.
|
||||
"""
|
||||
previous_data = request.GET.urlencode()
|
||||
filter_class = DocumentRequestFilter()
|
||||
filter_class = DocumentRequestFilter(request.GET or None)
|
||||
document_requests = DocumentRequest.objects.all()
|
||||
documents = Document.objects.filter(document_request_id__isnull=False)
|
||||
documents = filtersubordinates(
|
||||
@@ -475,6 +476,12 @@ def document_request_view(request):
|
||||
perm="horilla_documents.view_documentrequest",
|
||||
queryset=documents,
|
||||
)
|
||||
|
||||
if request.GET:
|
||||
filtered_docs = filter_class.qs
|
||||
filtered_docs = filtered_docs.filter(document_request_id__isnull=False)
|
||||
documents = filtered_docs
|
||||
|
||||
documents = group_by_queryset(
|
||||
documents, "document_request_id", request.GET.get("page"), "page"
|
||||
)
|
||||
@@ -847,6 +854,9 @@ def document_approve(request, id):
|
||||
|
||||
document_obj = get_object_or_404(Document, id=id)
|
||||
refresh_url = request.GET.get("refresh_url") or request.POST.get("refresh_url")
|
||||
hx_target = request.GET.get("hx_target") or request.POST.get("hx_target")
|
||||
hx_select = request.GET.get("hx_select") or request.POST.get("hx_select")
|
||||
hx_swap = request.GET.get("hx_swap") or request.POST.get("hx_swap")
|
||||
if document_obj.document:
|
||||
document_obj.status = "approved"
|
||||
document_obj.save()
|
||||
@@ -855,14 +865,20 @@ def document_approve(request, id):
|
||||
messages.error(request, _("No document uploaded"))
|
||||
# 918
|
||||
if refresh_url:
|
||||
attrs = []
|
||||
if hx_target:
|
||||
attrs.append(f'hx-target="{hx_target}"')
|
||||
if hx_select:
|
||||
attrs.append(f'hx-select="{hx_select}"')
|
||||
if hx_swap:
|
||||
attrs.append(f'hx-swap="{hx_swap}"')
|
||||
|
||||
span = f"""
|
||||
<span
|
||||
hx-trigger="load"
|
||||
hx-get="{refresh_url}"
|
||||
hx-target="#requestDocument{id}"
|
||||
hx-select="#requestDocument{id}"
|
||||
hx-swap="outerHTML"
|
||||
">
|
||||
{' '.join(attrs)}
|
||||
>
|
||||
</span>
|
||||
"""
|
||||
return HttpResponse(span)
|
||||
|
||||
Reference in New Issue
Block a user