Complete client-side dependencies management. Add information of which plugin needed an additional package that can now be deleted since not required any more

This commit is contained in:
Flavio Copes
2016-03-05 20:58:19 +01:00
parent c9b6b01607
commit cf6bfff8cc
2 changed files with 34 additions and 34 deletions

View File

@@ -43,38 +43,41 @@ $(document).on('click', '[data-plugin-action="remove-plugin"]', (event) => {
} }
}, (response) => { }, (response) => {
if (response.status == 'success') { if (response.status == 'success') {
// Go to Step 2 $('.remove-plugin-confirm').addClass('hidden');
loadPluginDependencies(slug, function(dependencies) {
$('.remove-plugin-step-1').addClass('hidden');
if (dependencies.length > 0) { if (response.dependencies.length > 0) {
addDependenciesToList(dependencies); addDependenciesToList(response.dependencies);
$('.remove-plugin-step-2').removeClass('hidden'); $('.remove-plugin-dependencies').removeClass('hidden');
} else { } else {
$('.remove-plugin-done').removeClass('hidden'); $('.remove-plugin-done').removeClass('hidden');
} getBackToPluginsList();
}
//The plugin was removed. When the modal closes, move to the plugins list
$(document).on('closing', '[data-remodal-id="delete-plugin"]', function (e) {
getBackToPluginsList();
}); });
} }
}); });
}); });
var loadPluginDependencies = function loadPluginDependencies(plugin, callback) { var getBackToPluginsList = function getBackToPluginsList() {
let url = `${config.base_url_relative}/plugins.json/task${config.param_sep}getPluginDependencies/plugin:${plugin}/admin-nonce${config.param_sep}${config.admin_nonce}`; window.location.href = `${config.base_url_relative}/plugins`;
request(url, {
method: 'get',
}, (response) => {
callback(response.dependencies);
});
}
var addDependencyToList = function addDependencyToList(dependency) {
var container = $('.plugin-dependencies-container');
container.append(`<li>${dependency} <a href="#" class="button" data-dependency-slug="${dependency}" data-plugin-action="remove-dependency">Remove</a></li>`);
}; };
var addDependenciesToList = function addDependenciesToList(dependencies) { var addDependencyToList = function addDependencyToList(dependency, slug = '') {
var container = $('.plugin-dependencies-container');
var text = `${dependency} <a href="#" class="button" data-dependency-slug="${dependency}" data-plugin-action="remove-dependency">Remove</a>`;
if (slug) {
text += ` (was needed by ${slug})`;
}
container.append(`<li>${text}</li>`);
};
var addDependenciesToList = function addDependenciesToList(dependencies, slug = '') {
dependencies.forEach(function(dependency) { dependencies.forEach(function(dependency) {
addDependencyToList(dependency); addDependencyToList(dependency, slug);
}); });
}; };
@@ -95,12 +98,9 @@ $(document).on('click', '[data-plugin-action="remove-dependency"]', (event) => {
$(event.target).removeClass('button'); $(event.target).removeClass('button');
$(event.target).replaceWith($('<span>Removed successfully</span>')); $(event.target).replaceWith($('<span>Removed successfully</span>'));
// add further dependencies i can remove to the bottom of the list if (response.dependencies.length > 0) {
loadPluginDependencies(slug, function(dependencies) { addDependenciesToList(response.dependencies, slug);
if (dependencies.length > 0) { }
addDependenciesToList(dependencies);
}
});
} }
}); });
}); });

View File

@@ -65,7 +65,7 @@
> >
<form> <form>
<div class="remove-plugin-step-1"> <div class="remove-plugin-confirm">
<h1>Remove the plugin</h1> <h1>Remove the plugin</h1>
<p class="bigger"> <p class="bigger">
Are you sure you want to delete this plugin? Are you sure you want to delete this plugin?
@@ -77,13 +77,13 @@
</div> </div>
</div> </div>
<div class="remove-plugin-step-2 hidden"> <div class="remove-plugin-dependencies hidden">
<h1>Remove the plugin dependencies</h1> <h1>Plugin removed successfully</h1>
<p class="bigger"> <p class="bigger">
The plugin required the following dependencies
</p> </p>
<p> <p>
Check the ones you want to remove, and click Continue The plugin required the following dependencies, which are not required by other installed packages. If you are not using them, you can remove them directly from here.
</p> </p>
<div> <div>