From 900ef1ad6d20f07c51a69f4ff6a771022403d4db Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Tue, 10 Jan 2023 10:03:27 +0100 Subject: [PATCH] Simplify onclick code for ressource lists --- app/static/js/ResourceLists/AdminUserList.js | 10 +++------- app/static/js/ResourceLists/CorpusFileList.js | 10 +++------- app/static/js/ResourceLists/CorpusList.js | 10 +++------- app/static/js/ResourceLists/JobInputList.js | 10 +++------- app/static/js/ResourceLists/JobList.js | 10 +++------- app/static/js/ResourceLists/JobResultList.js | 10 +++------- app/static/js/ResourceLists/PublicUserList.js | 10 +++------- 7 files changed, 21 insertions(+), 49 deletions(-) diff --git a/app/static/js/ResourceLists/AdminUserList.js b/app/static/js/ResourceLists/AdminUserList.js index 2749b976..0307bbdc 100644 --- a/app/static/js/ResourceLists/AdminUserList.js +++ b/app/static/js/ResourceLists/AdminUserList.js @@ -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); diff --git a/app/static/js/ResourceLists/CorpusFileList.js b/app/static/js/ResourceLists/CorpusFileList.js index 2397cd72..fd4ff480 100644 --- a/app/static/js/ResourceLists/CorpusFileList.js +++ b/app/static/js/ResourceLists/CorpusFileList.js @@ -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); diff --git a/app/static/js/ResourceLists/CorpusList.js b/app/static/js/ResourceLists/CorpusList.js index eff52814..e4af0b12 100644 --- a/app/static/js/ResourceLists/CorpusList.js +++ b/app/static/js/ResourceLists/CorpusList.js @@ -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); diff --git a/app/static/js/ResourceLists/JobInputList.js b/app/static/js/ResourceLists/JobInputList.js index 784e767a..36cb47f7 100644 --- a/app/static/js/ResourceLists/JobInputList.js +++ b/app/static/js/ResourceLists/JobInputList.js @@ -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`; diff --git a/app/static/js/ResourceLists/JobList.js b/app/static/js/ResourceLists/JobList.js index 49999053..1fa14ea2 100644 --- a/app/static/js/ResourceLists/JobList.js +++ b/app/static/js/ResourceLists/JobList.js @@ -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); diff --git a/app/static/js/ResourceLists/JobResultList.js b/app/static/js/ResourceLists/JobResultList.js index b8ef95c0..71c430af 100644 --- a/app/static/js/ResourceLists/JobResultList.js +++ b/app/static/js/ResourceLists/JobResultList.js @@ -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`; diff --git a/app/static/js/ResourceLists/PublicUserList.js b/app/static/js/ResourceLists/PublicUserList.js index bde271ef..e6cfff34 100644 --- a/app/static/js/ResourceLists/PublicUserList.js +++ b/app/static/js/ResourceLists/PublicUserList.js @@ -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}`;