mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-07 04:12:11 +00:00
Merge pull request #2957 from SchrodingersGat/locate-mixin
Adds plugin mixin to "locate" items
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
{% load i18n %}
|
||||
{% load inventree_extras %}
|
||||
|
||||
{% plugins_enabled as plugins_enabled %}
|
||||
{% settings_value 'BARCODE_ENABLE' as barcodes %}
|
||||
{% settings_value 'REPORT_ENABLE_TEST_REPORT' as test_report_enabled %}
|
||||
{% settings_value "REPORT_ENABLE" as report_enabled %}
|
||||
|
@@ -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