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:
parent
aaeccd3402
commit
8f06c8db1c
@ -16,8 +16,8 @@ foreach ($this->items as $i => $item) :
|
||||
if ($item->applied) :
|
||||
$status = ' class="table-active"';
|
||||
endif;
|
||||
?>
|
||||
<tr<?php echo $status; ?>>
|
||||
?>
|
||||
<tr<?php echo $status; ?>>
|
||||
<th scope="row" class="text-center">
|
||||
<?php echo $item->pull_id; ?>
|
||||
</th>
|
||||
@ -63,10 +63,10 @@ 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>
|
||||
</tr>
|
||||
<?php endforeach;
|
||||
|
@ -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);
|
||||
}));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user