class UserList extends RessourceList { static autoInit() { for (let userListElement of document.querySelectorAll('.user-list:not(.no-autoinit)')) { new UserList(userListElement); } } static options = { listContainerInnerHTMLGenerator: (listContainerElement) => { listContainerElement.innerHTML = `
search
Id Username Email Last seen Role
`.trim(); }, ressourceMapper: (user) => { return { 'id': user.id, 'id-1': user.id, 'username': user.username, 'email': user.email, 'last-seen': new Date(user.last_seen).toLocaleString('en-US'), 'member-since': user.member_since, 'role': user.role.name }; }, sortParams: ['member-since', {order: 'desc'}], listjs: { item: ` delete edit send `.trim(), valueNames: [ {data: ['id']}, {data: ['member-since']}, 'email', 'id-1', 'last-seen', 'role', 'username' ] } }; constructor(listContainerElement, options = {}) { super(listContainerElement, {...UserList.options, ...options}); } init(users) { super._init(Object.values(users)); } onClick(event) { let userElement = event.target.closest('tr'); if (userElement === null) {return;} let userId = userElement.dataset.id; if (userId === undefined) {return;} let actionButtonElement = event.target.closest('.action-button'); let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action; switch (action) { case 'delete': { Utils.deleteUserRequest(userId); if (userId === currentUserId) {window.location.href = '/';} break; } case 'edit': { window.location.href = `/admin/users/${userId}/edit`; break; } case 'view': { window.location.href = `/admin/users/${userId}`; break; } default: { break; } } } }