From 8f06c8db1ce5a8e01eed0db23ee52c7eeda0c864 Mon Sep 17 00:00:00 2001 From: datsepp Date: Tue, 10 Sep 2019 15:22:19 +0200 Subject: [PATCH] Refactored JSCode for button-click events. --- .../View/Pulls/tmpl/default_items.php | 104 +++++++++--------- media/com_patchtester/js/patchtester.js | 39 +++---- 2 files changed, 70 insertions(+), 73 deletions(-) diff --git a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php index 3d6345b..f829d66 100644 --- a/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php +++ b/administrator/components/com_patchtester/PatchTester/View/Pulls/tmpl/default_items.php @@ -16,57 +16,57 @@ foreach ($this->items as $i => $item) : if ($item->applied) : $status = ' class="table-active"'; endif; -?> -> - - pull_id; ?> - - - escape($item->title); ?> - -
-
- - - -
-
- - - -
- applied) : ?> -
- sha, 0, 10)); ?> -
+ ?> + > + + pull_id; ?> + + + escape($item->title); ?> + +
+
+ + + +
+
+ + + +
+ applied) : ?> +
+ sha, 0, 10)); ?> +
+ +
+ + + escape($item->branch); ?> + + + is_rtc) : ?> + + + -
- - - escape($item->branch); ?> - - - is_rtc) : ?> - - - - - - - applied) : ?> - - - - - - - applied) : ?> - - - - - - + + + applied) : ?> + + + + + + + applied) : ?> + + + + + + { - window.PatchTester = { - /** - * Process the patch action - * - * @param {String} task The task to perform - * @param {Number} id The item ID - */ - submitpatch: function (task, id) { - var idField = document.getElementById('pull_id'); - idField.value = id; + let submitPatch = document.querySelectorAll(".submitPatch"); + let pullIdForm = document.querySelector("#pull_id"); - Joomla.submitform(task); - } - }; + /** + * EventListener which listens on submitPatch Button, + * checks if it is an apply or revert method and + * processes the patch action + * + * @param {Event} event + */ + submitPatch.forEach((element) => element.addEventListener("click", (event) => { + let currentTarget = event.currentTarget, + data = currentTarget.dataset.task.split("-"), + task = data[0]; - Joomla.submitbutton = function (task) { - if (task != 'reset' || confirm(Joomla.JText._('COM_PATCHTESTER_CONFIRM_RESET', 'Resetting will attempt to revert all applied patches and removes all backed up files. This may result in a corrupted environment. Are you sure you want to continue?'))) { - Joomla.submitform(task); - } - }; -}(Joomla, window, document); + pullIdForm.value = data[1]; + Joomla.submitform(task); + })); +});