2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-07 12:22:11 +00:00

Improvements for status code generation

- Now includes labels
- Python template generates javascript which is then rendered? I don't even follow it any more
This commit is contained in:
Oliver Walters
2020-04-11 20:48:02 +10:00
parent 5d70f496a5
commit ba7c0bdea0
6 changed files with 81 additions and 24 deletions

View File

@@ -0,0 +1,27 @@
var {{ label }}Codes = {
{% for opt in options %}'{{ opt.key }}': {
key: '{{ opt.key }}',
value: '{{ opt.value }}',{% if opt.label %}
label: '{{ opt.label }}',{% endif %}
},{% endfor %}
};
function {{ label }}StatusDisplay(key) {
key = String(key);
var label = {{ label }}Codes[key].label;
var value = {{ label }}Codes[key].value;
if (value == null || value.length == 0) {
value = key;
}
// Label not found, return the original string
if (label == null || label.length == 0) {
return value;
}
return `<span class='label label-${label}'>${value}</span>`;
}

View File

@@ -5,6 +5,11 @@
<script type='text/javascript'>
{% include "status_codes.html" with label='stock' options=stock_status_codes %}
{% include "status_codes.html" with label='build' options=build_status_codes %}
{% include "status_codes.html" with label='order' options=order_status_codes %}
function getAvailableTableFilters(tableKey) {
tableKey = tableKey.toLowerCase();
@@ -23,10 +28,7 @@ function getAvailableTableFilters(tableKey) {
description: '{% trans "Show stock for active parts" %}',
},
'status': {
options: {
{% for opt in stock_status_codes %}'{{ opt.value }}': '{{ opt.key }}',
{% endfor %}
},
options: stockCodes,
title: '{% trans "Stock status" %}',
description: '{% trans "Stock status" %}',
},
@@ -38,10 +40,7 @@ function getAvailableTableFilters(tableKey) {
return {
status: {
title: '{% trans "Build status" %}',
options: {
{% for opt in build_status_codes %}'{{ opt.value }}': '{{ opt.key }}',
{% endfor %}
},
options: buildCodes,
},
};
@@ -52,10 +51,7 @@ function getAvailableTableFilters(tableKey) {
return {
status: {
title: '{% trans "Order status" %}',
options: {
{% for opt in order_status_codes %}'{{ opt.value }}': '{{ opt.key }}',
{% endfor %}
},
options: orderCodes,
},
};
}