2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00
2022-05-10 01:18:36 +10:00

75 lines
1.8 KiB
JavaScript

{% load i18n %}
{% load inventree_extras %}
/* globals
constructForm,
*/
/* exported
installPlugin,
locateItemOrLocation
*/
function installPlugin() {
constructForm(`/api/plugin/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/plugin/`,
{
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
}
}
},
);
}