[UPDT] EMPLOYEE: Added paginatination in document requests
This commit is contained in:
@@ -8,11 +8,12 @@ from django import forms
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from base.methods import choosesubordinates
|
||||
from base.methods import choosesubordinates, is_reportingmanager
|
||||
from employee.filters import DocumentRequestFilter
|
||||
from employee.models import Employee
|
||||
from horilla.decorators import manager_can_enter
|
||||
from horilla_documents.forms import (
|
||||
@@ -23,7 +24,7 @@ from horilla_documents.forms import (
|
||||
)
|
||||
from horilla_documents.models import Document, DocumentRequest
|
||||
from horilla_views.cbv_methods import login_required
|
||||
from horilla_views.generic.cbv.views import HorillaFormView
|
||||
from horilla_views.generic.cbv.views import HorillaFormView, HorillaNavView
|
||||
from notifications.signals import notify
|
||||
|
||||
|
||||
@@ -137,7 +138,7 @@ class DocumentRejectCbvForm(HorillaFormView):
|
||||
messages.error(self.request, _("Document request rejected"))
|
||||
else:
|
||||
messages.error(self.request, _("No document uploaded"))
|
||||
# form.save()
|
||||
form.save()
|
||||
return HttpResponse("<script>window.location.reload();</script>")
|
||||
return super().form_valid(form)
|
||||
|
||||
@@ -188,3 +189,60 @@ class DocumentUploadForm(HorillaFormView):
|
||||
form.save()
|
||||
return HttpResponse("<script>window.location.reload();</script>")
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class DocumentRequestNav(HorillaNavView):
|
||||
"""
|
||||
For nav bar
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.search_url = reverse("document-request-filter-view")
|
||||
self.create_attrs = f"""
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
hx-target="#genericModalBody"
|
||||
hx-get="{reverse_lazy('document-request-create')}"
|
||||
"""
|
||||
|
||||
if self.request.user.has_perm(
|
||||
"employee.change_employee"
|
||||
) or is_reportingmanager(self.request):
|
||||
if self.request.user.has_perm(
|
||||
"horilla_documents.change_documentrequest"
|
||||
) or is_reportingmanager(self.request):
|
||||
self.actions = [
|
||||
{
|
||||
"action": _("Bulk Approve Requests"),
|
||||
"attrs": f"""
|
||||
id="bulkApproveDocument"
|
||||
hx-post="{reverse('document-bulk-approve')}"
|
||||
hx-confirm='Do you really want to approve all the selected requests?'
|
||||
style="cursor: pointer;"
|
||||
hx-on:click="validateDocsIds(event, 'approved');"
|
||||
data-action="approved"
|
||||
""",
|
||||
},
|
||||
{
|
||||
"action": _("Bulk Reject Requests"),
|
||||
"attrs": f"""
|
||||
hx-get={reverse('document-bulk-reject')}
|
||||
data-target="#objectCreateModal"
|
||||
data-toggle="oh-modal-toggle"
|
||||
hx-on:click="validateDocsIds(event, 'rejected');"
|
||||
data-action="rejected"
|
||||
hx-target="#objectCreateModalTarget"
|
||||
id="bulkRejectDocument"
|
||||
style="cursor: pointer;"
|
||||
""",
|
||||
},
|
||||
]
|
||||
else:
|
||||
self.actions = None
|
||||
|
||||
nav_title = _("Document Requests")
|
||||
filter_body_template = "cbv/documents/document_filter.html"
|
||||
filter_instance = DocumentRequestFilter()
|
||||
filter_form_context_name = "form"
|
||||
search_swap_target = "#view-container"
|
||||
|
||||
@@ -32,13 +32,102 @@ var alreadyActionMessages = {
|
||||
},
|
||||
};
|
||||
|
||||
function validateDocsIds(event) {
|
||||
// function validateDocsIds(event) {
|
||||
// getCurrentLanguageCode(function (lang) {
|
||||
// const ids = [];
|
||||
// const checkedRows = $("[type=checkbox]:checked");
|
||||
// const takeAction = $(event.currentTarget).data("action");
|
||||
// let alreadyTakeAction = false;
|
||||
|
||||
// checkedRows.each(function () {
|
||||
// const id = $(this).attr("id");
|
||||
// const status = $(this).data("status");
|
||||
|
||||
// if (id) {
|
||||
// if (status === takeAction) alreadyTakeAction = true;
|
||||
// ids.push(id);
|
||||
// }
|
||||
// });
|
||||
|
||||
// if (ids.length === 0) {
|
||||
// var norowMessages = {
|
||||
// ar: "لم يتم تحديد أي صفوف.",
|
||||
// de: "Es wurden keine Zeilen ausgewählt.",
|
||||
// es: "No se han seleccionado filas.",
|
||||
// en: "No rows have been selected.",
|
||||
// fr: "Aucune ligne n'a été sélectionnée.",
|
||||
// };
|
||||
// event.preventDefault();
|
||||
// Swal.fire({
|
||||
// text: norowMessages[lang] || norowMessages.en,
|
||||
// icon: "warning",
|
||||
// confirmButtonText: "Close",
|
||||
// });
|
||||
// } else if (alreadyTakeAction) {
|
||||
// event.preventDefault();
|
||||
// Swal.fire({
|
||||
// text:
|
||||
// alreadyActionMessages[takeAction][lang] ||
|
||||
// alreadyActionMessages[takeAction].en,
|
||||
// icon: "warning",
|
||||
// confirmButtonText: "Close",
|
||||
// });
|
||||
// } else {
|
||||
// // Directly trigger action without confirmation
|
||||
// const triggerId =
|
||||
// takeAction === "approved"
|
||||
// ? "#bulkApproveDocument"
|
||||
// : "#bulkRejectDocument";
|
||||
// $(triggerId).attr("hx-vals", JSON.stringify({ ids })).click();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
function validateDocsIds(event, action = null) {
|
||||
getCurrentLanguageCode(function (lang) {
|
||||
const ids = [];
|
||||
const checkedRows = $("[type=checkbox]:checked");
|
||||
const takeAction = $(event.currentTarget).data("action");
|
||||
|
||||
// Use passed action parameter or try to get from element
|
||||
let takeAction = action;
|
||||
let currentElement = null;
|
||||
|
||||
// Handle case where event might be undefined or not have currentTarget
|
||||
if (event && event.currentTarget) {
|
||||
currentElement = event.currentTarget;
|
||||
} else if (event && event.target) {
|
||||
currentElement = event.target;
|
||||
}
|
||||
|
||||
if (!takeAction && currentElement) {
|
||||
// Try multiple ways to get the action attribute
|
||||
takeAction = $(currentElement).data("action");
|
||||
|
||||
// If data() doesn't work, try attr()
|
||||
if (!takeAction) {
|
||||
takeAction = $(currentElement).attr("data-action");
|
||||
}
|
||||
|
||||
// If still undefined, try getting from the element directly
|
||||
if (!takeAction) {
|
||||
takeAction = currentElement.getAttribute("data-action");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let alreadyTakeAction = false;
|
||||
|
||||
// Add validation to ensure takeAction is valid
|
||||
if (!takeAction || (takeAction !== "approved" && takeAction !== "rejected")) {
|
||||
if (currentElement && currentElement.attributes) {
|
||||
}
|
||||
if (event && event.preventDefault) {
|
||||
event.preventDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
checkedRows.each(function () {
|
||||
const id = $(this).attr("id");
|
||||
const status = $(this).data("status");
|
||||
@@ -84,6 +173,8 @@ function validateDocsIds(event) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function highlightRow(checkbox) {
|
||||
checkbox.closest(".oh-user_permission-list_item").removeClass("highlight-selected");
|
||||
if (checkbox.is(":checked")) {
|
||||
@@ -91,17 +182,31 @@ function highlightRow(checkbox) {
|
||||
}
|
||||
}
|
||||
|
||||
// function selectAllDocuments(event) {
|
||||
// event.stopPropagation();
|
||||
// const checkbox = event.currentTarget;
|
||||
// const isChecked = checkbox.checked;
|
||||
|
||||
// const accordionBody = checkbox
|
||||
// .closest(".oh-accordion-meta__header")
|
||||
// .nextElementSibling;
|
||||
|
||||
// if (accordionBody) {
|
||||
// const checkboxes = accordionBody.querySelectorAll('[type="checkbox"]');
|
||||
// checkboxes.forEach(cb => cb.checked = isChecked);
|
||||
// }
|
||||
// }
|
||||
|
||||
function selectAllDocuments(event) {
|
||||
event.stopPropagation();
|
||||
const checkbox = event.currentTarget;
|
||||
const isChecked = checkbox.checked;
|
||||
|
||||
const accordionBody = checkbox
|
||||
.closest(".oh-accordion-meta__header")
|
||||
.nextElementSibling;
|
||||
const button = checkbox.closest('button');
|
||||
const accordionPanel = button ? button.nextElementSibling : null;
|
||||
|
||||
if (accordionBody) {
|
||||
const checkboxes = accordionBody.querySelectorAll('[type="checkbox"]');
|
||||
if (accordionPanel && accordionPanel.classList.contains('accordion-panel')) {
|
||||
const checkboxes = accordionPanel.querySelectorAll('input[type="checkbox"]');
|
||||
checkboxes.forEach(cb => cb.checked = isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
94
employee/templates/cbv/documents/document_filter.html
Normal file
94
employee/templates/cbv/documents/document_filter.html
Normal file
@@ -0,0 +1,94 @@
|
||||
{% load i18n %}
|
||||
<div class="oh-dropdown__filter-body">
|
||||
<div class="oh-accordion">
|
||||
<div class="oh-accordion-header">{% trans "Work Info" %}</div>
|
||||
<div class="oh-accordion-body">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id.id_for_label}}">{% trans "Employee" %}</label>
|
||||
{{form.employee_id}}
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for ="{{form.employee_id__employee_work_info__job_position_id.id_for_label}}"
|
||||
>{% trans "Job Position" %}</label
|
||||
>
|
||||
{{form.employee_id__employee_work_info__job_position_id}}
|
||||
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__employee_work_info__shift_id.id_for_label}}">{% trans "Shift" %}</label>
|
||||
{{form.employee_id__employee_work_info__shift_id}}
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__employee_work_info__company_id.id_for_label}}">{% trans "Company" %}</label>
|
||||
{{form.employee_id__employee_work_info__company_id}}
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__is_active.id_for_label}}">{% trans "Is Active" %}?</label>
|
||||
{{form.employee_id__is_active}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__employee_work_info__department_id.id_for_label}}">{% trans "Department" %}</label>
|
||||
{{form.employee_id__employee_work_info__department_id}}
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__employee_work_info__job_role_id.id_for_label}}">{% trans "Job Role" %}</label>
|
||||
{{form.employee_id__employee_work_info__job_role_id}}
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__employee_work_info__work_type_id.id_for_label}}">{% trans "Work Type" %}</label>
|
||||
{{form.employee_id__employee_work_info__work_type_id}}
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__employee_work_info__reporting_manager_id.id_for_label}}"
|
||||
>{% trans "Reporting Manager" %}</label
|
||||
>
|
||||
{{form.employee_id__employee_work_info__reporting_manager_id}}
|
||||
</div>
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.employee_id__gender.id_for_label}}">{% trans "Gender" %}</label>
|
||||
{{form.employee_id__gender}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-accordion">
|
||||
<div class="oh-accordion-header">
|
||||
{% trans "Document Request" %}
|
||||
</div>
|
||||
<div class="oh-accordion-body">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
||||
{% comment %} <div class="oh-input-group">
|
||||
<label class="oh-label"
|
||||
>{% trans "title" %}</label
|
||||
>
|
||||
{{form.title}}
|
||||
</div> {% endcomment %}
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.status.id_for_label}}">{% trans "Status" %}</label>
|
||||
{{form.status}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
||||
{% comment %} <div class="oh-input-group">
|
||||
<label class="oh-label"
|
||||
>{% trans "Employee" %}</label
|
||||
>
|
||||
{{form.employee_id}}
|
||||
</div> {% endcomment %}
|
||||
<div class="oh-input-group">
|
||||
<label class="oh-label" for="{{form.document_request_id.id_for_label}}">{% trans "Document request" %}</label>
|
||||
{{form.document_request_id}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -32,6 +32,7 @@
|
||||
}
|
||||
</style>
|
||||
{% include 'documents/document_nav.html' %}
|
||||
|
||||
<div class="oh-checkpoint-badge mb-2" id="selectedDocuments" data-ids="[]" data-clicked="" style="display: none">
|
||||
{% trans "Selected Documents" %}
|
||||
</div>
|
||||
|
||||
@@ -440,6 +440,11 @@ urlpatterns = [
|
||||
document_request.DocumentRequestCreateForm.as_view(),
|
||||
name="document-request-create",
|
||||
),
|
||||
path(
|
||||
"document-request-nav-cbv/",
|
||||
document_request.DocumentRequestNav.as_view(),
|
||||
name="document-request-nav-cbv",
|
||||
),
|
||||
# path(
|
||||
# "document-request-create",
|
||||
# views.document_request_create,
|
||||
|
||||
Reference in New Issue
Block a user