mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Convert category parameter forms to use the API (#3130)
* Moving PartCategoryParameterTemplate model to the API - Add detail API endpoint - Add 'create' action to LIST endpoint * Update settings page to use the new API forms * Remove old views / forms * Update API version * Fix table buttons * Add title to deletion form * Add unit tests for new API views
This commit is contained in:
@ -8,14 +8,14 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block actions %}
|
||||
<button class='btn btn-success' id='new-cat-param' disabled=''>
|
||||
<button class='btn btn-success' id='new-cat-param'>
|
||||
<div class='fas fa-plus-circle'></div> {% trans "New Parameter" %}
|
||||
</button>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class='row'>
|
||||
<div class='row' id='cat-param-buttons'>
|
||||
<form action=''>
|
||||
<div class='col-sm-6' style='width: 250px'>
|
||||
<div class='form-group'><div class='controls'>
|
||||
|
@ -222,7 +222,7 @@ $('#cat-param-table').inventreeTable({
|
||||
switchable: false,
|
||||
},
|
||||
{
|
||||
field: 'parameter_template.name',
|
||||
field: 'parameter_template_detail.name',
|
||||
title: '{% trans "Parameter Template" %}',
|
||||
sortable: 'true',
|
||||
},
|
||||
@ -249,18 +249,23 @@ $('#cat-param-table').inventreeTable({
|
||||
|
||||
function loadTemplateTable(pk) {
|
||||
|
||||
// Enable the buttons
|
||||
$('#new-cat-param').removeAttr('disabled');
|
||||
var query = {};
|
||||
|
||||
if (pk) {
|
||||
query['category'] = pk;
|
||||
}
|
||||
|
||||
// Load the parameter table
|
||||
$("#cat-param-table").bootstrapTable('refresh', {
|
||||
query: {
|
||||
category: pk,
|
||||
},
|
||||
query: query,
|
||||
url: '{% url "api-part-category-parameter-list" %}',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Initially load table with *all* categories
|
||||
loadTemplateTable();
|
||||
|
||||
$('body').on('change', '#category-select', function() {
|
||||
var pk = $(this).val();
|
||||
loadTemplateTable(pk);
|
||||
@ -270,14 +275,20 @@ $("#new-cat-param").click(function() {
|
||||
|
||||
var pk = $('#category-select').val();
|
||||
|
||||
launchModalForm(`/part/category/${pk}/parameters/new/`, {
|
||||
success: function() {
|
||||
$("#cat-param-table").bootstrapTable('refresh', {
|
||||
query: {
|
||||
category: pk,
|
||||
}
|
||||
});
|
||||
constructForm('{% url "api-part-category-parameter-list" %}', {
|
||||
title: '{% trans "Create Category Parameter Template" %}',
|
||||
method: 'POST',
|
||||
fields: {
|
||||
parameter_template: {},
|
||||
category: {
|
||||
icon: 'fa-sitemap',
|
||||
value: pk,
|
||||
},
|
||||
default_value: {},
|
||||
},
|
||||
onSuccess: function() {
|
||||
loadTemplateTable(pk);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -286,15 +297,21 @@ $("#cat-param-table").on('click', '.template-edit', function() {
|
||||
var category = $('#category-select').val();
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
var url = `/part/category/${category}/parameters/${pk}/edit/`;
|
||||
|
||||
launchModalForm(url, {
|
||||
success: function() {
|
||||
$("#cat-param-table").bootstrapTable('refresh');
|
||||
constructForm(`/api/part/category/parameters/${pk}/`, {
|
||||
fields: {
|
||||
parameter_template: {},
|
||||
category: {
|
||||
icon: 'fa-sitemap',
|
||||
},
|
||||
default_value: {},
|
||||
},
|
||||
onSuccess: function() {
|
||||
loadTemplateTable(pk);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$("#cat-param-table").on('click', '.template-delete', function() {
|
||||
|
||||
var category = $('#category-select').val();
|
||||
@ -302,9 +319,11 @@ $("#cat-param-table").on('click', '.template-delete', function() {
|
||||
|
||||
var url = `/part/category/${category}/parameters/${pk}/delete/`;
|
||||
|
||||
launchModalForm(url, {
|
||||
success: function() {
|
||||
$("#cat-param-table").bootstrapTable('refresh');
|
||||
constructForm(`/api/part/category/parameters/${pk}/`, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Category Parameter Template" %}',
|
||||
onSuccess: function() {
|
||||
loadTemplateTable(pk);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user