More modal forms

- supplier-part-edit
- supplier-part-delete
This commit is contained in:
Oliver 2018-04-27 21:32:48 +10:00
parent bc3dca3aba
commit e1e3cc71e6
6 changed files with 80 additions and 33 deletions

View File

@ -1,5 +1 @@
{% extends 'delete_obj.html' %}
{% block del_title %}
Are you sure you want to delete this supplier part?
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<h3>Supplier part information</h3>
@ -30,13 +30,40 @@
<br>
<div class='container-fluid'>
<a href="{% url 'supplier-part-edit' part.id %}">
<button class="btn btn-info">Edit supplier part</button>
</a>
<a href="{% url 'supplier-part-delete' part.id %}">
<button class="btn btn-danger">Delete supplier part</button>
</a>
<button class="btn btn-info" id='part-edit'>Edit supplier part</button>
<button class="btn btn-danger" id='part-delete'>Delete supplier part</button>
</div>
{% include 'modal.html' %}
{% include 'modal_delete.html' %}
{% endblock %}
{% block javascript %}
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function () {
$('#part-edit').click(function () {
launchModalForm("#modal-form",
"{% url 'supplier-part-edit' part.id %}",
{
reload: true
}
);
});
$('#part-delete').click(function() {
launchDeleteForm("#modal-delete",
"{% url 'supplier-part-delete' part.id %}",
{
redirect: "{% url 'company-index' %}"
}
);
});
});
</script>
{% endblock %}

View File

@ -80,11 +80,7 @@ class EditSupplierPartForm(forms.ModelForm):
super(EditSupplierPartForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_id = 'id-edit-part-form'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit', 'Submit'))
self.helper.form_tag = False
class Meta:
model = SupplierPart

View File

@ -74,7 +74,8 @@ $(document).ready(function(){
$("#new-bom-item").click(function () {
launchModalForm("#modal-form",
"{% url 'bom-item-create' %}/?parent={{ part.id }}");
"{% url 'bom-item-create' %}",
{data: {parent: {{ part.id }} }});
});
});
</script>

View File

@ -1,18 +1,21 @@
{% extends "part/part_base.html" %}
{% load static %}
{% block details %}
{% include 'part/tabs.html' with tab='suppliers' %}
<h3>Part Suppliers</h3>
<table class="table table-striped">
<table class="table table-striped" id='supplier-table' data-sorting='true'>
<thead>
<tr>
<th>SKU</th>
<th>Supplier</th>
<th>MPN</th>
<th>URL</th>
</tr>
</thead>
<tbody>
{% for spart in part.supplier_parts.all %}
<tr>
<td><a href="{% url 'supplier-part-detail' spart.id %}">{{ spart.SKU }}</a></td>
@ -25,12 +28,38 @@
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class='container-fluid'>
<a href="{% url 'supplier-part-create' %}?part={{ part.id }}">
<button class="btn btn-success">New Supplier Part</button>
</a>
<button class="btn btn-success" id='supplier-create'>New Supplier Part</button>
</div>
{% include 'modal.html' %}
{% endblock %}
{% block javascript %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>``
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function (){
$('#supplier-table').footable();
$('#supplier-create').click(function () {
launchModalForm("#modal-form",
"{% url 'supplier-part-create' %}",
{
reload: true,
data: {part: {{ part.id }} }
});
});
});
</script>
{% endblock %}

View File

@ -224,17 +224,21 @@ class SupplierPartDetail(DetailView):
queryset = SupplierPart.objects.all()
class SupplierPartEdit(UpdateView):
class SupplierPartEdit(AjaxUpdateView):
model = SupplierPart
template_name = 'company/partedit.html'
context_object_name = 'part'
form_class = EditSupplierPartForm
ajax_template_name = 'modal_form.html'
ajax_form_title = 'Edit Supplier Part'
class SupplierPartCreate(CreateView):
class SupplierPartCreate(AjaxCreateView):
model = SupplierPart
form_class = EditSupplierPartForm
template_name = 'company/partcreate.html'
ajax_template_name = 'modal_form.html'
ajax_form_title = 'Create new Supplier Part'
#template_name = 'company/partcreate.html'
context_object_name = 'part'
def get_initial(self):
@ -255,13 +259,7 @@ class SupplierPartCreate(CreateView):
return initials
class SupplierPartDelete(DeleteView):
class SupplierPartDelete(AjaxDeleteView):
model = SupplierPart
success_url = '/supplier/'
template_name = 'company/partdelete.html'
def post(self, request, *args, **kwargs):
if 'confirm' in request.POST:
return super(SupplierPartDelete, self).post(request, *args, **kwargs)
else:
return HttpResponseRedirect(self.get_object().get_absolute_url())