mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Fix persist buttons (#4640)
Fixes "persist form" buttons for the following models: - Part - PartCategory - StockItem - StockLocation Closes https://github.com/inventree/InvenTree/issues/4491
This commit is contained in:
		@@ -334,18 +334,8 @@
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $("#cat-create").click(function() {
 | 
					    $("#cat-create").click(function() {
 | 
				
			||||||
 | 
					        createPartCategory({
 | 
				
			||||||
        var fields = categoryFields();
 | 
					            {% if category %}parent: {{ category.pk }},{% endif %}
 | 
				
			||||||
 | 
					 | 
				
			||||||
        {% if category %}
 | 
					 | 
				
			||||||
        fields.parent.value = {{ category.pk }};
 | 
					 | 
				
			||||||
        {% endif %}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        constructForm('{% url "api-part-category-list" %}', {
 | 
					 | 
				
			||||||
            fields: fields,
 | 
					 | 
				
			||||||
            method: 'POST',
 | 
					 | 
				
			||||||
            title: '{% trans "Create Part Category" %}',
 | 
					 | 
				
			||||||
            follow: true,
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -730,7 +730,7 @@ function insertPersistButton(options) {
 | 
				
			|||||||
    var html = `
 | 
					    var html = `
 | 
				
			||||||
    <div class="form-check form-switch">
 | 
					    <div class="form-check form-switch">
 | 
				
			||||||
        <input class="form-check-input" type="checkbox" id="modal-persist">
 | 
					        <input class="form-check-input" type="checkbox" id="modal-persist">
 | 
				
			||||||
        <label class="form-check-label" for="modal-persist">${message}</label>
 | 
					        <label class="form-check-label" for="modal-persist"><small>${message}</small></label>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
    `;
 | 
					    `;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* exported
 | 
					/* exported
 | 
				
			||||||
    createPart,
 | 
					    createPart,
 | 
				
			||||||
 | 
					    createPartCategory,
 | 
				
			||||||
    deletePart,
 | 
					    deletePart,
 | 
				
			||||||
    deletePartCategory,
 | 
					    deletePartCategory,
 | 
				
			||||||
    duplicateBom,
 | 
					    duplicateBom,
 | 
				
			||||||
@@ -253,8 +254,8 @@ function partFields(options={}) {
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Construct a set of fields for a PartCategory intance
 | 
					 * Construct a set of fields for a PartCategory intance
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function categoryFields() {
 | 
					function categoryFields(options={}) {
 | 
				
			||||||
    return {
 | 
					    let fields = {
 | 
				
			||||||
        parent: {
 | 
					        parent: {
 | 
				
			||||||
            help_text: '{% trans "Parent part category" %}',
 | 
					            help_text: '{% trans "Parent part category" %}',
 | 
				
			||||||
            required: false,
 | 
					            required: false,
 | 
				
			||||||
@@ -276,6 +277,28 @@ function categoryFields() {
 | 
				
			|||||||
            placeholder: 'fas fa-tag',
 | 
					            placeholder: 'fas fa-tag',
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (options.parent) {
 | 
				
			||||||
 | 
					        fields.parent.value = options.parent;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return fields;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Create a PartCategory via the API
 | 
				
			||||||
 | 
					function createPartCategory(options={}) {
 | 
				
			||||||
 | 
					    let fields = categoryFields(options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    constructForm('{% url "api-part-category-list" %}', {
 | 
				
			||||||
 | 
					        fields: fields,
 | 
				
			||||||
 | 
					        method: 'POST',
 | 
				
			||||||
 | 
					        title: '{% trans "Create Part Category" %}',
 | 
				
			||||||
 | 
					        follow: true,
 | 
				
			||||||
 | 
					        persist: true,
 | 
				
			||||||
 | 
					        persistMessage: '{% trans "Create new category after this one" %}',
 | 
				
			||||||
 | 
					        successMessage: '{% trans "Part category created" %}'
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -349,7 +372,7 @@ function createPart(options={}) {
 | 
				
			|||||||
        fields: partFields(options),
 | 
					        fields: partFields(options),
 | 
				
			||||||
        groups: partGroups(),
 | 
					        groups: partGroups(),
 | 
				
			||||||
        title: '{% trans "Create Part" %}',
 | 
					        title: '{% trans "Create Part" %}',
 | 
				
			||||||
        reloadFormAfterSuccess: true,
 | 
					        persist: true,
 | 
				
			||||||
        persistMessage: '{% trans "Create another part after this one" %}',
 | 
					        persistMessage: '{% trans "Create another part after this one" %}',
 | 
				
			||||||
        successMessage: '{% trans "Part created successfully" %}',
 | 
					        successMessage: '{% trans "Part created successfully" %}',
 | 
				
			||||||
        onSuccess: function(data) {
 | 
					        onSuccess: function(data) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -159,6 +159,9 @@ function createStockLocation(options={}) {
 | 
				
			|||||||
    options.method = 'POST';
 | 
					    options.method = 'POST';
 | 
				
			||||||
    options.fields = stockLocationFields(options);
 | 
					    options.fields = stockLocationFields(options);
 | 
				
			||||||
    options.title = '{% trans "New Stock Location" %}';
 | 
					    options.title = '{% trans "New Stock Location" %}';
 | 
				
			||||||
 | 
					    options.persist = true;
 | 
				
			||||||
 | 
					    options.persistMessage = '{% trans "Create another location after this one" %}';
 | 
				
			||||||
 | 
					    options.successMessage = '{% trans "Stock location created" %}';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructForm(url, options);
 | 
					    constructForm(url, options);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -473,6 +476,10 @@ function createNewStockItem(options={}) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    options.create = true;
 | 
					    options.create = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    options.persist = true;
 | 
				
			||||||
 | 
					    options.persistMessage = '{% trans "Create another item after this one" %}';
 | 
				
			||||||
 | 
					    options.successMessage = '{% trans "Stock item created" %}';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    options.fields = stockItemFields(options);
 | 
					    options.fields = stockItemFields(options);
 | 
				
			||||||
    options.groups = stockItemGroups(options);
 | 
					    options.groups = stockItemGroups(options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user