[UPDT] DOCUMENTS: Added confirmation to approve reject and bulk action and made reject reason form field as required
This commit is contained in:
@@ -184,17 +184,6 @@
|
||||
style="display: none"
|
||||
>
|
||||
<ul class="oh-dropdown__items">
|
||||
{% if perms.base.view_shiftrequest %}
|
||||
<li class="oh-dropdown__item">
|
||||
<a
|
||||
href="#"
|
||||
class="oh-dropdown__link"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#shiftRequestsExport"
|
||||
>{% trans "Export" %}</a
|
||||
>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if perms.horilla_documnets.change_documentrequest or request.user|is_reportingmanager %}
|
||||
|
||||
<li class="oh-dropdown__item">
|
||||
@@ -206,8 +195,8 @@
|
||||
{% if perms.base.change_shiftrequest or request.user|is_reportingmanager %}
|
||||
|
||||
<li class="oh-dropdown__item">
|
||||
<a class="oh-dropdown__link mb-2 " data-toggle="oh-modal-toggle" style="cursor: pointer;"
|
||||
data-target="#BulkRejectModal"
|
||||
<a class="oh-dropdown__link mb-2 " style="cursor: pointer;"
|
||||
id="BulkRejectDocument"
|
||||
>{% trans "Bulk Reject Requests" %}</a
|
||||
>
|
||||
</li>
|
||||
@@ -290,10 +279,9 @@
|
||||
</div>
|
||||
<div class="oh-modal__dialog-body" id="BulkRejectForm">
|
||||
<form id="bulk-reject-form">
|
||||
<textarea name="rejection_reason" cols="40" rows="2" class="oh-input w-100" placeholder="Rejection reason" id="bulk_rejection_reason"></textarea>
|
||||
|
||||
<textarea name="rejection_reason" cols="40" rows="2" class="oh-input w-100" placeholder="Rejection reason" id="bulk_rejection_reason" required></textarea>
|
||||
<div class="d-flex flex-row-reverse w-100 align-items-center mt-4">
|
||||
<button type="button" class="oh-btn oh-btn--secondary oh-btn--shadow bulk_reject">
|
||||
<button type="submit" class="oh-btn oh-btn--secondary oh-btn--shadow bulk_reject">
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -46,56 +46,134 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
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.",
|
||||
};
|
||||
var approveMessages = {
|
||||
ar: "هل ترغب حقًا في الموافقة على جميع الطلبات المحددة؟",
|
||||
de: "Möchten Sie wirklich alle ausgewählten Anfragen genehmigen?",
|
||||
es: "Realmente quieres aprobar todas las solicitudes seleccionadas?",
|
||||
en: "Do you really want to approve all the selected requests?",
|
||||
fr: "Voulez-vous vraiment approuver toutes les demandes sélectionnées?",
|
||||
};
|
||||
var rejectMessages = {
|
||||
ar: "هل تريد حقًا رفض جميع الطلبات المحددة؟",
|
||||
de: "Möchten Sie wirklich alle ausgewählten Anfragen ablehnen?",
|
||||
es: "¿Realmente deseas rechazar todas las solicitudes seleccionadas?",
|
||||
en: "Do you really want to reject all the selected requests?",
|
||||
fr: "Voulez-vous vraiment rejeter toutes les demandes sélectionnées?",
|
||||
};
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".bulk_approve").on("click", function () {
|
||||
checkedRows = $("[type=checkbox]:checked");
|
||||
ids = [];
|
||||
checkedRows.each(function () {
|
||||
if($(this).attr("id") != ""){
|
||||
ids.push($(this).attr("id"));
|
||||
var languageCode = null;
|
||||
getCurrentLanguageCode(function (code) {
|
||||
languageCode = code;
|
||||
var confirmMessage = approveMessages[languageCode];
|
||||
var textMessage = norowMessages[languageCode];
|
||||
checkedRows = $("[type=checkbox]:checked");
|
||||
ids = [];
|
||||
checkedRows.each(function () {
|
||||
if($(this).attr("id") != ""){
|
||||
ids.push($(this).attr("id"));
|
||||
}
|
||||
});
|
||||
if (ids.length === 0) {
|
||||
Swal.fire({
|
||||
text: textMessage,
|
||||
icon: "warning",
|
||||
confirmButtonText: "Close",
|
||||
});
|
||||
} else {
|
||||
// Use SweetAlert for the confirmation dialog
|
||||
Swal.fire({
|
||||
text: confirmMessage,
|
||||
icon: "success",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#008000",
|
||||
cancelButtonColor: "#d33",
|
||||
confirmButtonText: "Confirm",
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "{% url 'document-bulk-approve' %}",
|
||||
data: {
|
||||
"ids": ids,
|
||||
},
|
||||
traditional:true,
|
||||
success: function () {
|
||||
window.location.reload()
|
||||
|
||||
},
|
||||
error: function () {
|
||||
console.log("Error");
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "{% url 'document-bulk-approve' %}",
|
||||
data: {
|
||||
"ids": ids,
|
||||
},
|
||||
traditional:true,
|
||||
success: function () {
|
||||
window.location.reload()
|
||||
|
||||
},
|
||||
error: function () {
|
||||
console.log("Error");
|
||||
},
|
||||
});
|
||||
})
|
||||
});
|
||||
$(".bulk_reject").on("click", function () {
|
||||
checkedRows = $("[type=checkbox]:checked");
|
||||
reason = $("#bulk_rejection_reason").val()
|
||||
ids = [];
|
||||
checkedRows.each(function () {
|
||||
if($(this).attr("id") != ""){
|
||||
ids.push($(this).attr("id"));
|
||||
$("#BulkRejectDocument").on("click", function () {
|
||||
var languageCode = null;
|
||||
getCurrentLanguageCode(function (code) {
|
||||
languageCode = code;
|
||||
var rejectMessage = rejectMessages[languageCode];
|
||||
var textMessage = norowMessages[languageCode];
|
||||
checkedRows = $("[type=checkbox]:checked");
|
||||
reason = $("#bulk_rejection_reason").val()
|
||||
ids = [];
|
||||
checkedRows.each(function () {
|
||||
if($(this).attr("id") != ""){
|
||||
ids.push($(this).attr("id"));
|
||||
}
|
||||
});
|
||||
if (ids.length === 0) {
|
||||
Swal.fire({
|
||||
text: textMessage,
|
||||
icon: "warning",
|
||||
confirmButtonText: "Close",
|
||||
});
|
||||
} else {
|
||||
$("#BulkRejectModal").addClass("oh-modal--show");
|
||||
$(".bulk-reject-form").on("submit", function(){
|
||||
event.preventDefault()
|
||||
Swal.fire({
|
||||
text: rejectMessage,
|
||||
icon: "info",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#008000",
|
||||
cancelButtonColor: "#d33",
|
||||
confirmButtonText: "Confirm",
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'document-bulk-reject' %}",
|
||||
data: {
|
||||
"ids": ids,
|
||||
"reason": reason,
|
||||
csrfmiddlewaretoken: getCookie("csrftoken"),
|
||||
},
|
||||
traditional:true,
|
||||
success: function () {
|
||||
window.location.reload()
|
||||
},
|
||||
error: function () {
|
||||
console.log("Error");
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'document-bulk-reject' %}",
|
||||
data: {
|
||||
"ids": ids,
|
||||
"reason": reason,
|
||||
csrfmiddlewaretoken: getCookie("csrftoken"),
|
||||
},
|
||||
traditional:true,
|
||||
success: function () {
|
||||
window.location.reload()
|
||||
},
|
||||
error: function () {
|
||||
console.log("Error");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(".select_all").on("change", function(){
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
|
||||
|
||||
<div class="oh-accordion-meta__actions" onclick="event.stopPropagation()">
|
||||
<div class="oh-dropdown" x-data="{open: false}">
|
||||
<button class="oh-btn oh-stop-prop oh-accordion-meta__btn" @click="open = !open" @click.outside="open = false" title="Action">
|
||||
@@ -102,7 +102,7 @@
|
||||
<ion-icon class="ms-2 oh-accordion-meta__btn-icon md hydrated" name="caret-down-outline" role="img" aria-label="caret down outline"></ion-icon>
|
||||
</button>
|
||||
<div class="oh-dropdown__menu oh-dropdown__menu--right" x-show="open" style="display: none;">
|
||||
<ul class="oh-dropdown__items">
|
||||
<ul class="oh-dropdown__items">
|
||||
<li class="oh-dropdown__item">
|
||||
<a class="oh-dropdown__link"
|
||||
data-toggle="oh-modal-toggle"
|
||||
@@ -159,16 +159,16 @@
|
||||
class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round ms-2 mr-2 file-upload"
|
||||
title="{% trans 'Rejected' %}"
|
||||
>
|
||||
<ion-icon name="alert"></ion-icon>
|
||||
<ion-icon name="alert"></ion-icon>
|
||||
</span>
|
||||
{% else %}
|
||||
<span
|
||||
class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round ms-2 mr-2 file-upload"
|
||||
title="{% trans 'File Uploaded' %}"
|
||||
>
|
||||
<ion-icon name="image-outline"></ion-icon>
|
||||
<ion-icon name="image-outline"></ion-icon>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span
|
||||
class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round ms-2 mr-2 file-upload"
|
||||
@@ -210,6 +210,7 @@
|
||||
{% else %}
|
||||
<a
|
||||
type="submit"
|
||||
hx-confirm="{% trans 'Do you want to approve this request' %}"
|
||||
hx-get="{% url 'document-approve' document.id %}"
|
||||
hx-target="#viewFile"
|
||||
title="{% trans 'Approve' %}"
|
||||
@@ -223,7 +224,7 @@
|
||||
<a class="oh-btn oh-btn--danger w-100 oh-btn--disabled" onclick="event.stopPropagation()">
|
||||
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
{% else %}
|
||||
<a
|
||||
type="submit"
|
||||
hx-get="{% url 'document-reject' document.id %}"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{% load i18n %}
|
||||
<form
|
||||
id="file-form"
|
||||
hx-confirm="{% trans 'Do you want to reject this request' %}"
|
||||
hx-post="{% url 'document-reject' document_obj.id %}"
|
||||
hx-target="#uploadFileForm"
|
||||
hx-encoding="multipart/form-data"
|
||||
|
||||
@@ -97,3 +97,7 @@ class DocumentRejectForm(ModelForm):
|
||||
class Meta:
|
||||
model = Document
|
||||
fields = ["reject_reason"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["reject_reason"].widget.attrs["required"]=True
|
||||
|
||||
Reference in New Issue
Block a user