Simplify onclick code for ressource lists

This commit is contained in:
Patrick Jentsch 2023-01-10 10:03:27 +01:00
parent 0891176fd7
commit 900ef1ad6d
7 changed files with 21 additions and 49 deletions

View File

@ -84,15 +84,11 @@ class AdminUserList extends ResourceList {
}
onClick(event) {
let listItemElement = event.target.closest('.list-item');
let listItemElement = event.target.closest('.list-item[data-id]');
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;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete': {
console.log('delete', itemId);

View File

@ -92,15 +92,11 @@ class CorpusFileList extends ResourceList {
}
onClick(event) {
let listItemElement = event.target.closest('.list-item');
let listItemElement = event.target.closest('.list-item[data-id]');
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;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete': {
Utils.deleteCorpusFileRequest(this.userId, this.corpusId, itemId);

View File

@ -87,15 +87,11 @@ class CorpusList extends ResourceList {
}
onClick(event) {
let listItemElement = event.target.closest('.list-item');
let listItemElement = event.target.closest('.list-item[data-id]');
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;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete-request': {
Utils.deleteCorpusRequest(this.userId, itemId);

View File

@ -78,15 +78,11 @@ class JobInputList extends ResourceList {
}
onClick(event) {
let listItemElement = event.target.closest('.list-item');
let listItemElement = event.target.closest('.list-item[data-id]');
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;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'download' : listActionElement.dataset.listAction;
switch (listAction) {
case 'download': {
window.location.href = `/jobs/${this.jobId}/inputs/${itemId}/download`;

View File

@ -88,15 +88,11 @@ class JobList extends ResourceList {
}
onClick(event) {
let listItemElement = event.target.closest('.list-item');
let listItemElement = event.target.closest('.list-item[data-id]');
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;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete-request': {
Utils.deleteJobRequest(this.userId, itemId);

View File

@ -82,15 +82,11 @@ class JobResultList extends ResourceList {
}
onClick(event) {
let listItemElement = event.target.closest('.list-item');
let listItemElement = event.target.closest('.list-item[data-id]');
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;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'download' : listActionElement.dataset.listAction;
switch (listAction) {
case 'download': {
window.location.href = `/jobs/${this.jobId}/results/${itemId}/download`;

View File

@ -86,15 +86,11 @@ class PublicUserList extends ResourceList {
}
onClick(event) {
let listItemElement = event.target.closest('.list-item');
let listItemElement = event.target.closest('.list-item[data-id]');
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;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'view': {
window.location.href = `/users/${itemId}`;