mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add user settings to remember the last/favourite label template (#4938)
* Add user settings to remember the last/favourite label template Fixes #4932 * Remove settings_value from translated templates Thanks Oliver for the hint!
This commit is contained in:
parent
18d9ecd0f4
commit
46a808c064
@ -2100,7 +2100,35 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
|
|||||||
MinValueValidator(0),
|
MinValueValidator(0),
|
||||||
],
|
],
|
||||||
'default': 100,
|
'default': 100,
|
||||||
}
|
},
|
||||||
|
|
||||||
|
'DEFAULT_PART_LABEL_TEMPLATE': {
|
||||||
|
'name': _('Default part label template'),
|
||||||
|
'description': _('The part label template to be automatically selected'),
|
||||||
|
'validator': [
|
||||||
|
int,
|
||||||
|
],
|
||||||
|
'default': '',
|
||||||
|
},
|
||||||
|
|
||||||
|
'DEFAULT_ITEM_LABEL_TEMPLATE': {
|
||||||
|
'name': _('Default stock item template'),
|
||||||
|
'description': _('The stock item label template to be automatically selected'),
|
||||||
|
'validator': [
|
||||||
|
int,
|
||||||
|
],
|
||||||
|
'default': '',
|
||||||
|
},
|
||||||
|
|
||||||
|
'DEFAULT_LOCATION_LABEL_TEMPLATE': {
|
||||||
|
'name': _('Default stock location label template'),
|
||||||
|
'description': _('The stock location label template to be automatically selected'),
|
||||||
|
'validator': [
|
||||||
|
int,
|
||||||
|
],
|
||||||
|
'default': '',
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typ = 'user'
|
typ = 'user'
|
||||||
|
@ -148,6 +148,8 @@ class LabelPrintMixin(LabelFilterMixin):
|
|||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
"""Perform a GET request against this endpoint to print labels"""
|
"""Perform a GET request against this endpoint to print labels"""
|
||||||
|
common.models.InvenTreeUserSetting.set_setting('DEFAULT_' + self.ITEM_KEY.upper() + '_LABEL_TEMPLATE',
|
||||||
|
self.get_object().pk, None, user=request.user)
|
||||||
return self.print(request, self.get_items())
|
return self.print(request, self.get_items())
|
||||||
|
|
||||||
def get_plugin(self, request):
|
def get_plugin(self, request):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load static %}
|
||||||
|
{% load inventree_extras %}
|
||||||
/* globals
|
/* globals
|
||||||
attachSelect,
|
attachSelect,
|
||||||
closeModal,
|
closeModal,
|
||||||
@ -29,7 +30,6 @@
|
|||||||
* (via AJAX) from the server.
|
* (via AJAX) from the server.
|
||||||
*/
|
*/
|
||||||
function selectLabel(labels, items, options={}) {
|
function selectLabel(labels, items, options={}) {
|
||||||
|
|
||||||
// Array of available plugins for label printing
|
// Array of available plugins for label printing
|
||||||
var plugins = [];
|
var plugins = [];
|
||||||
|
|
||||||
@ -78,7 +78,6 @@ function selectLabel(labels, items, options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var modal = options.modal || '#modal-form';
|
var modal = options.modal || '#modal-form';
|
||||||
|
|
||||||
var label_list = makeOptionsList(
|
var label_list = makeOptionsList(
|
||||||
labels,
|
labels,
|
||||||
function(item) {
|
function(item) {
|
||||||
@ -92,6 +91,16 @@ function selectLabel(labels, items, options={}) {
|
|||||||
},
|
},
|
||||||
function(item) {
|
function(item) {
|
||||||
return item.pk;
|
return item.pk;
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
function(item) {
|
||||||
|
if (options.key == 'part')
|
||||||
|
return item.key == user_settings.DEFAULT_PART_LABEL_TEMPLATE;
|
||||||
|
else if (options.key == 'location')
|
||||||
|
return item.key == user_settings.DEFAULT_LOCATION_LABEL_TEMPLATE;
|
||||||
|
else if (options.key == 'stock')
|
||||||
|
return item.key == user_settings.DEFAULT_STOCK_LABEL_TEMPLATE;
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -214,6 +223,7 @@ function printLabels(options) {
|
|||||||
},
|
},
|
||||||
plural_name: options.plural_name,
|
plural_name: options.plural_name,
|
||||||
singular_name: options.singular_name,
|
singular_name: options.singular_name,
|
||||||
|
key: options.key,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -174,7 +174,7 @@ function enableSubmitButton(options, enable=true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function makeOption(text, value, title) {
|
function makeOption(text, value, title, selected) {
|
||||||
/* Format an option for a select element
|
/* Format an option for a select element
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -184,6 +184,9 @@ function makeOption(text, value, title) {
|
|||||||
html += ` title='${title}'`;
|
html += ` title='${title}'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
html += 'selected="selected"';
|
||||||
|
}
|
||||||
html += `>${text}</option>`;
|
html += `>${text}</option>`;
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
@ -200,8 +203,9 @@ function makeOption(text, value, title) {
|
|||||||
* - textFunc: Function which takes an element and generates the text to be displayed
|
* - textFunc: Function which takes an element and generates the text to be displayed
|
||||||
* - valueFunc: optional function which takes an element and generates the value
|
* - valueFunc: optional function which takes an element and generates the value
|
||||||
* - titleFunc: optional function which takes an element and generates a title
|
* - titleFunc: optional function which takes an element and generates a title
|
||||||
|
* - selectedFunc: optional function which takes an element and generate true if the given item should be added as selected
|
||||||
*/
|
*/
|
||||||
function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
|
function makeOptionsList(elements, textFunc, valueFunc, titleFunc, selectedFunc) {
|
||||||
|
|
||||||
var options = [];
|
var options = [];
|
||||||
|
|
||||||
@ -210,6 +214,7 @@ function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
|
|||||||
var text = textFunc(element);
|
var text = textFunc(element);
|
||||||
var value = null;
|
var value = null;
|
||||||
var title = null;
|
var title = null;
|
||||||
|
var selected = null;
|
||||||
|
|
||||||
if (valueFunc) {
|
if (valueFunc) {
|
||||||
value = valueFunc(element);
|
value = valueFunc(element);
|
||||||
@ -221,7 +226,11 @@ function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
|
|||||||
title = titleFunc(element);
|
title = titleFunc(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
options.push(makeOption(text, value, title));
|
if (selectedFunc) {
|
||||||
|
selected = selectedFunc(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.push(makeOption(text, value, title, selected));
|
||||||
});
|
});
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
Loading…
Reference in New Issue
Block a user