mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2025-02-06 21:58:26 +00:00
Refactored JSCode for button-click events.
This commit is contained in:
parent
aaeccd3402
commit
8f06c8db1c
@ -16,57 +16,57 @@ foreach ($this->items as $i => $item) :
|
||||
if ($item->applied) :
|
||||
$status = ' class="table-active"';
|
||||
endif;
|
||||
?>
|
||||
<tr<?php echo $status; ?>>
|
||||
<th scope="row" class="text-center">
|
||||
<?php echo $item->pull_id; ?>
|
||||
</th>
|
||||
<td>
|
||||
<span><?php echo $this->escape($item->title); ?></span>
|
||||
<div role="tooltip" id="tip<?php echo $i; ?>">
|
||||
<?php echo $this->escape($item->description); ?>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-auto">
|
||||
<a class="badge badge-info" href="<?php echo $item->pull_url; ?>" target="_blank">
|
||||
<?php echo Text::_('COM_PATCHTESTER_VIEW_ON_GITHUB'); ?>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-auto">
|
||||
<a class="badge badge-info" href="https://issues.joomla.org/tracker/<?php echo $this->trackerAlias; ?>/<?php echo $item->pull_id; ?>" target="_blank">
|
||||
<?php echo Text::_('COM_PATCHTESTER_VIEW_ON_JOOMLA_ISSUE_TRACKER'); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php if ($item->applied) : ?>
|
||||
<div class="col-md-auto">
|
||||
<span class="badge badge-info"><?php echo Text::sprintf('COM_PATCHTESTER_APPLIED_COMMIT_SHA', substr($item->sha, 0, 10)); ?></span>
|
||||
</div>
|
||||
?>
|
||||
<tr<?php echo $status; ?>>
|
||||
<th scope="row" class="text-center">
|
||||
<?php echo $item->pull_id; ?>
|
||||
</th>
|
||||
<td>
|
||||
<span><?php echo $this->escape($item->title); ?></span>
|
||||
<div role="tooltip" id="tip<?php echo $i; ?>">
|
||||
<?php echo $this->escape($item->description); ?>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-auto">
|
||||
<a class="badge badge-info" href="<?php echo $item->pull_url; ?>" target="_blank">
|
||||
<?php echo Text::_('COM_PATCHTESTER_VIEW_ON_GITHUB'); ?>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-auto">
|
||||
<a class="badge badge-info" href="https://issues.joomla.org/tracker/<?php echo $this->trackerAlias; ?>/<?php echo $item->pull_id; ?>" target="_blank">
|
||||
<?php echo Text::_('COM_PATCHTESTER_VIEW_ON_JOOMLA_ISSUE_TRACKER'); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php if ($item->applied) : ?>
|
||||
<div class="col-md-auto">
|
||||
<span class="badge badge-info"><?php echo Text::sprintf('COM_PATCHTESTER_APPLIED_COMMIT_SHA', substr($item->sha, 0, 10)); ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell text-center">
|
||||
<?php echo $this->escape($item->branch); ?>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell text-center">
|
||||
<?php if ($item->is_rtc) : ?>
|
||||
<span class="badge badge-success"><?php echo Text::_('JYES'); ?></span>
|
||||
<?php else : ?>
|
||||
<span class="badge badge-secondary"><?php echo Text::_('JNO'); ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell text-center">
|
||||
<?php echo $this->escape($item->branch); ?>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell text-center">
|
||||
<?php if ($item->is_rtc) : ?>
|
||||
<span class="badge badge-success"><?php echo Text::_('JYES'); ?></span>
|
||||
<?php else : ?>
|
||||
<span class="badge badge-secondary"><?php echo Text::_('JNO'); ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<?php if ($item->applied) : ?>
|
||||
<span class="badge badge-success"><?php echo Text::_('COM_PATCHTESTER_APPLIED'); ?></span>
|
||||
<?php else : ?>
|
||||
<span class="badge badge-secondary"><?php echo Text::_('COM_PATCHTESTER_NOT_APPLIED'); ?></span>
|
||||
<?php endif; ?>
|
||||
</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>
|
||||
<?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>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<?php if ($item->applied) : ?>
|
||||
<span class="badge badge-success"><?php echo Text::_('COM_PATCHTESTER_APPLIED'); ?></span>
|
||||
<?php else : ?>
|
||||
<span class="badge badge-secondary"><?php echo Text::_('COM_PATCHTESTER_NOT_APPLIED'); ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<?php if ($item->applied) : ?>
|
||||
<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 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>
|
||||
<?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) => {
|
||||
|
||||
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);
|
||||
}));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user