mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Reload settings values "live" (without a page refresh)
This commit is contained in:
parent
46d5a6f00b
commit
990b987692
@ -50,6 +50,23 @@ class SettingEdit(AjaxUpdateView):
|
|||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
"""
|
||||||
|
Custom data to return to the client after POST success
|
||||||
|
"""
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
setting = self.get_object()
|
||||||
|
|
||||||
|
data['pk'] = setting.pk
|
||||||
|
data['key'] = setting.key
|
||||||
|
data['value'] = setting.value
|
||||||
|
data['is_bool'] = setting.is_bool()
|
||||||
|
data['is_int'] = setting.is_int()
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def get_form(self):
|
def get_form(self):
|
||||||
"""
|
"""
|
||||||
Override default get_form behaviour
|
Override default get_form behaviour
|
||||||
|
@ -17,16 +17,21 @@
|
|||||||
<td>
|
<td>
|
||||||
{% if setting.is_bool %}
|
{% if setting.is_bool %}
|
||||||
<div>
|
<div>
|
||||||
<input fieldname='{{ setting.key }}' class='slidey' type='checkbox' data-offstyle='warning' data-onstyle='success' data-size='small' data-toggle='toggle' disabled autocomplete='off' {% if setting.as_bool %}checked=''{% endif %}>
|
<input fieldname='{{ setting.key }}' id='setting-value-{{ setting.key }}' type='checkbox' disabled='' {% if setting.as_bool %}checked=''{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<div id='setting-{{ setting.pk }}'>
|
||||||
|
<b>
|
||||||
|
<span id='setting-value-{{ setting.key }}'>
|
||||||
{% if setting.value %}
|
{% if setting.value %}
|
||||||
<i><b>
|
{{ setting.value }}
|
||||||
{{ setting.value }}</b> {{ setting.units }}
|
|
||||||
</i>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<i>{% trans "No value set" %}</i>
|
<i>{% trans "No value set" %}</i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</b>
|
||||||
|
{{ setting.units }}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>
|
<td>
|
||||||
{% trans setting.description %}
|
{% trans setting.description %}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
{% include "InvenTree/settings/user.html" %}
|
{% include "InvenTree/settings/user.html" %}
|
||||||
{% include "InvenTree/settings/user_settings.html" %}
|
{% include "InvenTree/settings/user_settings.html" %}
|
||||||
{% include "InvenTree/settings/user_homepage.html" %}
|
{% include "InvenTree/settings/user_homepage.html" %}
|
||||||
{% include "InvenTree/settings/user_search.html" %}
|
{% include "InvenTree/settings/user_homepage.html" %}
|
||||||
|
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
|
|
||||||
@ -54,7 +54,22 @@ $('table').find('.btn-edit-setting').click(function() {
|
|||||||
launchModalForm(
|
launchModalForm(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
reload: true,
|
success: function(response) {
|
||||||
|
|
||||||
|
console.log(`setting ${pk} -> ${response.value}`);
|
||||||
|
|
||||||
|
if (response.is_bool) {
|
||||||
|
var enabled = response.value.toLowerCase() == 'true';
|
||||||
|
|
||||||
|
console.log("bool result:", enabled);
|
||||||
|
|
||||||
|
$(`#setting-value-${setting}`).prop('checked', enabled);
|
||||||
|
} else {
|
||||||
|
$(`#setting-value-${setting}`).html(response.value);
|
||||||
|
|
||||||
|
console.log("Normal result:", response.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user