Boolean settings are now directly clickable

This commit is contained in:
Oliver 2022-02-03 15:25:21 +11:00
parent 0d6cdb1761
commit ababab944b
2 changed files with 39 additions and 1 deletions

View File

@ -19,7 +19,7 @@
<td>
{% if setting.is_bool %}
<div class='form-check form-switch'>
<input class='form-check-input' fieldname='{{ setting.key.upper }}' id='setting-value-{{ setting.key.upper }}' type='checkbox' disabled='' {% if setting.as_bool %}checked=''{% endif %}>
<input class='form-check-input boolean-setting' fieldname='{{ setting.key.upper }}' pk='{{ setting.pk }}' setting='{{ setting.key.upper }}' id='setting-value-{{ setting.key.upper }}' type='checkbox' {% if setting.as_bool %}checked=''{% endif %} {% if plugin %}plugin='{{ plugin.pk }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}>
</div>
{% else %}
<div id='setting-{{ setting.pk }}'>
@ -37,10 +37,12 @@
{{ setting.description }}
</td>
<td>
{% if not setting.is_bool %}
<div class='btn-group float-right'>
<button class='btn btn-outline-secondary btn-small btn-edit-setting' pk='{{ setting.pk }}' setting='{{ setting.key.upper }}' title='{% trans "Edit setting" %}' {% if plugin %}plugin='{{ plugin.pk }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}>
<span class='fas fa-edit icon-green'></span>
</button>
</div>
{% endif %}
</td>
</tr>

View File

@ -62,6 +62,42 @@
{% block js_ready %}
{{ block.super }}
// Callback for when boolean settings are edited
$('table').find('.boolean-setting').change(function() {
var setting = $(this).attr('setting');
var pk = $(this).attr('pk');
var plugin = $(this).attr('plugin');
var user = $(this).attr('user');
var checked = this.checked;
// Global setting by default
var url = `/api/settings/global/${pk}/`;
if (plugin) {
url = `/api/plugin/settings/${pk}/`;
} else if (user) {
url = `/api/settings/user/${pk}/`;
}
inventreePut(
url,
{
value: checked.toString(),
},
{
method: 'PATCH',
onSuccess: function(data) {
},
error: function(xhr) {
}
}
);
});
// Callback for when non-boolean settings are edited
$('table').find('.btn-edit-setting').click(function() {
var setting = $(this).attr('setting');
var pk = $(this).attr('pk');