mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-01 08:33:22 +02:00
116 lines
No EOL
6 KiB
Twig
116 lines
No EOL
6 KiB
Twig
<script src="/assets/js/tabulator.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 tldLinkFormatter(cell){
|
||
var displayName = cell.getValue();
|
||
var punycodeName = cell.getRow().getData().tld_o;
|
||
return `<a href="/registry/tld/${punycodeName}" style="font-weight:bold;">${displayName}</a>`;
|
||
}
|
||
|
||
function secureFormatter(cell) {
|
||
// Get the value of the 'secure' field
|
||
var secure = cell.getValue();
|
||
|
||
// Return appropriate SVG icon and text based on the secure value
|
||
return secure === 1 ?
|
||
`<svg xmlns="http://www.w3.org/2000/svg" class="icon me-1 text-success" 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> Signed` :
|
||
`<svg xmlns="http://www.w3.org/2000/svg" class="icon me-1 text-warning" 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="M18 6l-12 12" /><path d="M6 6l12 12" /></svg> Not signed`;
|
||
}
|
||
|
||
function actionsFormatter(cell, formatterParams, onRendered) {
|
||
return `<a class="btn btn-outline-info" href="/registry/tld/${cell.getRow().getData().tld_o}" title="Manage Settings"><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 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16l-3 -2l-2 2l-2 -2l-2 2l-2 -2l-3 2" /><path d="M14 8h-2.5a1.5 1.5 0 0 0 0 3h1a1.5 1.5 0 0 1 0 3h-2.5m2 0v1.5m0 -9v1.5" /></svg> Settings</a>`;
|
||
}
|
||
|
||
// Mapping of database string values to script names
|
||
const dbValueToScriptName = {
|
||
'/^(?!-)(?!.*--)[A-Z0-9-]{1,63}(?<!-)(.(?!-)(?!.*--)[A-Z0-9-]{1,63}(?<!-))*$/i': 'ASCII',
|
||
'/^[а-яА-ЯґҐєЄіІїЇѝЍћЋљЈ]+$/u': 'Cyrillic',
|
||
'/^[ぁ-んァ-ン一-龯々]+$/u': 'Japanese',
|
||
'/^[가-힣]+$/u': 'Korean',
|
||
};
|
||
|
||
const scriptNameToBadgeClass = {
|
||
'ASCII': 'bg-indigo-lt', // Blue badge for ASCII
|
||
'Cyrillic': 'bg-secondary-lt', // Grey badge for Cyrillic
|
||
'Japanese': 'bg-success-lt', // Green badge for Japanese
|
||
'Korean': 'bg-danger-lt', // Red badge for Korean
|
||
// Add more mappings as needed
|
||
'Unknown': 'bg-warning-lt' // Yellow badge for Unknown
|
||
};
|
||
|
||
function scriptNameFormatter(cell, formatterParams) {
|
||
const idnTableValue = cell.getValue();
|
||
const scriptName = dbValueToScriptName[idnTableValue] || 'Unknown';
|
||
const badgeClass = scriptNameToBadgeClass[scriptName];
|
||
|
||
// Return HTML string with Bootstrap badge
|
||
return `<span class="badge ${badgeClass}">${scriptName}</span>`;
|
||
}
|
||
|
||
table = new Tabulator("#tldTable", {
|
||
ajaxURL:"/api/records/domain_tld", // Set the URL for your JSON data
|
||
ajaxConfig:"GET",
|
||
pagination:"local",
|
||
paginationSize:10,
|
||
ajaxResponse:function(url, params, response){
|
||
return response.records;
|
||
},
|
||
layout:"fitDataFill",
|
||
responsiveLayout: "collapse",
|
||
responsiveLayoutCollapseStartOpen:false,
|
||
resizableColumns:false,
|
||
columns:[
|
||
{formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0},
|
||
{title:"TLD", field:"tld", width:350, minWidth:50, headerSort:true, resizable:false, formatter: tldLinkFormatter, responsive:0},
|
||
{ title: "{{ __('Script') }}", field: "idn_table", width:250, minWidth:80, headerSort:true, resizable:false, formatter: scriptNameFormatter, responsive:2},
|
||
{title:"DNSSEC", field:"secure", width:250, minWidth:80, headerSort:true, resizable:false, formatter: secureFormatter, responsive:2},
|
||
{title: "{{ __('Actions') }}", formatter: actionsFormatter, headerSort: false, resizable:false, download:false, hozAlign: "center", responsive:0, cellClick:function(e, cell){ e.stopPropagation(); }},
|
||
],
|
||
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 () {
|
||
var term = searchInput.value.toLowerCase();
|
||
|
||
if (term) { // Only apply the filter when there's a term to search for
|
||
table.setFilter(function (data) {
|
||
// Check if any of the fields contain the search term
|
||
return (
|
||
String(data.tld).toLowerCase().includes(term) ||
|
||
String(data.secure).toLowerCase().includes(term)
|
||
);
|
||
});
|
||
} else {
|
||
table.clearFilter(); // Clear the filter when the search box is emptied
|
||
}
|
||
});
|
||
});
|
||
|
||
function downloadCSV() {
|
||
table.download("csv", "data.csv");
|
||
}
|
||
|
||
function downloadJSON() {
|
||
table.download("json", "data.json");
|
||
}
|
||
|
||
function downloadXLSX() {
|
||
table.download("xlsx", "data.xlsx", {sheetName:"My TLDs"});
|
||
}
|
||
|
||
function downloadPDF() {
|
||
table.download("pdf", "data.pdf", {
|
||
orientation:"portrait",
|
||
title:"My TLDs",
|
||
jsPDF:{unit:"mm", format:"a4", orientation:"p"}
|
||
});
|
||
}
|
||
</script> |