Bug fix for boolean settings (#3760)

* Fix for boolean settings

- Ensure "user" attribute is provided
- Fix for *all* boolean user settings

* Refactor boolean setting into separate template

* Fix order-of-operations

* Fix settings for specific plugins
This commit is contained in:
Oliver 2022-10-08 23:46:08 +11:00 committed by GitHub
parent fbc99257bd
commit cc68cd83a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 7 deletions

View File

@ -23,9 +23,7 @@
</td>
<td>
{% if setting.is_bool %}
<div class='form-check form-switch'>
<input class='form-check-input boolean-setting' fieldname='{{ setting.key.upper }}' pk='{{ setting.pk }}' setting='{{ setting.key.upper }}' id='setting-value-{{ setting.pk }}-{{ setting.typ }}' type='checkbox' {% if setting.as_bool %}checked=''{% endif %}{{reference}}>
</div>
{% include "InvenTree/settings/setting_boolean.html" %}
{% else %}
<div id='setting-{{ setting.pk }}'>
<span id='setting-value-{{ setting.pk }}-{{ setting.typ }}' fieldname='{{ setting.key.upper }}'>
@ -41,7 +39,18 @@
</span>
{{ setting.units }}
<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.slug }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}>
<button
class='btn btn-outline-secondary btn-small btn-edit-setting'
title='{% trans "Edit setting" %}'
pk='{{ setting.pk }}'
setting='{{ setting.key.upper }}'
{% if plugin %}plugin='{{ plugin.slug }}'{% endif %}
{% if user_setting or notification_setting %}user='{{request.user.id}}'{% endif %}
{% if notification_setting %}
notification=true
method='{{ setting.method }}'
{% endif %}
>
<span class='fas fa-edit icon-green'></span>
</button>
</div>

View File

@ -0,0 +1,18 @@
<div class='form-check form-switch'>
<input
class='form-check-input boolean-setting'
fieldname='{{ setting.key.upper }}'
pk='{{ setting.pk }}'
setting='{{ setting.key.upper }}'
id='setting-value-{{setting.pk }}-{{ setting.typ }}'
type='checkbox'
{% if setting.as_bool %}checked=''{% endif %}
{{ reference }}
{% if plugin %}plugin='{{ plugin.slug }}'{% endif %}
{% if user_setting or notification_setting %}user='{{ request.user.pk }}'{% endif %}
{% if notification_setting %}
notification=true
method='{{ setting.method }}'
{% endif %}
>
</div>

View File

@ -78,12 +78,12 @@ $('table').find('.boolean-setting').change(function() {
// Global setting by default
var url = `/api/settings/global/${setting}/`;
if (plugin) {
if (notification) {
url = `/api/settings/notification/${pk}/`;
} else if (plugin) {
url = `/api/plugin/settings/${plugin}/${setting}/`;
} else if (user) {
url = `/api/settings/user/${setting}/`;
} else if (notification) {
url = `/api/settings/notification/${pk}/`;
}
inventreePut(