mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-30 22:36:18 +02:00
205 lines
No EOL
12 KiB
Twig
205 lines
No EOL
12 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="/assets/js/xlsx.full.min.js" defer></script>
|
|
<script src="/assets/js/jspdf.umd.min.js" defer></script>
|
|
<script src="/assets/js/jspdf.plugin.autotable.min.js" defer></script>
|
|
<script>
|
|
var table;
|
|
|
|
document.addEventListener("DOMContentLoaded", function(){
|
|
function domainLinkFormatter(cell){
|
|
var displayName = cell.getValue();
|
|
var punycodeName = cell.getRow().getData().name_o;
|
|
return `<a href="/domain/view/${punycodeName}" style="font-weight:bold;">${displayName}</a>`;
|
|
}
|
|
|
|
function actionsFormatter(cell, formatterParams, onRendered) {
|
|
var rowData = cell.getRow().getData();
|
|
var actionButtons = '';
|
|
|
|
var hasPendingDelete = rowData.domain_status.some(statusObj => statusObj.status && statusObj.status.includes('pendingDelete'));
|
|
var hasPendingRestore = rowData.rgpstatus ? rowData.rgpstatus.includes('pendingRestore') : false;
|
|
|
|
// Common action button for all statuses
|
|
actionButtons += `<a class="btn btn-outline-primary btn-icon" href="domain/update/${cell.getRow().getData().name_o}" title="{{ __('Update Domain') }}"><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> `;
|
|
|
|
if (hasPendingRestore) {
|
|
actionButtons += `<a class="btn btn-outline-secondary btn-icon report-btn" id="report-btn" href="javascript:void(0);" data-report-url="domain/report/${cell.getRow().getData().name_o}" title="{{ __('Submit Report') }}"><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="M3.06 13a9 9 0 1 0 .49 -4.087" /><path d="M3 4.001v5h5" /><path d="M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /></svg></a>`;
|
|
} else if (hasPendingDelete) {
|
|
actionButtons += `<a class="btn btn-outline-warning btn-icon restore-btn" id="restore-btn" href="javascript:void(0);" data-restore-url="domain/restore/${cell.getRow().getData().name_o}" title="{{ __('Restore Domain') }}"><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="M15 4.55a8 8 0 0 0 -6 14.9m0 -4.45v5h-5" /><path d="M18.37 7.16l0 .01" /><path d="M13 19.94l0 .01" /><path d="M16.84 18.37l0 .01" /><path d="M19.37 15.1l0 .01" /><path d="M19.94 11l0 .01" /></svg></a>`;
|
|
} else {
|
|
actionButtons += `<a class="btn btn-outline-success btn-icon" href="domain/renew/${cell.getRow().getData().name_o}" title="{{ __('Renew Domain') }}"><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="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4"></path><path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"></path></svg></a> `;
|
|
actionButtons += `<a class="btn btn-outline-danger btn-icon delete-btn" id="delete-btn" href="javascript:void(0);" data-delete-url="domain/delete/${cell.getRow().getData().name_o}" title="{{ __('Delete Domain') }}"><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>`;
|
|
}
|
|
|
|
return actionButtons;
|
|
}
|
|
|
|
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="status status-${badgeClass}">${text}</span>`;
|
|
}
|
|
|
|
// Check if statusArray is empty or not
|
|
if (statusArray && Array.isArray(statusArray) && statusArray.length > 0) {
|
|
return statusArray.map(item => createBadge(item.status, 'green')).join(' ');
|
|
} else if (rowData.rgpstatus) {
|
|
// Fallback to rgpstatus column if statusArray is empty
|
|
return createBadge(rowData.rgpstatus, 'info');
|
|
} else {
|
|
// Display 'ok' status with info badge if both statusArray and rgpstatus are empty
|
|
return createBadge('ok', 'info');
|
|
}
|
|
}
|
|
|
|
var searchTerm = ""; // global variable to hold the search term
|
|
|
|
function updateSearchTerm(term) {
|
|
searchTerm = term;
|
|
table.replaceData();
|
|
}
|
|
|
|
table = new Tabulator("#domainTable", {
|
|
pagination: true,
|
|
paginationMode: "remote",
|
|
paginationSize: 10,
|
|
paginationSizeSelector:[10, 25, 50, 100],
|
|
paginationCounter:"rows",
|
|
paginationCounterElement:"#page-count",
|
|
clipboard:true,
|
|
clipboardPasteAction:"replace",
|
|
printAsHtml:true,
|
|
sortMode: "remote",
|
|
ajaxURL: "/dapi/domains",
|
|
ajaxURLGenerator: function(url, config, params) {
|
|
var queryParts = [];
|
|
|
|
// Handle search term
|
|
if (searchTerm) {
|
|
queryParts.push("filter1=name,cs," + encodeURIComponent(searchTerm));
|
|
queryParts.push("filter2=crdate,cs," + encodeURIComponent(searchTerm));
|
|
queryParts.push("filter3=exdate,cs," + encodeURIComponent(searchTerm));
|
|
queryParts.push("filter4=registrant_identifier,cs," + encodeURIComponent(searchTerm));
|
|
queryParts.push("filter5=name_o,cs," + encodeURIComponent(searchTerm));
|
|
}
|
|
|
|
// Handle sorting from Tabulator
|
|
if (params.sort && params.sort.length > 0) {
|
|
var sorter = params.sort[0]; // single-column sorting
|
|
var sortField = encodeURIComponent(sorter.field);
|
|
var sortDir = (sorter.dir === "asc" ? "asc" : "desc");
|
|
queryParts.push("order=" + sortField + "," + sortDir);
|
|
} else {
|
|
// fallback default order if no sorters
|
|
queryParts.push("order=crdate,desc");
|
|
}
|
|
|
|
// 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 pageSize = params.size || this.options.paginationSize;
|
|
var lastPage = Math.ceil(response.results / pageSize);
|
|
return {
|
|
last_page: lastPage,
|
|
last_row: response.results,
|
|
data: response.records,
|
|
};
|
|
} else {
|
|
console.error('Unexpected response format', response);
|
|
return { last_page: 1, last_row: 0, data: [] };
|
|
}
|
|
},
|
|
layout:"fitColumns",
|
|
responsiveLayout: "collapse",
|
|
responsiveLayoutCollapseStartOpen:false,
|
|
resizableColumns:false,
|
|
placeholder: "{{ __('No Data') }}",
|
|
columns:[
|
|
{formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0},
|
|
{title:"{{ __('Name') }}", field:"name", minWidth:180, resizable:false, headerSort:true, formatter: domainLinkFormatter, responsive:0},
|
|
{title:"{{ __('Registrant') }}", minWidth:200, field:"registrant_identifier", resizable:false, headerSort:true, responsive:2},
|
|
{title:"{{ __('Creation Date') }}", width:250, minWidth:150, field:"crdate", resizable:false, headerSort:true, responsive:2},
|
|
{title:"{{ __('Expiration Date') }}", width:250, minWidth:150, field:"exdate", resizable:false, headerSort:true, responsive:2},
|
|
{title:"{{ __('Status') }}", width:150, field:"domain_status", formatter: statusFormatter, resizable:false, headerSort:true, download:false, responsive:2},
|
|
{title: "{{ __('Actions') }}", formatter: actionsFormatter, resizable:false, 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 domain?') }}",
|
|
showCancelButton: true,
|
|
confirmButtonText: "{{ __('Confirm') }}"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
let deleteUrl = e.target.closest('.delete-btn').getAttribute('data-delete-url');
|
|
window.location.href = deleteUrl;
|
|
}
|
|
});
|
|
} else if (e.target.closest('.restore-btn')) {
|
|
e.preventDefault(); // Prevent the default link behavior
|
|
Swal.fire({
|
|
title: "{{ __('Are you sure you want to restore this domain?') }}",
|
|
showCancelButton: true,
|
|
confirmButtonText: "{{ __('Confirm') }}"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
let restoreUrl = e.target.closest('.restore-btn').getAttribute('data-restore-url');
|
|
window.location.href = restoreUrl;
|
|
}
|
|
});
|
|
} else if (e.target.closest('.report-btn')) {
|
|
e.preventDefault(); // Prevent the default link behavior
|
|
Swal.fire({
|
|
title: "{{ __('Are you sure you want to submit restore report for this domain?') }}",
|
|
showCancelButton: true,
|
|
confirmButtonText: "{{ __('Confirm') }}"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
let reportUrl = e.target.closest('.report-btn').getAttribute('data-report-url');
|
|
window.location.href = reportUrl;
|
|
}
|
|
});
|
|
}
|
|
}},
|
|
]
|
|
});
|
|
var searchInput = document.getElementById("search-input");
|
|
let searchTimeout;
|
|
|
|
searchInput.addEventListener("input", function () {
|
|
clearTimeout(searchTimeout);
|
|
searchTimeout = setTimeout(() => {
|
|
updateSearchTerm(searchInput.value);
|
|
}, 300); // 300ms delay
|
|
});
|
|
});
|
|
|
|
function downloadCSV() {
|
|
table.download("csv", "domains.csv");
|
|
}
|
|
|
|
function downloadJSON() {
|
|
table.download("json", "domains.json");
|
|
}
|
|
|
|
function downloadXLSX() {
|
|
table.download("xlsx", "domains.xlsx", {sheetName:"My Domains"});
|
|
}
|
|
|
|
function downloadPDF() {
|
|
table.download("pdf", "domains.pdf", {
|
|
orientation:"portrait",
|
|
title:"My Domains"
|
|
});
|
|
}
|
|
</script> |