You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sessioncommunities.online/output/js/constants.js

60 lines
1.6 KiB
JavaScript

2 years ago
// This file contains definitions which help to reduce the amount
// of redunant values in the main file, especially those that could
// change in the foreseeable future.
export const dom = {
tbl_communities: () => document.getElementById("tbl_communities"),
td_last_checked: () => document.getElementById("td_last_checked"),
qr_modal: (communityID) => document.getElementById(`modal_${communityID}`),
join_urls: () => document.getElementsByClassName("td_join_url"),
td_summary: () => document.getElementById("td_summary"),
snackbar: () => document.getElementById("copy-snackbar")
2 years ago
}
export const COLUMN = {
IDENTIFIER: 0, LANGUAGE: 1, NAME: 2,
DESCRIPTION: 3, USERS: 4, PREVIEW: 5,
QR_CODE: 6, JOIN_URL: 7
};
// Reverse enum.
// Takes original key-value pairs, flips them, and casefolds the new values.
// Should correspond to #th_{} and .td_{} elements in communities table.
export const COLUMN_LITERAL = Object.fromEntries(
Object.entries(COLUMN).map(([name, id]) => [id, name.toLowerCase()])
2 years ago
);
export const COMPARISON = {
GREATER: 1, EQUAL: 0, SMALLER: -1
};
export const ATTRIBUTES = {
SORTING: {
ACTIVE: 'data-sort',
ASCENDING: 'data-sort-asc',
COLUMN: 'data-sorted-by',
COLUMN_LITERAL: 'sorted-by'
}
2 years ago
};
export function columnAscendingByDefault(column) {
return column != COLUMN.USERS;
2 years ago
}
export function columnIsSortable(column) { return column != COLUMN.QR_CODE; }
export function columnNeedsCasefold(column) {
return [
COLUMN.IDENTIFIER,
COLUMN.NAME,
2 years ago
COLUMN.DESCRIPTION
].includes(column);
}
export function columnIsNumeric(column) {
return [
COLUMN.USERS
].includes(column);
}