mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	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:
		@@ -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>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								InvenTree/templates/InvenTree/settings/setting_boolean.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								InvenTree/templates/InvenTree/settings/setting_boolean.html
									
									
									
									
									
										Normal 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>
 | 
			
		||||
@@ -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(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user