mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor edit and delete forms for ManufacturerPart
This commit is contained in:
parent
96a2629fd2
commit
206d7bd96a
@ -113,21 +113,27 @@ $('#order-part, #order-part2').click(function() {
|
||||
});
|
||||
|
||||
$('#edit-part').click(function () {
|
||||
launchModalForm(
|
||||
"{% url 'manufacturer-part-edit' part.id %}",
|
||||
{
|
||||
reload: true
|
||||
}
|
||||
);
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-detail" part.pk %}', {
|
||||
fields: {
|
||||
part: {},
|
||||
manufacturer: {},
|
||||
MPN: {},
|
||||
description: {},
|
||||
link: {},
|
||||
},
|
||||
title: '{% trans "Edit Manufacturer Part" %}',
|
||||
reload: true,
|
||||
});
|
||||
});
|
||||
|
||||
$('#delete-part').click(function() {
|
||||
launchModalForm(
|
||||
"{% url 'manufacturer-part-delete' %}?part={{ part.id }}",
|
||||
{
|
||||
redirect: "{% url 'company-detail-manufacturer-parts' part.manufacturer.id %}"
|
||||
}
|
||||
);
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-detail" part.pk %}', {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Manufacturer Part" %}',
|
||||
redirect: "{% url 'company-detail-manufacturer-parts' part.manufacturer.id %}",
|
||||
});
|
||||
});
|
||||
|
||||
{% endblock %}
|
@ -1,46 +0,0 @@
|
||||
{% extends "modal_delete_form.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block pre_form_content %}
|
||||
<div class='alert alert-block alert-warning'>
|
||||
{% trans "Are you sure you want to delete the following Manufacturer Parts?" %}
|
||||
</div>
|
||||
{% for part in parts %}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block form_data %}
|
||||
|
||||
{% for part in parts %}
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tr>
|
||||
<input type='hidden' name='manufacturer-part-{{ part.id}}' value='manufacturer-part-{{ part.id }}'/>
|
||||
|
||||
<td>
|
||||
{% include "hover_image.html" with image=part.part.image %}
|
||||
{{ part.part.full_name }}
|
||||
</td>
|
||||
<td>
|
||||
{% include "hover_image.html" with image=part.manufacturer.image %}
|
||||
{{ part.manufacturer.name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ part.MPN }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% if part.supplier_parts.all|length > 0 %}
|
||||
<div class='alert alert-block alert-danger'>
|
||||
<p>{% blocktrans with count=part.supplier_parts.all|length %}There are {{count}} suppliers defined for this manufacturer part. If you delete it, the following supplier parts will also be deleted:{% endblocktrans %}</p>
|
||||
<ul class='list-group' style='margin-top:10px'>
|
||||
{% for spart in part.supplier_parts.all %}
|
||||
<li class='list-group-item'>{{ spart.supplier.name }} - {{ spart.SKU }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
@ -42,10 +42,7 @@ company_urls = [
|
||||
manufacturer_part_urls = [
|
||||
url(r'^new/?', views.ManufacturerPartCreate.as_view(), name='manufacturer-part-create'),
|
||||
|
||||
url(r'^delete/', views.ManufacturerPartDelete.as_view(), name='manufacturer-part-delete'),
|
||||
|
||||
url(r'^(?P<pk>\d+)/', include([
|
||||
url(r'^edit/?', views.ManufacturerPartEdit.as_view(), name='manufacturer-part-edit'),
|
||||
url(r'^suppliers/', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part_suppliers.html'), name='manufacturer-part-suppliers'),
|
||||
url('^.*$', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part_suppliers.html'), name='manufacturer-part-detail'),
|
||||
])),
|
||||
|
@ -258,16 +258,6 @@ class ManufacturerPartDetail(DetailView):
|
||||
return ctx
|
||||
|
||||
|
||||
class ManufacturerPartEdit(AjaxUpdateView):
|
||||
""" Update view for editing ManufacturerPart """
|
||||
|
||||
model = ManufacturerPart
|
||||
context_object_name = 'part'
|
||||
form_class = EditManufacturerPartForm
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = _('Edit Manufacturer Part')
|
||||
|
||||
|
||||
class ManufacturerPartCreate(AjaxCreateView):
|
||||
""" Create view for making new ManufacturerPart """
|
||||
|
||||
@ -336,85 +326,6 @@ class ManufacturerPartCreate(AjaxCreateView):
|
||||
return initials
|
||||
|
||||
|
||||
class ManufacturerPartDelete(AjaxDeleteView):
|
||||
""" Delete view for removing a ManufacturerPart.
|
||||
|
||||
ManufacturerParts can be deleted using a variety of 'selectors'.
|
||||
|
||||
- ?part=<pk> -> Delete a single ManufacturerPart object
|
||||
- ?parts=[] -> Delete a list of ManufacturerPart objects
|
||||
|
||||
"""
|
||||
|
||||
success_url = '/manufacturer/'
|
||||
ajax_template_name = 'company/manufacturer_part_delete.html'
|
||||
ajax_form_title = _('Delete Manufacturer Part')
|
||||
|
||||
role_required = 'purchase_order.delete'
|
||||
|
||||
parts = []
|
||||
|
||||
def get_context_data(self):
|
||||
ctx = {}
|
||||
|
||||
ctx['parts'] = self.parts
|
||||
|
||||
return ctx
|
||||
|
||||
def get_parts(self):
|
||||
""" Determine which ManufacturerPart object(s) the user wishes to delete.
|
||||
"""
|
||||
|
||||
self.parts = []
|
||||
|
||||
# User passes a single ManufacturerPart ID
|
||||
if 'part' in self.request.GET:
|
||||
try:
|
||||
self.parts.append(ManufacturerPart.objects.get(pk=self.request.GET.get('part')))
|
||||
except (ValueError, ManufacturerPart.DoesNotExist):
|
||||
pass
|
||||
|
||||
elif 'parts[]' in self.request.GET:
|
||||
|
||||
part_id_list = self.request.GET.getlist('parts[]')
|
||||
|
||||
self.parts = ManufacturerPart.objects.filter(id__in=part_id_list)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.request = request
|
||||
self.get_parts()
|
||||
|
||||
return self.renderJsonResponse(request, form=self.get_form())
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
""" Handle the POST action for deleting ManufacturerPart object.
|
||||
"""
|
||||
|
||||
self.request = request
|
||||
self.parts = []
|
||||
|
||||
for item in self.request.POST:
|
||||
if item.startswith('manufacturer-part-'):
|
||||
pk = item.replace('manufacturer-part-', '')
|
||||
|
||||
try:
|
||||
self.parts.append(ManufacturerPart.objects.get(pk=pk))
|
||||
except (ValueError, ManufacturerPart.DoesNotExist):
|
||||
pass
|
||||
|
||||
confirm = str2bool(self.request.POST.get('confirm_delete', False))
|
||||
|
||||
data = {
|
||||
'form_valid': confirm,
|
||||
}
|
||||
|
||||
if confirm:
|
||||
for part in self.parts:
|
||||
part.delete()
|
||||
|
||||
return self.renderJsonResponse(self.request, data=data, form=self.get_form())
|
||||
|
||||
|
||||
class SupplierPartDetail(DetailView):
|
||||
""" Detail view for SupplierPart """
|
||||
model = SupplierPart
|
||||
|
Loading…
Reference in New Issue
Block a user