class UserList extends RessourceList { static options = { item: ` delete edit send `.trim(), ressourceMapper: user => { return { id: user.id, idDuplicate: user.id, username: user.username, email: user.email, last_seen: new Date(user.last_seen).toLocaleString("en-US"), role: user.role.name }; }, sortValueName: 'memberSince', valueNames: [ {data: ['id']}, {data: ['memberSince']}, 'email', 'idDuplicate', 'last_seen', 'role', 'username' ] }; constructor(listElement, options = {}) { super(listElement, {...UserList.options, ...options}); } init(users) { super._init(Object.values(users)); } onclick(event) { let action; let actionButtonElement; let deleteModal; let deleteModalElement; let tmp; let userElement; let userId; userElement = event.target.closest('tr[data-id]'); if (userElement === null) {return;} userId = userElement.dataset.id; actionButtonElement = event.target.closest('.action-button[data-action]'); action = (actionButtonElement === null) ? 'view' : actionButtonElement.dataset.action; switch (action) { case 'delete': tmp = document.createElement('div'); tmp.innerHTML = ` `.trim(); deleteModalElement = document.querySelector('#modals').appendChild(tmp.firstChild); deleteModal = M.Modal.init( deleteModalElement, { onCloseEnd: () => { deleteModal.destroy(); deleteModalElement.remove(); } } ); deleteModal.open(); break; case 'edit': window.location.href = `/admin/users/${userId}/edit`; break; case 'view': window.location.href = `/admin/users/${userId}`; break; default: break; } } }