2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-29 14:24:25 +00:00

Implement a generic API endpoint for enumeration of status codes (#4543)

* Implement a generic API endpoint for enumeration of status codes

* Adds endpoint for PurchaseOrderStatus

* Add more endpoints (sales order / return orer)

* Add endpoints for StockStatus and StockTrackingCode

* Support build status

* Use the attribute name as the dict key

* Refactored status codes in javascript

- Now accessible by "name" (instead of integer key)
- Will make javascript code much more readable

* Bump API version
This commit is contained in:
Oliver
2023-03-31 07:27:24 +11:00
committed by GitHub
parent f4f7803e96
commit 327ecf2156
9 changed files with 189 additions and 61 deletions
+9 -31
View File
@@ -1,11 +1,15 @@
{% load report %}
/*
* Status codes for the {{ label }} model.
* Generated from the values specified in "status_codes.py"
*/
const {{ label }}Codes = {
{% for opt in options %}'{{ opt.key }}': {
key: '{{ opt.key }}',
value: '{{ opt.value }}',{% if opt.color %}
label: 'bg-{{ opt.color }}',{% endif %}
{% for entry in data %}
'{{ entry.name }}': {
key: {{ entry.key }},
value: '{{ entry.label }}',{% if entry.color %}
label: 'bg-{{ entry.color }}',{% endif %}
},
{% endfor %}
};
@@ -13,33 +17,7 @@ const {{ label }}Codes = {
/*
* Render the status for a {{ label }} object.
* Uses the values specified in "status_codes.py"
* This function is generated by the "status_codes.html" template
*/
function {{ label }}StatusDisplay(key, options={}) {
key = String(key);
var value = null;
var label = null;
if (key in {{ label }}Codes) {
value = {{ label }}Codes[key].value;
label = {{ label }}Codes[key].label;
}
// Fallback option for label
label = label || 'bg-dark';
if (value == null || value.length == 0) {
value = key;
label = '';
}
var classes = `badge rounded-pill ${label}`;
if (options.classes) {
classes += ' ' + options.classes;
}
return `<span class='${classes}'>${value}</span>`;
return renderStatusLabel(key, {{ label }}Codes, options);
}