Changes to icon importer
This commit is contained in:
68
assets/js/icon-import.js
Normal file
68
assets/js/icon-import.js
Normal file
@ -0,0 +1,68 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const installButtons = document.querySelectorAll('.install-btn');
|
||||
const uninstallButtons = document.querySelectorAll('.uninstall-btn');
|
||||
|
||||
// Handle Install button click
|
||||
installButtons.forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
console.log('Install button clicked');
|
||||
const iconSetId = this.getAttribute('data-icon-set-id');
|
||||
console.log('Icon Set ID:', iconSetId);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('action', 'install_icon_set');
|
||||
formData.append('icon_set_id', iconSetId);
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', mytheme_ajax.ajax_url, true);
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
alert('Icon set installed successfully!');
|
||||
} else {
|
||||
alert('Failed to install icon set: ' + response.data.message);
|
||||
}
|
||||
} else {
|
||||
alert('There was an error with the request.');
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
});
|
||||
});
|
||||
|
||||
// Handle Uninstall button click
|
||||
uninstallButtons.forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
console.log('Uninstall button clicked');
|
||||
const iconSetId = this.getAttribute('data-icon-set-id');
|
||||
console.log('Icon Set ID for uninstall:', iconSetId);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('action', 'uninstall_icon_set');
|
||||
formData.append('icon_set_id', iconSetId);
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', mytheme_ajax.ajax_url, true);
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
alert('Icon set uninstalled successfully!');
|
||||
} else {
|
||||
alert('Failed to uninstall icon set: ' + response.data.message);
|
||||
}
|
||||
} else {
|
||||
alert('There was an error with the request.');
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user