Enhance list onClick handling

This commit is contained in:
Patrick Jentsch
2023-01-05 15:03:59 +01:00
parent 9977128cb9
commit 381716f87a
9 changed files with 120 additions and 97 deletions

View File

@@ -24,11 +24,11 @@ class JobResultList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item clickable hoverable">
<td><span class="description"></span></td>
<td><span class="filename"></span></td>
<td class="right-align">
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="download"><i class="material-icons">file_download</i></a>
</td>
</tr>
`.trim();
@@ -82,15 +82,18 @@ class JobResultList extends ResourceList {
}
onClick(event) {
let jobResultElement = event.target.closest('tr');
if (jobResultElement === null) {return;}
let jobResultId = jobResultElement.dataset.id;
if (jobResultId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'download' : 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)
? 'download' : listActionElement.dataset.listAction;
switch (listAction) {
case 'download': {
window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`;
window.location.href = `/jobs/${this.jobId}/results/${itemId}/download`;
break;
}
default: {