2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-06 15:28:49 +00:00
Matthias Mair 8df5649b6f
[FR] Add API endpoint to activate plugins (#4186)
* make plugin urls def cleaner

* rename plugin managment endpoints

* [FR] Add API endpoint to activate plugins
Fixes #4182

* fix for api url change

* bump API version
2023-01-26 07:05:09 +11:00

73 lines
1.8 KiB
JavaScript

{% load i18n %}
{% load inventree_extras %}
/* globals
constructForm,
*/
/* exported
installPlugin,
locateItemOrLocation
*/
function installPlugin() {
constructForm(`/api/plugins/install/`, {
method: 'POST',
title: '{% trans "Install Plugin" %}',
fields: {
packagename: {},
url: {},
confirm: {},
},
onSuccess: function(data) {
msg = '{% trans "The Plugin was installed" %}';
showMessage(msg, {style: 'success', details: data.result, timeout: 30000});
}
});
}
function locateItemOrLocation(options={}) {
if (!options.item && !options.location) {
console.error(`locateItemOrLocation: Either 'item' or 'location' must be provided!`);
return;
}
function performLocate(plugin) {
inventreePut(
'{% url "api-locate-plugin" %}',
{
plugin: plugin,
item: options.item,
location: options.location,
},
{
method: 'POST',
},
);
}
// Request the list of available 'locate' plugins
inventreeGet(
`/api/plugins/`,
{
mixin: 'locate',
},
{
success: function(plugins) {
// No 'locate' plugins are available!
if (plugins.length == 0) {
console.warn(`No 'locate' plugins are available`);
} else if (plugins.length == 1) {
// Only a single locate plugin is available
performLocate(plugins[0].key);
} else {
// More than 1 location plugin available
// Select from a list
}
}
},
);
}