From 2ce5b7c896266ac01eaabebdf4d67c71b9f1a257 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 28 Mar 2022 20:25:47 +1100 Subject: [PATCH 1/5] Make plugins_enabled variable available to javascript code --- InvenTree/templates/js/dynamic/settings.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/InvenTree/templates/js/dynamic/settings.js b/InvenTree/templates/js/dynamic/settings.js index 4e7d36f72b..4dd6f8c6e6 100644 --- a/InvenTree/templates/js/dynamic/settings.js +++ b/InvenTree/templates/js/dynamic/settings.js @@ -20,6 +20,12 @@ const global_settings = { {% endfor %} }; +{% if plugins_enabled %} +const plugins_enabled = true; +{% else %} +const plugins_enabled = false; +{% endif %} + /* * Edit a setting value */ From 05344a3675b1e35a299c4214458c4e52ceb6cd4c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 28 Mar 2022 20:36:34 +1100 Subject: [PATCH 2/5] Only check for label printing plugins if plugins are enabled --- InvenTree/InvenTree/version.py | 2 +- InvenTree/templates/js/dynamic/settings.js | 3 +- InvenTree/templates/js/translated/label.js | 35 ++++++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index f97f134e4a..8d9b0e8da1 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -196,7 +196,7 @@ def isInvenTreeUpToDate(): and stores it to the database as INVENTREE_LATEST_VERSION """ - latest = common.models.InvenTreeSetting.get_setting('INVENTREE_LATEST_VERSION', None) + latest = common.models.InvenTreeSetting.get_setting('INVENTREE_LATEST_VERSION', backup_value=None, create=False) # No record for "latest" version - we must assume we are up to date! if not latest: diff --git a/InvenTree/templates/js/dynamic/settings.js b/InvenTree/templates/js/dynamic/settings.js index 4dd6f8c6e6..79c0d3e213 100644 --- a/InvenTree/templates/js/dynamic/settings.js +++ b/InvenTree/templates/js/dynamic/settings.js @@ -20,7 +20,8 @@ const global_settings = { {% endfor %} }; -{% if plugins_enabled %} +{% plugins_enabled as p_en %} +{% if p_en %} const plugins_enabled = true; {% else %} const plugins_enabled = false; diff --git a/InvenTree/templates/js/translated/label.js b/InvenTree/templates/js/translated/label.js index c0f4c2f735..d19c403861 100644 --- a/InvenTree/templates/js/translated/label.js +++ b/InvenTree/templates/js/translated/label.js @@ -10,6 +10,7 @@ modalSetTitle, modalSubmit, openModal, + plugins_enabled, showAlertDialog, */ @@ -232,26 +233,28 @@ function selectLabel(labels, items, options={}) { var plugins = []; // Request a list of available label printing plugins from the server - inventreeGet( - `/api/plugin/`, - {}, - { - 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); - } - }); + if (plugins_enabled) { + inventreeGet( + `/api/plugin/`, + {}, + { + 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); + } + }); + } } - } - ); + ); + } var plugin_selection = ''; - if (plugins.length > 0) { + if (plugins_enabled && plugins.length > 0) { plugin_selection =`
@@ -181,6 +183,7 @@
+ {% if labels_enabled %}
+ {% endif %} {% include "filter_list.html" with id="location" %}
@@ -222,6 +226,15 @@ ] ); + {% if labels_enabled %} + $('#print-label').click(function() { + + var locs = [{{ location.pk }}]; + + printStockLocationLabels(locs); + + }); + $('#multi-location-print-label').click(function() { var selections = $('#sublocation-table').bootstrapTable('getSelections'); @@ -234,6 +247,7 @@ printStockLocationLabels(locations); }); + {% endif %} {% if location %} $("#barcode-check-in").click(function() { @@ -298,14 +312,6 @@ adjustLocationStock('move'); }); - $('#print-label').click(function() { - - var locs = [{{ location.pk }}]; - - printStockLocationLabels(locs); - - }); - {% endif %} $('#show-qr-code').click(function() { diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index f916344bf9..3791d5f059 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -6,6 +6,7 @@ {% settings_value 'REPORT_ENABLE_TEST_REPORT' as test_report_enabled %} {% settings_value "REPORT_ENABLE" as report_enabled %} {% settings_value "SERVER_RESTART_REQUIRED" as server_restart_required %} +{% settings_value "LABEL_ENABLE" with user=user as labels_enabled %} {% inventree_demo_mode as demo_mode %} From 89d0e41ebc3a7596220e7475ea20089e4979cd3a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 28 Mar 2022 20:59:34 +1100 Subject: [PATCH 5/5] JS lint fix --- InvenTree/templates/js/dynamic/settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/templates/js/dynamic/settings.js b/InvenTree/templates/js/dynamic/settings.js index 79c0d3e213..2832bd3482 100644 --- a/InvenTree/templates/js/dynamic/settings.js +++ b/InvenTree/templates/js/dynamic/settings.js @@ -4,6 +4,7 @@ editSetting, user_settings, global_settings, + plugins_enabled, */ {% user_settings request.user as USER_SETTINGS %}