forked from FrederikBaerentsen/BrickTracker
Simplify the way javascript is loaded (we don't have that many scripts running) and use data attribute to instantiate grid and tables
This commit is contained in:
@@ -115,13 +115,11 @@ class BrickChanger {
|
||||
}
|
||||
|
||||
// Helper to setup the changer
|
||||
const setup_changers = () => {
|
||||
document.querySelectorAll("*[data-changer-id]").forEach(el => {
|
||||
new BrickChanger(
|
||||
el.dataset.changerPrefix,
|
||||
el.dataset.changerId,
|
||||
el.dataset.changerUrl,
|
||||
el.dataset.changerParent
|
||||
);
|
||||
});
|
||||
}
|
||||
const setup_changers = () => document.querySelectorAll("*[data-changer-id]").forEach(
|
||||
el => new BrickChanger(
|
||||
el.dataset.changerPrefix,
|
||||
el.dataset.changerId,
|
||||
el.dataset.changerUrl,
|
||||
el.dataset.changerParent
|
||||
)
|
||||
);
|
||||
@@ -50,15 +50,15 @@ class BrickGridSortButton {
|
||||
|
||||
// Grid class
|
||||
class BrickGrid {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
constructor(grid) {
|
||||
this.id = grid.id;
|
||||
|
||||
// Grid elements (built based on the initial id)
|
||||
this.html_grid = document.getElementById(id);
|
||||
this.html_sort = document.getElementById(`${id}-sort`);
|
||||
this.html_search = document.getElementById(`${id}-search`);
|
||||
this.html_filter = document.getElementById(`${id}-filter`);
|
||||
this.html_theme = document.getElementById(`${id}-theme`);
|
||||
this.html_grid = document.getElementById(this.id);
|
||||
this.html_sort = document.getElementById(`${this.id}-sort`);
|
||||
this.html_search = document.getElementById(`${this.id}-search`);
|
||||
this.html_filter = document.getElementById(`${this.id}-filter`);
|
||||
this.html_theme = document.getElementById(`${this.id}-theme`);
|
||||
|
||||
// Sort buttons
|
||||
this.html_sort_buttons = {};
|
||||
@@ -251,3 +251,8 @@ class BrickGrid {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to setup the grids
|
||||
const setup_grids = () => document.querySelectorAll('*[data-grid="true"]').forEach(
|
||||
el => new BrickGrid(el)
|
||||
);
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
class BrickTable {
|
||||
constructor(id, per_page, no_sort = [], number = []) {
|
||||
const columns = [];
|
||||
constructor(table, per_page) {
|
||||
const columns = []
|
||||
const no_sort = [];
|
||||
const number = [];
|
||||
|
||||
// Read the table header for parameters
|
||||
table.querySelectorAll('th').forEach((th, index) => {
|
||||
if (th.dataset.tableNoSort) {
|
||||
no_sort.push(index);
|
||||
}
|
||||
|
||||
if (th.dataset.tableNumber) {
|
||||
number.push(index);
|
||||
}
|
||||
});
|
||||
|
||||
if (no_sort.length) {
|
||||
columns.push({ select: no_sort, sortable: false, searchable: false });
|
||||
@@ -10,7 +23,7 @@ class BrickTable {
|
||||
columns.push({ select: number, type: "number", searchable: false });
|
||||
}
|
||||
|
||||
this.table = new simpleDatatables.DataTable(`#${id}`, {
|
||||
this.table = new simpleDatatables.DataTable(`#${table.id}`, {
|
||||
columns: columns,
|
||||
pagerDelta: 1,
|
||||
perPage: per_page,
|
||||
@@ -67,3 +80,8 @@ class BrickTable {
|
||||
return search;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to setup the tables
|
||||
const setup_tables = (per_page) => document.querySelectorAll('table[data-table="true"]').forEach(
|
||||
el => new BrickTable(el, per_page)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user