From 4381a16b0e5aa0ad36e2deca26c676ac5bde5398 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 29 Jul 2021 12:31:07 +1000 Subject: [PATCH] Template cleanup --- InvenTree/build/templates/build/index.html | 2 +- InvenTree/common/models.py | 1 + .../templates/company/company_base.html | 21 +++++----- .../order/templates/order/order_base.html | 2 +- .../templates/order/sales_order_base.html | 2 +- .../order/templates/order/sales_orders.html | 2 +- InvenTree/part/templates/part/part_base.html | 21 +++++----- InvenTree/templates/js/dynamic/inventree.js | 6 +-- InvenTree/templates/js/translated/build.js | 6 +-- InvenTree/templates/js/translated/stock.js | 41 ++++++++++--------- 10 files changed, 50 insertions(+), 54 deletions(-) diff --git a/InvenTree/build/templates/build/index.html b/InvenTree/build/templates/build/index.html index d5e6484d56..6b0d9163eb 100644 --- a/InvenTree/build/templates/build/index.html +++ b/InvenTree/build/templates/build/index.html @@ -82,7 +82,7 @@ }, { success: function(response) { - var prefix = '{% settings_value "BUILDORDER_REFERENCE_PREFIX" %}'; + var prefix = global_settings.BUILDORDER_REFERENCE_PREFIX; for (var idx = 0; idx < response.length; idx++) { diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 935990e074..53c6c03df7 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -812,6 +812,7 @@ class InvenTreeSetting(BaseInvenTreeSetting): help_text=_('Settings key (must be unique - case insensitive'), ) + class InvenTreeUserSetting(BaseInvenTreeSetting): """ An InvenTreeSetting object with a usercontext diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index 3b8f1e7734..c50a9490f0 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -198,17 +198,16 @@ ); }); - {% settings_value "INVENTREE_DOWNLOAD_FROM_URL" as allow_download %} + if (global_settings.INVENTREE_DOWNLOAD_FROM_URL) { - {% if allow_download %} - $('#company-image-url').click(function() { - launchModalForm( - '{% url "company-image-download" company.id %}', - { - reload: true, - } - ) - }); - {% endif %} + $('#company-image-url').click(function() { + launchModalForm( + '{% url "company-image-download" company.id %}', + { + reload: true, + } + ) + }); + } {% endblock %} \ No newline at end of file diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index 11396e07a7..0d46207c33 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -164,7 +164,7 @@ $("#edit-order").click(function() { constructForm('{% url "api-po-detail" order.pk %}', { fields: { reference: { - prefix: "{% settings_value 'PURCHASEORDER_REFERENCE_PREFIX' %}", + prefix: global_settings.PURCHASEORDER_REFERENCE_PREFIX, }, {% if order.lines.count == 0 and order.status == PurchaseOrderStatus.PENDING %} supplier: { diff --git a/InvenTree/order/templates/order/sales_order_base.html b/InvenTree/order/templates/order/sales_order_base.html index 60099a2578..6f8c422f7a 100644 --- a/InvenTree/order/templates/order/sales_order_base.html +++ b/InvenTree/order/templates/order/sales_order_base.html @@ -157,7 +157,7 @@ $("#edit-order").click(function() { constructForm('{% url "api-so-detail" order.pk %}', { fields: { reference: { - prefix: "{% settings_value 'SALESORDER_REFERENCE_PREFIX' %}", + prefix: global_settings.SALESORDER_REFERENCE_PREFIX, }, {% if order.lines.count == 0 and order.status == SalesOrderStatus.PENDING %} customer: { diff --git a/InvenTree/order/templates/order/sales_orders.html b/InvenTree/order/templates/order/sales_orders.html index d4ebbd4ca8..71ffbc212f 100644 --- a/InvenTree/order/templates/order/sales_orders.html +++ b/InvenTree/order/templates/order/sales_orders.html @@ -67,7 +67,7 @@ { success: function(response) { - var prefix = '{% settings_value "SALESORDER_REFERENCE_PREFIX" %}'; + var prefix = global_settings.SALESORDER_REFERENCE_PREFIX; for (var idx = 0; idx < response.length; idx++) { var order = response[idx]; diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 9fe6c7b486..d7b196917d 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -394,17 +394,16 @@ {% if roles.part.change %} - {% settings_value "INVENTREE_DOWNLOAD_FROM_URL" as allow_download %} - {% if allow_download %} - $("#part-image-url").click(function() { - launchModalForm( - '{% url "part-image-download" part.id %}', - { - reload: true, - } - ); - }); - {% endif %} + if (global_settings.INVENTREE_DOWNLOAD_FROM_URL) { + $("#part-image-url").click(function() { + launchModalForm( + '{% url "part-image-download" part.id %}', + { + reload: true, + } + ); + }); + } $("#part-image-select").click(function() { launchModalForm("{% url 'part-image-select' part.id %}", diff --git a/InvenTree/templates/js/dynamic/inventree.js b/InvenTree/templates/js/dynamic/inventree.js index aa87008fbe..21e667adcb 100644 --- a/InvenTree/templates/js/dynamic/inventree.js +++ b/InvenTree/templates/js/dynamic/inventree.js @@ -91,11 +91,7 @@ function inventreeDocReady() { url: '/api/part/', data: { search: request.term, - {% if request.user %} - limit: {% settings_value 'SEARCH_PREVIEW_RESULTS' user=request.user %}, - {% else %} - limit: 25, - {% endif %} + limit: user_settings.SEARCH_PREVIEW_RESULTS, offset: 0 }, success: function (data) { diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index f43de6ec2b..4b8cd47eb5 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -5,7 +5,7 @@ function buildFormFields() { return { reference: { - prefix: "{% settings_value 'BUILDORDER_REFERENCE_PREFIX' %}", + prefix: global_settings.BUILDORDER_REFERENCE_PREFIX, }, title: {}, part: {}, @@ -232,7 +232,7 @@ function loadBuildOrderAllocationTable(table, options={}) { switchable: false, title: '{% trans "Build Order" %}', formatter: function(value, row) { - var prefix = "{% settings_value 'BUILDORDER_REFERENCE_PREFIX' %}"; + var prefix = global_settings.BUILDORDER_REFERENCE_PREFIX; var ref = `${prefix}${row.build_detail.reference}`; @@ -848,7 +848,7 @@ function loadBuildTable(table, options) { switchable: true, formatter: function(value, row, index, field) { - var prefix = "{% settings_value 'BUILDORDER_REFERENCE_PREFIX' %}"; + var prefix = global_settings.BUILDORDER_REFERENCE_PREFIX; if (prefix) { value = `${prefix}${value}`; diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index a2015797fe..c573694724 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -6,8 +6,6 @@ * Requires api.js to be loaded first */ -{% settings_value 'BARCODE_ENABLE' as barcodes %} - function stockStatusCodes() { return [ {% for code in StockStatus.list %} @@ -1037,7 +1035,7 @@ function loadStockTable(table, options) { if (row.purchase_order_reference) { - var prefix = '{% settings_value "PURCHASEORDER_REFERENCE_PREFIX" %}'; + var prefix = global_settings.PURCHASEORDER_REFERENCE_PREFIX; text = prefix + row.purchase_order_reference; } @@ -1090,15 +1088,18 @@ function loadStockTable(table, options) { } */ + var buttons = [ + '#stock-print-options', + '#stock-options'; + ]; + + if (global_settings.BARCODE_ENABLE) { + buttons.push('#stock-barcode-options'); + } + linkButtonsToSelection( table, - [ - '#stock-print-options', - {% if barcodes %} - '#stock-barcode-options', - {% endif %} - '#stock-options', - ] + buttons, ); @@ -1138,19 +1139,19 @@ function loadStockTable(table, options) { printTestReports(items); }) - {% if barcodes %} - $('#multi-item-barcode-scan-into-location').click(function() { - var selections = $('#stock-table').bootstrapTable('getSelections'); + if (global_settings.BARCODE_ENABLE) { + $('#multi-item-barcode-scan-into-location').click(function() { + var selections = $('#stock-table').bootstrapTable('getSelections'); - var items = []; + var items = []; - selections.forEach(function(item) { - items.push(item.pk); - }) + selections.forEach(function(item) { + items.push(item.pk); + }) - scanItemsIntoLocation(items); - }); - {% endif %} + scanItemsIntoLocation(items); + }); + } $('#multi-item-stocktake').click(function() { stockAdjustment('count');