mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-30 22:36:18 +02:00
118 lines
No EOL
6.9 KiB
Twig
118 lines
No EOL
6.9 KiB
Twig
<script src="/assets/js/tabulator.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 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-icon 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="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 10h3v-3l-3.5 -3.5a6 6 0 0 1 8 8l6 6a2 2 0 0 1 -3 3l-6 -6a6 6 0 0 1 -8 -8l3.5 3.5" /></svg></a> <a class="btn btn-icon btn-outline-secondary" href="/registry/reserved" title="{{ __('Manage Reserved Names') }}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 6l11 0" /><path d="M9 12l11 0" /><path d="M9 18l11 0" /><path d="M5 6l0 .01" /><path d="M5 12l0 .01" /><path d="M5 18l0 .01" /></svg></a> <a class="btn btn-icon btn-outline-dark" href="/registry/tokens" title="{{ __('Manage Allocation Tokens') }}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 12l8 -4.5" /><path d="M12 12v9" /><path d="M12 12l-8 -4.5" /><path d="M12 12l8 4.5" /><path d="M12 3v9" /><path d="M12 12l-8 4.5" /></svg></a>`;
|
||
}
|
||
|
||
// Mapping of database string values to script names
|
||
const dbValueToScriptName = {
|
||
'/^(?!-)(?!.*--)[A-Z0-9-]{1,63}(?<!-)(.(?!-)(?!.*--)[A-Z0-9-]{1,63}(?<!-))*$/i': 'ASCII',
|
||
'/^[а-яА-ЯґҐєЄіІїЇѝЍћЋљЈ0-9ʼѫѣѭ]+$/u': 'Cyrillic',
|
||
'/^[ぁ-んァ-ン一-龯々0-9]+$/u': 'Japanese',
|
||
'/^[가-힣0-9]+$/u': 'Korean',
|
||
'/^(?!-)(?!.*--)[\u0621-\u064A\u0660-\u0669\u0671-\u06D3-]{1,63}(?<!-)$/u': 'Arabic'
|
||
};
|
||
|
||
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
|
||
'Arabic': 'bg-teal-lt', // Teal badge for Japanese
|
||
// 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,
|
||
paginationSizeSelector:[10, 25, 50, 100],
|
||
clipboard:true,
|
||
clipboardPasteAction:"replace",
|
||
ajaxResponse:function(url, params, response){
|
||
return response.records;
|
||
},
|
||
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:"TLD", field:"tld", minWidth:50, headerSort:true, resizable:false, formatter: tldLinkFormatter, responsive:0},
|
||
{ title: "{{ __('Script') }}", field: "idn_table", width:300, 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(); }},
|
||
]
|
||
});
|
||
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", "tlds.csv");
|
||
}
|
||
|
||
function downloadJSON() {
|
||
table.download("json", "tlds.json");
|
||
}
|
||
|
||
function downloadXLSX() {
|
||
table.download("xlsx", "tlds.xlsx", {sheetName:"My TLDs"});
|
||
}
|
||
|
||
function downloadPDF() {
|
||
table.download("pdf", "tlds.pdf", {
|
||
orientation:"portrait",
|
||
title:"My TLDs"
|
||
});
|
||
}
|
||
</script> |