mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-01 16:43:26 +02:00
168 lines
No EOL
9.3 KiB
Twig
168 lines
No EOL
9.3 KiB
Twig
<script src="/assets/js/tabulator.min.js" defer></script>
|
|
<script src="/assets/js/sweetalert2.min.js" defer></script>
|
|
<script src="/assets/js/tabler.min.js" defer></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.6.0/jspdf.plugin.autotable.min.js"></script>
|
|
<script>
|
|
var table;
|
|
|
|
document.addEventListener("DOMContentLoaded", function(){
|
|
function domainLinkFormatter(cell){
|
|
var value = cell.getValue();
|
|
return `<a href="/application/view/${value}" style="font-weight:bold;">${value}</a>`;
|
|
}
|
|
|
|
function actionsFormatter(cell, formatterParams, onRendered) {
|
|
var rowData = cell.getRow().getData();
|
|
var actionButtons = '';
|
|
|
|
var isRejected = rowData.application_status.some(statusObj => statusObj.status && statusObj.status.includes('rejected'));
|
|
var isInvalid = rowData.application_status.some(statusObj => statusObj.status && statusObj.status.includes('invalid'));
|
|
|
|
if (!isRejected && !isInvalid) {
|
|
actionButtons += `<a class="btn btn-outline-green btn-icon" href="application/approve/${cell.getRow().getData().name}" title="Approve Application"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" /></svg></a> `;
|
|
actionButtons += `<a class="btn btn-outline-warning btn-icon" href="application/reject/${cell.getRow().getData().name}" title="Reject Application"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" /><path d="M5.7 5.7l12.6 12.6" /></svg></a> `;
|
|
actionButtons += `<a class="btn btn-outline-info btn-icon" href="application/update/${cell.getRow().getData().name}" title="Update Application"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></a> `;
|
|
actionButtons += `<a class="btn btn-outline-danger btn-icon delete-btn" id="delete-btn" href="javascript:void(0);" data-delete-url="application/delete/${cell.getRow().getData().name}" title="Delete Application"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M4 7h16"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"></path><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path><path d="M10 12l4 4m0 -4l-4 4"></path></svg></a>`;
|
|
} else {
|
|
actionButtons += `<strong class="text-success"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" /><path d="M9 12l2 2l4 -4" /></svg> Completed</strong>`;
|
|
}
|
|
|
|
return actionButtons;
|
|
}
|
|
|
|
function phaseFormatter(cell) {
|
|
var statusArray = cell.getValue();
|
|
var rowData = cell.getRow().getData(); // Get the entire row data
|
|
|
|
// Function to create a badge
|
|
function createBadge(text, badgeClass) {
|
|
return `<span class="status status-${badgeClass}">${text}</span>`;
|
|
}
|
|
|
|
// Check if statusArray is empty or not
|
|
return createBadge(statusArray, 'info');
|
|
}
|
|
|
|
function statusFormatter(cell) {
|
|
var statusArray = cell.getValue();
|
|
var rowData = cell.getRow().getData(); // Get the entire row data
|
|
|
|
// Function to create a badge
|
|
function createBadge(text, badgeClass) {
|
|
return `<span class="badge bg-${badgeClass}-lt">${text}</span>`;
|
|
}
|
|
|
|
// Check if statusArray is empty or not
|
|
if (statusArray && Array.isArray(statusArray) && statusArray.length > 0) {
|
|
return statusArray.map(item => createBadge(item.status, 'lime')).join(' ');
|
|
}
|
|
}
|
|
|
|
var searchTerm = ""; // global variable to hold the search term
|
|
|
|
function updateSearchTerm(term) {
|
|
searchTerm = term;
|
|
table.replaceData();
|
|
}
|
|
|
|
table = new Tabulator("#applicationTable", {
|
|
pagination: true,
|
|
paginationMode: "remote",
|
|
paginationSize: 10,
|
|
ajaxURL: "/api/records/application",
|
|
ajaxParams: {
|
|
join: "contact",
|
|
join: "application_status"
|
|
},
|
|
ajaxURLGenerator: function(url, config, params) {
|
|
var queryParts = ["join=contact", "join=application_status"];
|
|
|
|
// Handle search term
|
|
if (searchTerm) {
|
|
queryParts.push("filter1=name,cs," + encodeURIComponent(searchTerm));
|
|
queryParts.push("filter2=crdate,cs," + encodeURIComponent(searchTerm));
|
|
}
|
|
|
|
queryParts.push("order=id");
|
|
|
|
// Include pagination parameters
|
|
if (params.page) {
|
|
queryParts.push("page=" + params.page + "," + params.size);
|
|
}
|
|
|
|
return url + "?" + queryParts.join("&");
|
|
},
|
|
ajaxResponse: function(url, params, response) {
|
|
if (response && Array.isArray(response.records) && typeof response.results === 'number') {
|
|
var lastPage = Math.ceil(response.results / this.options.paginationSize);
|
|
return {
|
|
last_page: lastPage, // Calculated total number of pages
|
|
data: response.records, // Data for the current page
|
|
};
|
|
} else {
|
|
console.error('Unexpected response format', response);
|
|
return { last_page: 1, data: [] };
|
|
}
|
|
},
|
|
dataReceiveParams: {
|
|
"last_page": "results", // Mapping 'results' to 'last_page'
|
|
},
|
|
layout:"fitDataFill",
|
|
responsiveLayout: "collapse",
|
|
responsiveLayoutCollapseStartOpen:false,
|
|
resizableColumns:false,
|
|
columns:[
|
|
{formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0},
|
|
{title:"{{ __('Name') }}", field:"name", width:250, headerSort:false, formatter: domainLinkFormatter, responsive:0},
|
|
{title:"{{ __('Applicant') }}", width:150, field:"registrant.identifier", headerSort:false, responsive:2},
|
|
{title:"{{ __('Creation Date') }}", width:250, minWidth:150, field:"crdate", headerSort:false, responsive:2},
|
|
{title:"{{ __('Phase') }}", width:150, minWidth:100, field:"phase_type", formatter: phaseFormatter, headerSort:false, responsive:2},
|
|
{title:"{{ __('Status') }}", width:200, field:"application_status", formatter: statusFormatter, headerSort:false, download:false, responsive:2},
|
|
{title: "{{ __('Actions') }}", formatter: actionsFormatter, headerSort: false, download:false, hozAlign: "center", responsive:0, cellClick: function(e, cell){
|
|
if (e.target.closest('.delete-btn')) {
|
|
e.preventDefault(); // Prevent the default link behavior
|
|
Swal.fire({
|
|
title: "{{ __('Are you sure you want to delete this application?') }}",
|
|
showCancelButton: true,
|
|
confirmButtonText: "{{ __('Confirm') }}"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
let deleteUrl = e.target.closest('.delete-btn').getAttribute('data-delete-url');
|
|
window.location.href = deleteUrl;
|
|
}
|
|
});
|
|
}
|
|
}},
|
|
],
|
|
placeholder:function(){
|
|
return this.getHeaderFilters().length ? "No Matching Data" : "{{ __('No Data') }}"; //set placeholder based on if there are currently any header filters
|
|
}
|
|
});
|
|
var searchInput = document.getElementById("search-input");
|
|
searchInput.addEventListener("input", function () {
|
|
updateSearchTerm(searchInput.value);
|
|
});
|
|
});
|
|
|
|
function downloadCSV() {
|
|
table.download("csv", "data.csv");
|
|
}
|
|
|
|
function downloadJSON() {
|
|
table.download("json", "data.json");
|
|
}
|
|
|
|
function downloadXLSX() {
|
|
table.download("xlsx", "data.xlsx", {sheetName:"My Applications"});
|
|
}
|
|
|
|
function downloadPDF() {
|
|
table.download("pdf", "data.pdf", {
|
|
orientation:"portrait",
|
|
title:"My Applications",
|
|
jsPDF:{unit:"mm", format:"a4", orientation:"p"}
|
|
});
|
|
}
|
|
</script> |