mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-05 17:18:04 +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-primary" 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-green" href="/registry/promotion/${cell.getRow().getData().tld_o}" title="{{ __('Manage Promotions') }}"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M17 17m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /><path d="M7 7m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /><path d="M6 18l12 -12" /></svg></a> <a class="btn btn-icon btn-outline-orange" href="/registry/idnexport/${cell.getRow().getData().tld_o}" title="{{ __('Export IDN Table') }}" target="_blank"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M14 3v4a1 1 0 0 0 1 1h4" /><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v5m-5 6h7m-3 -3l3 3l-3 3" /></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> |