2021-01-13 10:57:13 +00:00
|
|
|
class UserList extends RessourceList {
|
2021-12-02 15:25:48 +00:00
|
|
|
static options = {
|
|
|
|
item: `
|
2021-12-08 10:25:52 +00:00
|
|
|
<tr class="hoverable">
|
2022-02-08 11:26:20 +00:00
|
|
|
<td><span class="id-1"></span></td>
|
2021-12-02 15:25:48 +00:00
|
|
|
<td><span class="username"></span></td>
|
|
|
|
<td><span class="email"></span></td>
|
2022-02-08 11:26:20 +00:00
|
|
|
<td><span class="last-seen"></span></td>
|
2021-12-02 15:25:48 +00:00
|
|
|
<td><span class="role"></span></td>
|
|
|
|
<td class="right-align">
|
|
|
|
<a class="action-button btn-floating red tooltipped waves-effect waves-light" data-action="delete" data-position="top" data-tooltip="Delete"><i class="material-icons">delete</i></a>
|
|
|
|
<a class="action-button btn-floating tooltipped waves-effect waves-light" data-action="edit" data-position="top" data-tooltip="Edit"><i class="material-icons">edit</i></a>
|
|
|
|
<a class="action-button btn-floating tooltipped waves-effect waves-light" data-action="view" data-position="top" data-tooltip="View"><i class="material-icons">send</i></a>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.trim(),
|
2021-12-03 11:01:50 +00:00
|
|
|
ressourceMapper: user => {
|
|
|
|
return {
|
2022-02-08 11:26:20 +00:00
|
|
|
'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
|
2021-12-03 11:01:50 +00:00
|
|
|
};
|
|
|
|
},
|
2022-02-08 11:26:20 +00:00
|
|
|
sortValueName: 'member-since',
|
2021-12-03 11:01:50 +00:00
|
|
|
valueNames: [
|
|
|
|
{data: ['id']},
|
2022-02-08 11:26:20 +00:00
|
|
|
{data: ['member-since']},
|
2021-12-03 11:01:50 +00:00
|
|
|
'email',
|
2022-02-08 11:26:20 +00:00
|
|
|
'id-1',
|
|
|
|
'last-seen',
|
2021-12-03 11:01:50 +00:00
|
|
|
'role',
|
|
|
|
'username'
|
|
|
|
]
|
2021-12-02 15:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-13 10:57:13 +00:00
|
|
|
constructor(listElement, options = {}) {
|
|
|
|
super(listElement, {...UserList.options, ...options});
|
|
|
|
}
|
|
|
|
|
|
|
|
init(users) {
|
2021-11-30 15:22:16 +00:00
|
|
|
super._init(Object.values(users));
|
2021-01-13 10:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onclick(event) {
|
2021-12-01 13:15:20 +00:00
|
|
|
let action;
|
|
|
|
let actionButtonElement;
|
|
|
|
let deleteModal;
|
|
|
|
let deleteModalElement;
|
|
|
|
let tmp;
|
|
|
|
let userElement;
|
|
|
|
let userId;
|
|
|
|
|
|
|
|
userElement = event.target.closest('tr[data-id]');
|
2021-11-30 15:22:16 +00:00
|
|
|
if (userElement === null) {return;}
|
2021-12-01 13:15:20 +00:00
|
|
|
userId = userElement.dataset.id;
|
|
|
|
actionButtonElement = event.target.closest('.action-button[data-action]');
|
|
|
|
action = (actionButtonElement === null) ? 'view' : actionButtonElement.dataset.action;
|
2021-01-13 10:57:13 +00:00
|
|
|
switch (action) {
|
|
|
|
case 'delete':
|
2021-12-01 13:15:20 +00:00
|
|
|
tmp = document.createElement('div');
|
|
|
|
tmp.innerHTML = `
|
2021-11-30 15:22:16 +00:00
|
|
|
<div class="modal">
|
|
|
|
<div class="modal-content">
|
|
|
|
<h4>Confirm user deletion</h4>
|
|
|
|
<p>Do you really want to delete user <b>${userId}</b>? All files will be permanently deleted!</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<a href="#!" class="btn modal-close waves-effect waves-light">Cancel</a>
|
|
|
|
<a class="btn modal-close red waves-effect waves-light" href="/admin/users/${userId}/delete"><i class="material-icons left">delete</i>Delete</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`.trim();
|
2021-12-01 13:15:20 +00:00
|
|
|
deleteModalElement = document.querySelector('#modals').appendChild(tmp.firstChild);
|
|
|
|
deleteModal = M.Modal.init(
|
|
|
|
deleteModalElement,
|
|
|
|
{
|
|
|
|
onCloseEnd: () => {
|
|
|
|
deleteModal.destroy();
|
|
|
|
deleteModalElement.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2021-01-13 10:57:13 +00:00
|
|
|
deleteModal.open();
|
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
window.location.href = `/admin/users/${userId}/edit`;
|
|
|
|
break;
|
|
|
|
case 'view':
|
2021-11-30 15:22:16 +00:00
|
|
|
window.location.href = `/admin/users/${userId}`;
|
2021-01-13 10:57:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|