2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Adds an endpoint for calling the plugin code to "locate" something

This commit is contained in:
Oliver Walters
2022-05-09 23:42:28 +10:00
parent 9b7c26ec9c
commit 57f3efe758
5 changed files with 135 additions and 2 deletions

View File

@ -7,6 +7,7 @@
/* exported
installPlugin,
locateItemOrLocation
*/
function installPlugin() {
@ -24,3 +25,50 @@ function installPlugin() {
}
});
}
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(
'{% url "api-plugin-list" %}',
{
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
}
}
},
);
}