33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2025-01-03 07:12:36 +00:00

Refactored JSCode for button-click events.

This commit is contained in:
datsepp 2019-09-10 15:22:19 +02:00
parent aaeccd3402
commit 8f06c8db1c
2 changed files with 70 additions and 73 deletions

View File

@ -63,9 +63,9 @@ foreach ($this->items as $i => $item) :
</td>
<td class="text-center">
<?php if ($item->applied) : ?>
<button class="btn btn-sm btn-success" onclick="event.stopPropagation(); PatchTester.submitpatch('revert', '<?php echo (int) $item->applied; ?>');"><?php echo Text::_('COM_PATCHTESTER_REVERT_PATCH'); ?></button>
<button type="button" class="btn btn-sm btn-success submitPatch" data-task="revert-<?php echo (int) $item->applied; ?>"><?php echo Text::_('COM_PATCHTESTER_REVERT_PATCH'); ?></button>
<?php else : ?>
<button class="btn btn-sm btn-primary" onclick="event.stopPropagation(); PatchTester.submitpatch('apply', '<?php echo (int) $item->pull_id; ?>');"><?php echo Text::_('COM_PATCHTESTER_APPLY_PATCH'); ?></button>
<button type="button" class="btn btn-sm btn-primary submitPatch" data-task="apply-<?php echo (int) $item->pull_id; ?>"><?php echo Text::_('COM_PATCHTESTER_APPLY_PATCH'); ?></button>
<?php endif; ?>
</td>
</tr>

View File

@ -9,27 +9,24 @@ if (typeof Joomla === 'undefined') {
throw new Error('PatchTester JavaScript requires the Joomla core JavaScript API')
}
!function (Joomla, window, document) {
'use strict';
document.addEventListener("DOMContentLoaded", (event) => {
let submitPatch = document.querySelectorAll(".submitPatch");
let pullIdForm = document.querySelector("#pull_id");
window.PatchTester = {
/**
* Process the patch action
* EventListener which listens on submitPatch Button,
* checks if it is an apply or revert method and
* processes the patch action
*
* @param {String} task The task to perform
* @param {Number} id The item ID
* @param {Event} event
*/
submitpatch: function (task, id) {
var idField = document.getElementById('pull_id');
idField.value = id;
submitPatch.forEach((element) => element.addEventListener("click", (event) => {
let currentTarget = event.currentTarget,
data = currentTarget.dataset.task.split("-"),
task = data[0];
pullIdForm.value = data[1];
Joomla.submitform(task);
}
};
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);
}));
});