cmsmanage/paperwork/js/department_certifications.entry.ts

109 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-07-22 19:02:17 -04:00
import {
Tabulator,
EditModule,
FilterModule,
HtmlTableImportModule,
ResponsiveLayoutModule,
2024-07-23 00:01:29 -04:00
type FilterType,
2024-07-22 19:02:17 -04:00
} from "tabulator-tables";
import "tabulator-tables/src/scss/themes/bootstrap/tabulator_bootstrap5.scss";
Tabulator.registerModule([
EditModule,
FilterModule,
HtmlTableImportModule,
ResponsiveLayoutModule,
]);
Tabulator.extendModule("filter", "filters", {
2024-07-23 00:01:29 -04:00
"!includes"(headerValue: string, rowValue: string) {
2024-07-22 19:02:17 -04:00
return !rowValue.includes(headerValue);
2024-07-23 00:01:29 -04:00
},
2024-07-22 19:02:17 -04:00
});
2024-07-23 00:01:29 -04:00
const certification_table_element = document.querySelector(
"table.certifications",
);
if (certification_table_element instanceof HTMLTableElement) {
const certification_table = new Tabulator(certification_table_element, {
2024-07-22 19:02:17 -04:00
layout: "fitDataFill",
responsiveLayout: "collapse",
pagination: true,
paginationSize: 50,
columnDefaults: {
headerFilter: true,
},
2024-07-23 00:01:29 -04:00
rowFormatter(row) {
2024-07-22 19:02:17 -04:00
const data = row.getData();
if (data.version.includes("[OUTDATED]")) {
row.getElement().classList.add("table-warning");
}
},
columns: [
{
title: "Department",
field: "department",
headerFilter: "list",
headerFilterParams: {
valuesLookup: "active",
autocomplete: true,
listOnEmpty: true,
clearable: true,
},
},
{
title: "Certification",
field: "certification",
headerFilter: "list",
headerFilterParams: {
valuesLookup: "active",
autocomplete: true,
listOnEmpty: true,
clearable: true,
},
},
{
title: "Member/Name",
field: "member_name",
},
{
title: "Version",
field: "version",
headerFilter: "list",
headerFilterParams: {
valuesLookup: "active",
autocomplete: true,
listOnEmpty: true,
clearable: true,
},
},
],
});
function setOutdatedFilter(showOutdated: boolean) {
if (showOutdated) {
2024-07-23 00:01:29 -04:00
certification_table.removeFilter(
"version",
"!includes" as FilterType,
"[OUTDATED]",
);
2024-07-22 19:02:17 -04:00
} else {
2024-07-23 00:01:29 -04:00
certification_table.addFilter(
"version",
"!includes" as FilterType,
"[OUTDATED]",
);
2024-07-22 19:02:17 -04:00
}
}
certification_table.on("tableBuilt", () => {
2024-07-23 00:01:29 -04:00
const outdatedToggle = document.querySelector("#showOutdated");
2024-07-22 19:02:17 -04:00
if (outdatedToggle instanceof HTMLInputElement) {
setOutdatedFilter(outdatedToggle.checked);
2024-07-23 00:01:29 -04:00
outdatedToggle.addEventListener("change", () => {
setOutdatedFilter(outdatedToggle.checked);
});
2024-07-22 19:02:17 -04:00
}
});
}