From ababab944bcd72372ea625d6e500487d09a9cca7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Feb 2022 15:25:21 +1100 Subject: [PATCH 1/3] Boolean settings are now directly clickable --- .../templates/InvenTree/settings/setting.html | 4 ++- .../InvenTree/settings/settings.html | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/InvenTree/settings/setting.html b/InvenTree/templates/InvenTree/settings/setting.html index 16fc67ef86..dc15760ef5 100644 --- a/InvenTree/templates/InvenTree/settings/setting.html +++ b/InvenTree/templates/InvenTree/settings/setting.html @@ -19,7 +19,7 @@ {% if setting.is_bool %}
- +
{% else %}
@@ -37,10 +37,12 @@ {{ setting.description }} + {% if not setting.is_bool %}
+ {% endif %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/settings/settings.html b/InvenTree/templates/InvenTree/settings/settings.html index 5fcd18644f..4b6c9e9320 100644 --- a/InvenTree/templates/InvenTree/settings/settings.html +++ b/InvenTree/templates/InvenTree/settings/settings.html @@ -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'); From 5cd5ee81aff86dbce4f5363b5834aedaa7ceda2e Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Feb 2022 15:30:36 +1100 Subject: [PATCH 2/3] Layout changes --- .../templates/InvenTree/settings/setting.html | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/InvenTree/templates/InvenTree/settings/setting.html b/InvenTree/templates/InvenTree/settings/setting.html index dc15760ef5..743e37bf8e 100644 --- a/InvenTree/templates/InvenTree/settings/setting.html +++ b/InvenTree/templates/InvenTree/settings/setting.html @@ -16,6 +16,9 @@ {% endif %} {{ setting.name }} + + {{ setting.description }} + {% if setting.is_bool %}
@@ -31,18 +34,12 @@ {% endif %} {{ setting.units }} -
- {% endif %} - - {{ setting.description }} - - - {% if not setting.is_bool %} -
- +
+ +
{% endif %} - \ No newline at end of file + From bf528db4ab585744b57e1eb11d70de7004120a35 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Feb 2022 15:46:44 +1100 Subject: [PATCH 3/3] Display error if setting update failes --- InvenTree/templates/InvenTree/settings/settings.html | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/templates/InvenTree/settings/settings.html b/InvenTree/templates/InvenTree/settings/settings.html index 4b6c9e9320..ba27187747 100644 --- a/InvenTree/templates/InvenTree/settings/settings.html +++ b/InvenTree/templates/InvenTree/settings/settings.html @@ -91,6 +91,7 @@ $('table').find('.boolean-setting').change(function() { onSuccess: function(data) { }, error: function(xhr) { + showApiError(xhr, url); } } );