324 lines
11 KiB
JavaScript
324 lines
11 KiB
JavaScript
tickShiftCheckboxes();
|
|
function makeShiftListUnique(list) {
|
|
return Array.from(new Set(list));
|
|
}
|
|
|
|
tickWorktypeCheckboxes();
|
|
function makeWorktypeListUnique(list) {
|
|
return Array.from(new Set(list));
|
|
}
|
|
|
|
tickRShiftCheckboxes();
|
|
function makeRShiftListUnique(list) {
|
|
return Array.from(new Set(list));
|
|
}
|
|
|
|
tickRWorktypeCheckboxes();
|
|
function makeRWorktypeListUnique(list) {
|
|
return Array.from(new Set(list));
|
|
}
|
|
|
|
function getCookie(name) {
|
|
let cookieValue = null;
|
|
if (document.cookie && document.cookie !== "") {
|
|
const cookies = document.cookie.split(";");
|
|
for (let i = 0; i < cookies.length; i++) {
|
|
const cookie = cookies[i].trim();
|
|
// Does this cookie string begin with the name we want?
|
|
if (cookie.substring(0, name.length + 1) === name + "=") {
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return cookieValue;
|
|
}
|
|
|
|
|
|
function shiftRequestApprove() {
|
|
|
|
|
|
|
|
ids = [];
|
|
// function addIdsTab(tabId){
|
|
// var dataIds = $("#"+tabId).attr("data-ids");
|
|
// if (dataIds){
|
|
// ids = ids.concat(JSON.parse(dataIds));
|
|
// }
|
|
// }
|
|
// addIdsTab("shiftselectedInstances");
|
|
// addIdsTab("allocatedselectedInstances");
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
if (ids.length === 0) {
|
|
Swal.fire({
|
|
text: i18nMessages.noRowsSelected,
|
|
icon: "warning",
|
|
confirmButtonText: i18nMessages.close,
|
|
});
|
|
} else {
|
|
// Use SweetAlert for the confirmation dialog
|
|
Swal.fire({
|
|
text: i18nMessages.confirmBulkApprove,
|
|
icon: "success",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#008000",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: i18nMessages.confirm,
|
|
cancelButtonText: i18nMessages.cancel,
|
|
}).then(function (result) {
|
|
if (result.isConfirmed) {
|
|
// ids = [];
|
|
// ids.push($("#selectedInstances").attr("data-ids"));
|
|
// ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/shift-request-bulk-approve",
|
|
data: {
|
|
csrfmiddlewaretoken: getCookie("csrftoken"),
|
|
ids: JSON.stringify(ids),
|
|
},
|
|
success: function (response, textStatus, jqXHR) {
|
|
if (jqXHR.status === 200) {
|
|
location.reload(); // Reload the current page
|
|
} else {
|
|
// console.log("Unexpected HTTP status:", jqXHR.status);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function shiftRequestReject() {
|
|
ids = [];
|
|
// function addIdsTab(tabId){
|
|
// var dataIds = $("#"+tabId).attr("data-ids");
|
|
// if (dataIds){
|
|
// ids = ids.concat(JSON.parse(dataIds));
|
|
// }
|
|
// }
|
|
// addIdsTab("shiftselectedInstances");
|
|
// addIdsTab("allocatedselectedInstances");
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
if (ids.length === 0) {
|
|
Swal.fire({
|
|
text: i18nMessages.noRowsSelected,
|
|
icon: "warning",
|
|
confirmButtonText: i18nMessages.close,
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
text: i18nMessages.confirmBulkReject,
|
|
icon: "info",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#008000",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: i18nMessages.confirm,
|
|
cancelButtonText: i18nMessages.cancel,
|
|
}).then(function (result) {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/shift-request-bulk-cancel",
|
|
data: {
|
|
csrfmiddlewaretoken: getCookie("csrftoken"),
|
|
ids: JSON.stringify(ids),
|
|
},
|
|
success: function (response, textStatus, jqXHR) {
|
|
if (jqXHR.status === 200) {
|
|
location.reload(); // Reload the current page
|
|
} else {
|
|
// console.log("Unexpected HTTP status:", jqXHR.status);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function shiftRequestDelete() {
|
|
ids = [];
|
|
// function addIdsTab(tabId){
|
|
// var dataIds = $("#"+tabId).attr("data-ids");
|
|
// if (dataIds){
|
|
// ids = ids.concat(JSON.parse(dataIds));
|
|
// }
|
|
// }
|
|
// addIdsTab("shiftselectedInstances");
|
|
// addIdsTab("allocatedselectedInstances");
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
if (ids.length === 0) {
|
|
Swal.fire({
|
|
text: i18nMessages.noRowsSelected,
|
|
icon: "warning",
|
|
confirmButtonText: i18nMessages.close,
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
text: i18nMessages.confirmBulkDelete,
|
|
icon: "error",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#008000",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: i18nMessages.confirm,
|
|
cancelButtonText: i18nMessages.cancel,
|
|
}).then(function (result) {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/shift-request-bulk-delete",
|
|
data: {
|
|
csrfmiddlewaretoken: getCookie("csrftoken"),
|
|
ids: JSON.stringify(ids),
|
|
},
|
|
success: function (response, textStatus, jqXHR) {
|
|
if (jqXHR.status === 200) {
|
|
location.reload(); // Reload the current page
|
|
} else {
|
|
// console.log("Unexpected HTTP status:", jqXHR.status);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
function archiveRotateShift() {
|
|
ids = [];
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
if (ids.length === 0) {
|
|
Swal.fire({
|
|
text: i18nMessages.noRowsSelected,
|
|
icon: "warning",
|
|
confirmButtonText: i18nMessages.close,
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
text: i18nMessages.confirmBulkArchive,
|
|
icon: "info",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#008000",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: i18nMessages.confirm,
|
|
cancelButtonText: i18nMessages.cancel,
|
|
}).then(function (result) {
|
|
if (result.isConfirmed) {
|
|
ids = [];
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/rotating-shift-assign-bulk-archive?is_active=False",
|
|
data: {
|
|
csrfmiddlewaretoken: getCookie("csrftoken"),
|
|
ids: JSON.stringify(ids),
|
|
},
|
|
success: function (response, textStatus, jqXHR) {
|
|
if (jqXHR.status === 200) {
|
|
location.reload(); // Reload the current page
|
|
} else {
|
|
// console.log("Unexpected HTTP status:", jqXHR.status);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
function un_archiveRotateShift() {
|
|
ids = [];
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
if (ids.length === 0) {
|
|
Swal.fire({
|
|
text: i18nMessages.noRowsSelected,
|
|
icon: "warning",
|
|
confirmButtonText: i18nMessages.close,
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
text: i18nMessages.confirmBulkUnArchive,
|
|
icon: "info",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#008000",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: i18nMessages.confirm,
|
|
cancelButtonText: i18nMessages.cancel,
|
|
}).then(function (result) {
|
|
if (result.isConfirmed) {
|
|
ids = [];
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/rotating-shift-assign-bulk-archive?is_active=True",
|
|
data: {
|
|
csrfmiddlewaretoken: getCookie("csrftoken"),
|
|
ids: JSON.stringify(ids),
|
|
},
|
|
success: function (response, textStatus, jqXHR) {
|
|
if (jqXHR.status === 200) {
|
|
location.reload(); // Reload the current page
|
|
} else {
|
|
// console.log("Unexpected HTTP status:", jqXHR.status);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
function deleteRotatingShift() {
|
|
ids = [];
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
if (ids.length === 0) {
|
|
Swal.fire({
|
|
text: i18nMessages.noRowsSelected,
|
|
icon: "warning",
|
|
confirmButtonText: i18nMessages.close,
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
text: i18nMessages.confirmBulkDelete,
|
|
icon: "error",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#008000",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: i18nMessages.confirm,
|
|
cancelButtonText: i18nMessages.cancel,
|
|
}).then(function (result) {
|
|
if (result.isConfirmed) {
|
|
ids = [];
|
|
ids.push($("#selectedInstances").attr("data-ids"));
|
|
ids = JSON.parse($("#selectedInstances").attr("data-ids"));
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/rotating-shift-assign-bulk-delete",
|
|
data: {
|
|
csrfmiddlewaretoken: getCookie("csrftoken"),
|
|
ids: JSON.stringify(ids),
|
|
},
|
|
success: function (response, textStatus, jqXHR) {
|
|
if (jqXHR.status === 200) {
|
|
location.reload(); // Reload the current page
|
|
} else {
|
|
// console.log("Unexpected HTTP status:", jqXHR.status);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|
|
};
|