mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-15 11:35:41 +00:00
Modal form for part creation
This commit is contained in:
@ -12,10 +12,7 @@ class EditPartForm(forms.ModelForm):
|
|||||||
super(EditPartForm, self).__init__(*args, **kwargs)
|
super(EditPartForm, self).__init__(*args, **kwargs)
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
|
|
||||||
self.helper.form_id = 'id-edit-part-form'
|
self.helper.form_tag = False
|
||||||
self.helper.form_method = 'post'
|
|
||||||
|
|
||||||
self.helper.add_input(Submit('submit', 'Submit'))
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Part
|
model = Part
|
||||||
|
@ -22,12 +22,10 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
<button type='button' class='btn btn-primary js-create-cat'>
|
<button type='button' class='btn btn-primary' id='create-cat'>
|
||||||
New Category
|
New Category
|
||||||
</button>
|
</button>
|
||||||
<a href="{% url 'part-create' %}?category={{ category.id }}">
|
<button class="btn btn-success" id='create-part'>New Part</button>
|
||||||
<button class="btn btn-success">New Part</button>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="{% url 'category-edit' category.id %}">
|
<a href="{% url 'category-edit' category.id %}">
|
||||||
<button class="btn btn-info">Edit Category</button>
|
<button class="btn btn-info">Edit Category</button>
|
||||||
@ -39,12 +37,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='modal fade' id='modal-cat'>
|
{% include 'modal.html' %}
|
||||||
<div class='modal-dialog'>
|
|
||||||
<div class='modal-content'>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -54,10 +47,18 @@
|
|||||||
|
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
|
|
||||||
$(".js-create-cat").click(function() {
|
$("#create-cat").click(function() {
|
||||||
launchModalForm("#modal-cat",
|
launchModalForm("#modal-form",
|
||||||
"{% url 'category-create' %}",
|
"{% url 'category-create' %}",
|
||||||
{category: {{ category.id }} });
|
{category: {{ category.id }}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#create-part").click( function() {
|
||||||
|
launchModalForm("#modal-form",
|
||||||
|
"{% url 'part-create' %}",
|
||||||
|
{category: {{ category.id }}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,12 +5,7 @@
|
|||||||
|
|
||||||
{% include "part/cat_link.html" with category=category %}
|
{% include "part/cat_link.html" with category=category %}
|
||||||
|
|
||||||
<div class='modal fade' id='modal-cat'>
|
{% include 'modal.html' %}
|
||||||
<div class='modal-dialog'>
|
|
||||||
<div class='modal-content'>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if children.all|length > 0 %}
|
{% if children.all|length > 0 %}
|
||||||
<h4>Part Categories</h4>
|
<h4>Part Categories</h4>
|
||||||
@ -21,12 +16,10 @@
|
|||||||
{% include "part/category_parts.html" with parts=parts %}
|
{% include "part/category_parts.html" with parts=parts %}
|
||||||
|
|
||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
<button type='button' class='btn btn-primary js-create-cat'>
|
<button type='button' class='btn btn-primary' id='create-cat'>
|
||||||
New Category
|
New Category
|
||||||
</button>
|
</button>
|
||||||
<a href="{% url 'part-create' %}">
|
<button class="btn btn-success" id='create-part'>New Part</button>
|
||||||
<button class="btn btn-success">New Part</button>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -37,8 +30,12 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
$(".js-create-cat").click(function() {
|
$("#create-cat").click(function() {
|
||||||
launchModalForm("#modal-cat", "{% url 'category-create' %}");
|
launchModalForm("#modal-form", "{% url 'category-create' %}");
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#create-part").click(function() {
|
||||||
|
launchModalForm("#modal-form", "{% url 'part-create' %}");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -41,7 +41,7 @@ class PartIndex(ListView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class PartCreate(CreateView):
|
class PartCreate(AjaxCreateView):
|
||||||
""" Create a new part
|
""" Create a new part
|
||||||
- Optionally provide a category object as initial data
|
- Optionally provide a category object as initial data
|
||||||
"""
|
"""
|
||||||
@ -49,6 +49,9 @@ class PartCreate(CreateView):
|
|||||||
form_class = EditPartForm
|
form_class = EditPartForm
|
||||||
template_name = 'part/create.html'
|
template_name = 'part/create.html'
|
||||||
|
|
||||||
|
ajax_form_title = 'Create new part'
|
||||||
|
ajax_template_name = 'modal_form.html'
|
||||||
|
|
||||||
def get_category_id(self):
|
def get_category_id(self):
|
||||||
return self.request.GET.get('category', None)
|
return self.request.GET.get('category', None)
|
||||||
|
|
||||||
|
6
InvenTree/templates/modal.html
Normal file
6
InvenTree/templates/modal.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<div class='modal fade modal-fixed-footer' role='dialog' id='modal-form'>
|
||||||
|
<div class='modal-dialog'>
|
||||||
|
<div class='modal-content'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
Reference in New Issue
Block a user