2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Implement new approach for plugin settings

- URL specifies plugin slug and setting key
This commit is contained in:
Oliver Walters
2022-05-08 20:08:22 +10:00
parent f733e23b65
commit 3a9bacb27c
7 changed files with 91 additions and 24 deletions

View File

@ -24,7 +24,7 @@
<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.key.upper }}' type='checkbox' {% if setting.as_bool %}checked=''{% endif %} {% if plugin %}plugin='{{ plugin.pk }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}{% if notification_setting %}notification='{{request.user.id}}'{% 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.slug }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}{% if notification_setting %}notification='{{request.user.id}}'{% endif %}>
</div>
{% else %}
<div id='setting-{{ setting.pk }}'>
@ -41,7 +41,7 @@
</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.pk }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}>
<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 %}>
<span class='fas fa-edit icon-green'></span>
</button>
</div>

View File

@ -67,7 +67,6 @@
$('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 notification = $(this).attr('notification');
@ -78,7 +77,7 @@ $('table').find('.boolean-setting').change(function() {
var url = `/api/settings/global/${setting}/`;
if (plugin) {
url = `/api/plugin/settings/${pk}/`;
url = `/api/plugin/settings/${plugin}/${setting}/`;
} else if (user) {
url = `/api/settings/user/${setting}/`;
} else if (notification) {
@ -105,7 +104,6 @@ $('table').find('.boolean-setting').change(function() {
// 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');
var plugin = $(this).attr('plugin');
var is_global = true;
var notification = $(this).attr('notification');
@ -122,13 +120,11 @@ $('table').find('.btn-edit-setting').click(function() {
title = '{% trans "Edit Notification Setting" %}';
} else if (is_global) {
title = '{% trans "Edit Global Setting" %}';
pk = setting;
} else {
title = '{% trans "Edit User Setting" %}';
pk = setting;
}
editSetting(pk, {
editSetting(setting, {
plugin: plugin,
global: is_global,
notification: notification,

View File

@ -32,7 +32,7 @@ const plugins_enabled = false;
* Interactively edit a setting value.
* Launches a modal dialog form to adjut the value of the setting.
*/
function editSetting(pk, options={}) {
function editSetting(key, options={}) {
// Is this a global setting or a user setting?
var global = options.global || false;
@ -44,13 +44,13 @@ function editSetting(pk, options={}) {
var url = '';
if (plugin) {
url = `/api/plugin/settings/${pk}/`;
url = `/api/plugin/settings/${plugin}/${key}/`;
} else if (notification) {
url = `/api/settings/notification/${pk}/`;
} else if (global) {
url = `/api/settings/global/${pk}/`;
url = `/api/settings/global/${key}/`;
} else {
url = `/api/settings/user/${pk}/`;
url = `/api/settings/user/${key}/`;
}
var reload_required = false;