mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-22 10:36:03 +02:00
97 lines
No EOL
4.5 KiB
Twig
97 lines
No EOL
4.5 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 registrarLinkFormatter(cell){
|
|
var value = cell.getValue();
|
|
return `<a href="/registrar/view/${value}" style="font-weight:bold;">${value}</a>`;
|
|
}
|
|
|
|
function actionsFormatter(cell, formatterParams, onRendered) {
|
|
return `
|
|
<a class="btn btn-outline-primary btn-icon update-btn" href="/registrar/update/${cell.getRow().getData().clid}"><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>
|
|
`;
|
|
}
|
|
|
|
function statusFormatter(cell) {
|
|
var statusArray = cell.getValue();
|
|
if (statusArray && Array.isArray(statusArray)) {
|
|
return statusArray.map(item => item.status).join(', ');
|
|
}
|
|
return "";
|
|
}
|
|
|
|
currency = "{{ currency }} ";
|
|
|
|
table = new Tabulator("#registrarTable", {
|
|
ajaxURL:"/api/records/registrar", // 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:"{{ __('Name') }}", field:"name", width:200, headerSort:true, formatter: registrarLinkFormatter, responsive:0},
|
|
{title:"IANA ID", field:"iana_id", width:300, headerSort:true, responsive:2},
|
|
{title:"{{ __('Email') }}", field:"email", width:300, headerSort:true, responsive:2},
|
|
{title:"{{ __('Balance') }}", field:"accountBalance", width:300, headerSort:false, download:false, responsive:2, formatter:"money", formatterParams:{
|
|
decimal:".",
|
|
thousand:" ",
|
|
symbol:currency,
|
|
negativeSign:true,
|
|
}},
|
|
{title: "{{ __('Actions') }}", formatter: actionsFormatter, responsive:0, headerSort: false, download:false, hozAlign: "center", 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 filter when there's a term to search for
|
|
table.setFilter(function (data) {
|
|
return (
|
|
String(data.name).toLowerCase().includes(term) ||
|
|
String(data.iana_id).toLowerCase().includes(term) ||
|
|
String(data.email).toLowerCase().includes(term) ||
|
|
String(data.accountBalance).toString().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 Registrars"});
|
|
}
|
|
|
|
function downloadPDF() {
|
|
table.download("pdf", "data.pdf", {
|
|
orientation:"portrait",
|
|
title:"My Registrars",
|
|
jsPDF:{unit:"mm", format:"a4", orientation:"p"}
|
|
});
|
|
}
|
|
</script> |