mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
Merge pull request #2957 from SchrodingersGat/locate-mixin
Adds plugin mixin to "locate" items
This commit is contained in:
@ -236,17 +236,13 @@ function selectLabel(labels, items, options={}) {
|
||||
if (plugins_enabled) {
|
||||
inventreeGet(
|
||||
`/api/plugin/`,
|
||||
{},
|
||||
{
|
||||
mixin: 'labels',
|
||||
},
|
||||
{
|
||||
async: false,
|
||||
success: function(response) {
|
||||
response.forEach(function(plugin) {
|
||||
// Look for active plugins which implement the 'labels' mixin class
|
||||
if (plugin.active && plugin.mixins && plugin.mixins.labels) {
|
||||
// This plugin supports label printing
|
||||
plugins.push(plugin);
|
||||
}
|
||||
});
|
||||
plugins = response;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -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(
|
||||
`/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
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user