Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update js scripts #368

Merged
merged 6 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions media/com_patchtester/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
"type": "script",
"uri": "com_patchtester/fetcher.js",
"attributes": {
"type": "module",
"defer": true
"type": "module"
}
},
{
"name": "com_patchtester.patchtester",
"type": "script",
"uri": "com_patchtester/patchtester.js",
"attributes": {
"type": "module",
"defer": true
"type": "module"
}
},
{
Expand Down
70 changes: 24 additions & 46 deletions media/com_patchtester/js/patchtester.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,34 @@
/**
* Patch testing component for the Joomla! CMS
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

if (typeof Joomla === 'undefined') {
throw new Error('PatchTester JavaScript requires the Joomla core JavaScript API')
}

document.addEventListener("DOMContentLoaded", function (event) {
roland-d marked this conversation as resolved.
Show resolved Hide resolved
const submitPatch = document.querySelectorAll(".submitPatch");
Joomla.submitbutton = (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);
}
};

/**
* 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(function (element) {
element.addEventListener("click", function (event) {
const currentTarget = event.currentTarget;
const task = `${currentTarget.dataset.task}.${currentTarget.dataset.task}`
const id = parseInt(currentTarget.dataset.id)

PatchTester.submitpatch(task, id);
});
});
});

!function (Joomla, window, document) {
roland-d marked this conversation as resolved.
Show resolved Hide resolved
'use strict';

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;

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);
/**
* EventListener which listens on submitPatch Button,
* checks if it is an apply or revert method and
* processes the patch action
*
* @param {Event} event
*/
document.querySelectorAll(".submitPatch").forEach((element) => element.addEventListener("click", (event) => {
const element = document.getElementById('pull_id');
const target = event.currentTarget;

if (element) {
element.value = parseInt(target.dataset.id);
}

Joomla.submitform(`${target.dataset.task}.${target.dataset.task}`);
}));