From 7c087ee161e96f597ae4ec8a344b438546647be0 Mon Sep 17 00:00:00 2001 From: Alejandro Date: Sat, 24 Feb 2024 19:52:02 -0400 Subject: [PATCH] Refactor JS code related to listings --- app/views/admin/list.php | 9 --------- app/views/admin/partials/lists/links.php | 2 +- app/views/admin/partials/lists/pages.php | 2 +- app/views/admin/partials/lists/posts.php | 2 +- app/views/admin/partials/lists/tags.php | 2 +- app/views/admin/partials/lists/users.php | 2 +- app/views/admin/partials/media_header.php | 14 +++++++------- public/assets/js/admin.js | 9 +++++++++ 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/views/admin/list.php b/app/views/admin/list.php index 6e38c58..a6cfabd 100755 --- a/app/views/admin/list.php +++ b/app/views/admin/list.php @@ -73,14 +73,5 @@ Listing.setNextPageUrl(); Listing.loadNextPage(); }); - - function listHandleResponse(res) { - if (res.success) { - document.querySelector('dialog[open]')?.close(); - Dropdown.close(); - Listing.setNextPage(1); - Listing.loadNextPage(); - } - } sectionEnd() ?> diff --git a/app/views/admin/partials/lists/links.php b/app/views/admin/partials/lists/links.php index 031c412..5dcbc62 100755 --- a/app/views/admin/partials/lists/links.php +++ b/app/views/admin/partials/lists/links.php @@ -28,7 +28,7 @@ class="danger" if (confirm(.sprintf())) { Form.send('/admin/links/remove/' + , null, null, { csrf: csrfToken())) ?>, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } " >include('icons/trash.svg') ?> diff --git a/app/views/admin/partials/lists/pages.php b/app/views/admin/partials/lists/pages.php index 60022cf..1e26f3a 100755 --- a/app/views/admin/partials/lists/pages.php +++ b/app/views/admin/partials/lists/pages.php @@ -29,7 +29,7 @@ class="danger" if (confirm(.sprintf())) { Form.send('/admin/pages/remove/' + , null, null, { csrf: csrfToken())) ?>, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } " >include('icons/trash.svg') ?> diff --git a/app/views/admin/partials/lists/posts.php b/app/views/admin/partials/lists/posts.php index e59ef6b..120d598 100755 --- a/app/views/admin/partials/lists/posts.php +++ b/app/views/admin/partials/lists/posts.php @@ -35,7 +35,7 @@ class="danger" if (confirm(.sprintf())) { Form.send('/admin/posts/remove/' + , null, null, { csrf: csrfToken())) ?>, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } " >include('icons/trash.svg') ?> diff --git a/app/views/admin/partials/lists/tags.php b/app/views/admin/partials/lists/tags.php index 8c627c1..f7750ed 100755 --- a/app/views/admin/partials/lists/tags.php +++ b/app/views/admin/partials/lists/tags.php @@ -21,7 +21,7 @@ class="danger" if (confirm(.sprintf())) { Form.send('/admin/tags/remove/' + , null, null, { csrf: csrfToken())) ?>, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } " >include('icons/trash.svg') ?> diff --git a/app/views/admin/partials/lists/users.php b/app/views/admin/partials/lists/users.php index b52b252..6f1fefe 100755 --- a/app/views/admin/partials/lists/users.php +++ b/app/views/admin/partials/lists/users.php @@ -42,7 +42,7 @@ class="danger" if (confirm(.sprintf())) { Form.send('/admin/users/remove/' + , null, null, { csrf: csrfToken())) ?>, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } " >include('icons/trash.svg') ?> diff --git a/app/views/admin/partials/media_header.php b/app/views/admin/partials/media_header.php index 7c9412e..3df287d 100644 --- a/app/views/admin/partials/media_header.php +++ b/app/views/admin/partials/media_header.php @@ -114,7 +114,7 @@ function uploadFile() { Form.send('/admin/media/upload' + window.location.search, 'file-form', get('#file-form button'), { csrf: csrf_token, }).then(res => { - listHandleResponse(res); + Listing.handleResponse(res); get('#input-file').value = ''; }); } @@ -124,7 +124,7 @@ function deleteFile(i) { if (confirm(.sprintf(file_name))) { Form.send('/admin/media/remove?path=' + path + '/' + file_name, null, null, { csrf: csrf_token, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } } @@ -136,7 +136,7 @@ function openEditFileDialog(i) { function editFile() { Form.send('/admin/media/save?path=' + path + '/' + file_name, 'edit-dialog', null, { csrf: csrf_token, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } function openFolderDialog() { @@ -147,7 +147,7 @@ function openFolderDialog() { function createFolder() { Form.send('/admin/media/createFolder' + window.location.search, 'folder-dialog', null, { csrf: csrf_token, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } function openMoveDialog(i) { @@ -158,7 +158,7 @@ function openMoveDialog(i) { function moveFile() { Form.send('/admin/media/move?path=' + path + '/' + file_name, 'move-dialog', null, { csrf: csrf_token, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } function openDuplicateDialog(i) { @@ -169,7 +169,7 @@ function openDuplicateDialog(i) { function duplicateFile() { Form.send('/admin/media/duplicate?path=' + path + '/' + file_name, 'duplicate-dialog', null, { csrf: csrf_token, - }).then(res => listHandleResponse(res)); + }).then(res => Listing.handleResponse(res)); } function copyPath(path) { @@ -217,7 +217,7 @@ function downloadAll() { Snackbar.show(res.errors[0], false); } - listHandleResponse(res); + Listing.handleResponse(res); }) .catch(() => Snackbar.show(LANG.unexpected_error, false)) .finally(() => document.body.style.cursor = 'default'); diff --git a/public/assets/js/admin.js b/public/assets/js/admin.js index a749a2c..2ef6112 100755 --- a/public/assets/js/admin.js +++ b/public/assets/js/admin.js @@ -232,6 +232,15 @@ class Listing { get('#main-listing > svg')?.remove(); }); } + + static handleResponse(res) { + if (res.success) { + document.querySelector('dialog[open]')?.close(); + Dropdown.close(); + this.setNextPage(1); + this.loadNextPage(); + } + } } class Dropdown {