Modal form for company-delete

This commit is contained in:
Oliver 2018-04-27 22:07:11 +10:00
parent 36cf946a78
commit 4794714a09
4 changed files with 41 additions and 18 deletions

View File

@ -1,17 +1,13 @@
{% extends "delete_obj.html" %}
{% block del_title %}
Are you sure you want to delete company '{{ company.name }}'?
{% endblock %}
{% block del_body %}
<br>
{% if company.part_count > 0 %}
<p>There are {{ company.part_count }} parts sourced from this company.<br>
If this supplier is deleted, these supplier part entries will also be deleted.</p>
<ul class='list-group'>
{% for part in company.parts.all %}
<li class='list-group-item'><b>{{ part.SKU }}</b><br><i>Part - {{ part.part.name }}</i></li>
<li class='list-group-item'><b>{{ part.SKU }}</b> - <i>{{ part.part.name }}</i></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends "company/company_base.html" %}
{% load static %}
{% block details %}
{% include 'company/tabs.html' with tab='details' %}
@ -25,8 +25,36 @@
{% endif %}
<div class='container-fluid'>
<a href="{% url 'company-edit' company.id %}"><button class="btn btn-info">Edit Company</button></a>
<a href="{% url 'company-delete' company.id %}"><button class="btn btn-danger">Delete Company</button></a>
<button class="btn btn-info" id='edit-company'>Edit Company</button>
<button class="btn btn-danger" id='delete-company'>Delete Company</button>
</div>
{% include 'modals.html' %}
{% endblock %}
{% block javascript %}
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function() {
$('#edit-company').click(function() {
launchModalForm("#modal-form",
"{% url 'company-edit' company.id %}",
{
reload: true
});
});
$('#delete-company').click(function() {
launchDeleteForm("#modal-delete",
"{% url 'company-delete' company.id %}",
{
redirect: "{% url 'company-index' %}"
});
})
});
</script>
{% endblock %}

View File

@ -42,6 +42,7 @@
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function() {
$('#company-table').footable();
$('#new-company').click(function () {
@ -51,6 +52,7 @@
follow: true
});
});
});
</script>
{% endblock %}

View File

@ -38,11 +38,13 @@ class CompanyDetail(DetailView):
model = Company
class CompanyEdit(UpdateView):
class CompanyEdit(AjaxUpdateView):
model = Company
form_class = EditCompanyForm
template_name = 'company/edit.html'
context_object_name = 'company'
ajax_template_name = 'modal_form.html'
ajax_form_title = 'Edit Company'
class CompanyCreate(AjaxCreateView):
@ -54,13 +56,8 @@ class CompanyCreate(AjaxCreateView):
ajax_form_title = "Create new Company"
class CompanyDelete(DeleteView):
class CompanyDelete(AjaxDeleteView):
model = Company
success_url = '/company/'
template_name = 'company/delete.html'
def post(self, request, *args, **kwargs):
if 'confirm' in request.POST:
return super(CompanyDelete, self).post(request, *args, **kwargs)
else:
return HttpResponseRedirect(self.get_object().get_absolute_url())
ajax_form_title = 'Delete Company'