mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-29 07:01:35 +00:00
Enhance list onClick handling
This commit is contained in:
@@ -12,16 +12,16 @@ class UserList extends ResourceList {
|
||||
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<tr class="list-item clickable hoverable">
|
||||
<td><span class="id-1"></span></td>
|
||||
<td><span class="username"></span></td>
|
||||
<td><span class="email"></span></td>
|
||||
<td><span class="last-seen"></span></td>
|
||||
<td><span class="role"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="edit"><i class="material-icons">edit</i></a>
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
|
||||
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete"><i class="material-icons">delete</i></a>
|
||||
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="edit"><i class="material-icons">edit</i></a>
|
||||
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
@@ -84,24 +84,27 @@ class UserList extends ResourceList {
|
||||
}
|
||||
|
||||
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) {
|
||||
let listItemElement = event.target.closest('.list-item');
|
||||
if (listItemElement === null) {return;}
|
||||
if (!('id' in listItemElement.dataset)) {return;}
|
||||
let itemId = listItemElement.dataset.id;
|
||||
if (itemId === undefined) {return;}
|
||||
let listActionElement = event.target.closest('.list-item .list-action-trigger');
|
||||
let listAction =
|
||||
listActionElement === null || !('listAction' in listActionElement.dataset)
|
||||
? 'view' : listActionElement.dataset.listAction;
|
||||
switch (listAction) {
|
||||
case 'delete': {
|
||||
Utils.deleteUserRequest(userId);
|
||||
if (userId === currentUserId) {window.location.href = '/';}
|
||||
Utils.deleteUserRequest(itemId);
|
||||
if (itemId === currentUserId) {window.location.href = '/';}
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
window.location.href = `/admin/users/${userId}/edit`;
|
||||
window.location.href = `/admin/users/${itemId}/edit`;
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/admin/users/${userId}`;
|
||||
window.location.href = `/admin/users/${itemId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
Reference in New Issue
Block a user