From 990b98769245f506c328283dc089509ccc9e4db6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 27 Jul 2021 17:03:37 +1000 Subject: [PATCH] Reload settings values "live" (without a page refresh) --- InvenTree/common/views.py | 17 +++++++++++++++ .../templates/InvenTree/settings/setting.html | 21 ++++++++++++------- .../InvenTree/settings/settings.html | 19 +++++++++++++++-- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/InvenTree/common/views.py b/InvenTree/common/views.py index 75fc78b4e3..6cac8bbb19 100644 --- a/InvenTree/common/views.py +++ b/InvenTree/common/views.py @@ -50,6 +50,23 @@ class SettingEdit(AjaxUpdateView): 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): """ Override default get_form behaviour diff --git a/InvenTree/templates/InvenTree/settings/setting.html b/InvenTree/templates/InvenTree/settings/setting.html index 66f3f9f3b0..e75c0b37d7 100644 --- a/InvenTree/templates/InvenTree/settings/setting.html +++ b/InvenTree/templates/InvenTree/settings/setting.html @@ -17,16 +17,21 @@ {% if setting.is_bool %}
- +
{% else %} - {% if setting.value %} - - {{ setting.value }} {{ setting.units }} - - {% else %} - {% trans "No value set" %} - {% endif %} +
+ + + {% if setting.value %} + {{ setting.value }} + {% else %} + {% trans "No value set" %} + {% endif %} + + + {{ setting.units }} +
{% endif %} {% trans setting.description %} diff --git a/InvenTree/templates/InvenTree/settings/settings.html b/InvenTree/templates/InvenTree/settings/settings.html index bb3284cf38..b5953f0aba 100644 --- a/InvenTree/templates/InvenTree/settings/settings.html +++ b/InvenTree/templates/InvenTree/settings/settings.html @@ -17,7 +17,7 @@ {% include "InvenTree/settings/user.html" %} {% include "InvenTree/settings/user_settings.html" %} {% include "InvenTree/settings/user_homepage.html" %} -{% include "InvenTree/settings/user_search.html" %} +{% include "InvenTree/settings/user_homepage.html" %} {% if user.is_staff %} @@ -54,7 +54,22 @@ $('table').find('.btn-edit-setting').click(function() { launchModalForm( 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); + } + } } ); });