Made all categories accessible for parameter templates configuration

This commit is contained in:
eeintech 2020-11-03 14:45:53 -05:00
parent 6b702ef676
commit 72b5a105f8
3 changed files with 18 additions and 17 deletions

View File

@ -201,28 +201,25 @@ class ColorThemeSelectForm(forms.ModelForm):
class SettingCategorySelectForm(forms.ModelForm): class SettingCategorySelectForm(forms.ModelForm):
""" Form for setting category settings """ """ Form for setting category settings """
name = forms.ChoiceField(required=False) category = forms.ModelChoiceField(queryset=PartCategory.objects.all())
class Meta: class Meta:
model = PartCategory model = PartCategory
fields = [ fields = [
'name' 'category'
] ]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(SettingCategorySelectForm, self).__init__(*args, **kwargs) super(SettingCategorySelectForm, self).__init__(*args, **kwargs)
# Populate category choices
self.fields['name'].choices = [('', '-' * 10)] + PartCategory.get_parent_categories()
self.helper = FormHelper() self.helper = FormHelper()
# Form rendering # Form rendering
self.helper.form_show_labels = False self.helper.form_show_labels = False
self.helper.layout = Layout( self.helper.layout = Layout(
Div( Div(
Div(Field('name'), Div(Field('category'),
css_class='col-sm-6', css_class='col-sm-6',
style='width: auto;'), style='width: 30%;'),
Div(StrictButton(_('Select Category'), css_class='btn btn-primary', type='submit'), Div(StrictButton(_('Select Category'), css_class='btn btn-primary', type='submit'),
css_class='col-sm-6', css_class='col-sm-6',
style='width: auto; padding-left: 0;'), style='width: auto; padding-left: 0;'),

View File

@ -765,7 +765,7 @@ class SettingCategorySelectView(FormView):
category = self.request.GET.get('category', None) category = self.request.GET.get('category', None)
if category: if category:
initial['name'] = category initial['category'] = category
return initial return initial
@ -778,11 +778,9 @@ class SettingCategorySelectView(FormView):
form = self.get_form() form = self.get_form()
if form.is_valid(): if form.is_valid():
category = form.cleaned_data['name']
context = self.get_context_data() context = self.get_context_data()
context['category'] = category context['category'] = form.cleaned_data['category']
return super(SettingCategorySelectView, self).render_to_response(context) return super(SettingCategorySelectView, self).render_to_response(context)

View File

@ -14,7 +14,9 @@
<form action="{% url 'settings-category' %}" method="post"> <form action="{% url 'settings-category' %}" method="post">
{% csrf_token %} {% csrf_token %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% crispy form %} <div id="category-select">
{% crispy form %}
</div>
</form> </form>
{% if category %} {% if category %}
@ -35,10 +37,14 @@
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
{% if category %}
$(document).ready(function() {
attachSelect('#category-select');
});
{% if category %}
$("#param-table").inventreeTable({ $("#param-table").inventreeTable({
url: "{% url 'api-part-category-parameters' category %}", url: "{% url 'api-part-category-parameters' category.pk %}",
queryParams: { queryParams: {
ordering: 'name', ordering: 'name',
}, },
@ -74,7 +80,7 @@
$("#new-param").click(function() { $("#new-param").click(function() {
launchModalForm("{% url 'category-param-template-create' category %}", { launchModalForm("{% url 'category-param-template-create' category.pk %}", {
success: function() { success: function() {
$("#param-table").bootstrapTable('refresh'); $("#param-table").bootstrapTable('refresh');
}, },
@ -84,7 +90,7 @@
$("#param-table").on('click', '.template-edit', function() { $("#param-table").on('click', '.template-edit', function() {
var button = $(this); var button = $(this);
var url = "/part/category/{{ category }}/parameters/" + button.attr('pk') + "/edit/"; var url = "/part/category/{{ category.pk }}/parameters/" + button.attr('pk') + "/edit/";
launchModalForm(url, { launchModalForm(url, {
success: function() { success: function() {
@ -96,7 +102,7 @@
$("#param-table").on('click', '.template-delete', function() { $("#param-table").on('click', '.template-delete', function() {
var button = $(this); var button = $(this);
var url = "/part/category/{{ category }}/parameters/" + button.attr('pk') + "/delete/"; var url = "/part/category/{{ category.pk }}/parameters/" + button.attr('pk') + "/delete/";
launchModalForm(url, { launchModalForm(url, {
success: function() { success: function() {