mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Modal for edit and delete part category
This commit is contained in:
parent
5162c1d11f
commit
bc3dca3aba
@ -1,41 +1,33 @@
|
|||||||
{% extends 'delete_obj.html' %}
|
|
||||||
|
|
||||||
{% block del_title %}
|
|
||||||
Are you sure you want to delete category '{{ category.name }}'?
|
Are you sure you want to delete category '{{ category.name }}'?
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block del_body %}
|
{% if category.children.all|length > 0 %}
|
||||||
|
<p>This category contains {{ category.children.all|length }} child categories.<br>
|
||||||
|
If this category is deleted, these child categories will be moved to
|
||||||
|
{% if category.parent %}
|
||||||
|
the '{{ category.parent.name }}' category.
|
||||||
|
{% else %}
|
||||||
|
the top level 'Parts' category.
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
|
||||||
{% if category.children.all|length > 0 %}
|
<ul class='list-group'>
|
||||||
<p>This category contains {{ category.children.all|length }} child categories.<br>
|
{% for cat in category.children.all %}
|
||||||
If this category is deleted, these child categories will be moved to
|
<li class='list-group-item'><b>{{ cat.name }}</b> - <i>{{ cat.description }}</i></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if category.parts.all|length > 0 %}
|
||||||
|
<p>This category contains {{ category.parts.all|length }} parts.<br>
|
||||||
{% if category.parent %}
|
{% if category.parent %}
|
||||||
the '{{ category.parent.name }}' category.
|
If this category is deleted, these parts will be moved to the parent category '{{ category.parent.pathstring }}'
|
||||||
{% else %}
|
{% else %}
|
||||||
the top level 'Parts' category.
|
If this category is deleted, these parts will be moved to the top-level category 'Parts'
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
<ul class='list-group'>
|
||||||
<ul class='list-group'>
|
{% for part in category.parts.all %}
|
||||||
{% for cat in category.children.all %}
|
<li class='list-group-item'><b>{{ part.name }}</b> - <i>{{ part.description }}</i></li>
|
||||||
<li class='list-group-item'><b>{{ cat.name }}</b> - <i>{{ cat.description }}</i></li>
|
{% endfor %}
|
||||||
{% endfor %}
|
</ul>
|
||||||
</ul>
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if category.parts.all|length > 0 %}
|
|
||||||
<p>This category contains {{ category.parts.all|length }} parts.<br>
|
|
||||||
{% if category.parent %}
|
|
||||||
If this category is deleted, these parts will be moved to the parent category '{{ category.parent.pathstring }}'
|
|
||||||
{% else %}
|
|
||||||
If this category is deleted, these parts will be moved to the top-level category 'Parts'
|
|
||||||
{% endif %}
|
|
||||||
</p>
|
|
||||||
<ul class='list-group'>
|
|
||||||
{% for part in category.parts.all %}
|
|
||||||
<li class='list-group-item'><b>{{ part.name }}</b> - <i>{{ part.description }}</i></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
@ -25,19 +25,14 @@
|
|||||||
<button type='button' class='btn btn-primary' id='create-cat'>
|
<button type='button' class='btn btn-primary' id='create-cat'>
|
||||||
New Category
|
New Category
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-success" id='create-part'>New Part</button>
|
<button class="btn btn-info" id='edit-category'>Edit Category</button>
|
||||||
|
<button class="btn btn-success" id='create-part'>New Part</button>
|
||||||
<a href="{% url 'category-edit' category.id %}">
|
<button class="btn btn-danger" id='delete-category'>Delete Category</button>
|
||||||
<button class="btn btn-info">Edit Category</button>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="{% url 'category-delete' category.id %}">
|
|
||||||
<button class="btn btn-danger">Delete Category</button>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% include 'modal.html' %}
|
{% include 'modal.html' %}
|
||||||
|
{% include 'modal_delete.html' %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -49,6 +44,19 @@
|
|||||||
$(document).ready(function (){
|
$(document).ready(function (){
|
||||||
$('#part-list').footable();
|
$('#part-list').footable();
|
||||||
|
|
||||||
|
$("#edit-category").click(function () {
|
||||||
|
launchModalForm("#modal-form",
|
||||||
|
"{% url 'category-edit' category.id %}",
|
||||||
|
{reload: true},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#delete-category").click(function() {
|
||||||
|
launchDeleteForm("#modal-delete",
|
||||||
|
"{% url 'category-delete' category.id %}",
|
||||||
|
{redirect: "{% url 'part-index' %}"});
|
||||||
|
});
|
||||||
|
|
||||||
$("#create-cat").click(function() {
|
$("#create-cat").click(function() {
|
||||||
launchModalForm("#modal-form",
|
launchModalForm("#modal-form",
|
||||||
"{% url 'category-create' %}",
|
"{% url 'category-create' %}",
|
||||||
|
@ -116,10 +116,12 @@ class CategoryDetail(DetailView):
|
|||||||
template_name = 'part/category_detail.html'
|
template_name = 'part/category_detail.html'
|
||||||
|
|
||||||
|
|
||||||
class CategoryEdit(UpdateView):
|
class CategoryEdit(AjaxUpdateView):
|
||||||
model = PartCategory
|
model = PartCategory
|
||||||
template_name = 'part/category_edit.html'
|
template_name = 'part/category_edit.html'
|
||||||
form_class = EditCategoryForm
|
form_class = EditCategoryForm
|
||||||
|
ajax_template_name = 'modal_form.html'
|
||||||
|
ajax_form_title = 'Edit Part Category'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(CategoryEdit, self).get_context_data(**kwargs).copy()
|
context = super(CategoryEdit, self).get_context_data(**kwargs).copy()
|
||||||
@ -129,18 +131,12 @@ class CategoryEdit(UpdateView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class CategoryDelete(DeleteView):
|
class CategoryDelete(AjaxDeleteView):
|
||||||
model = PartCategory
|
model = PartCategory
|
||||||
template_name = 'part/category_delete.html'
|
template_name = 'part/category_delete.html'
|
||||||
context_object_name = 'category'
|
context_object_name = 'category'
|
||||||
success_url = '/part/'
|
success_url = '/part/'
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
if 'confirm' in request.POST:
|
|
||||||
return super(CategoryDelete, self).post(request, *args, **kwargs)
|
|
||||||
else:
|
|
||||||
return HttpResponseRedirect(self.get_object().get_absolute_url())
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryCreate(AjaxCreateView):
|
class CategoryCreate(AjaxCreateView):
|
||||||
model = PartCategory
|
model = PartCategory
|
||||||
|
@ -51,9 +51,15 @@ function launchDeleteForm(modal, url, options = {}) {
|
|||||||
success: function (response) {
|
success: function (response) {
|
||||||
$(modal).modal('hide');
|
$(modal).modal('hide');
|
||||||
|
|
||||||
if (options.redirect) {
|
if (options.success) {
|
||||||
|
options.success();
|
||||||
|
}
|
||||||
|
else if (options.redirect) {
|
||||||
window.location.href = options.redirect;
|
window.location.href = options.redirect;
|
||||||
}
|
}
|
||||||
|
else if (options.reload) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function (xhr, ajaxOptions, thrownError) {
|
error: function (xhr, ajaxOptions, thrownError) {
|
||||||
alert('Error deleting item:\n' + thrownError);
|
alert('Error deleting item:\n' + thrownError);
|
||||||
@ -123,14 +129,15 @@ function launchModalForm(modal, url, options = {}) {
|
|||||||
|
|
||||||
$(modal).modal('hide');
|
$(modal).modal('hide');
|
||||||
|
|
||||||
if (options.redirect) {
|
|
||||||
window.location.href = options.redirect;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.success) {
|
if (options.success) {
|
||||||
options.success();
|
options.success();
|
||||||
}
|
}
|
||||||
|
else if (options.redirect) {
|
||||||
|
window.location.href = options.redirect;
|
||||||
|
}
|
||||||
|
else if (options.reload) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (response.html_form) {
|
else if (response.html_form) {
|
||||||
var target = modal + ' .modal-form-content';
|
var target = modal + ' .modal-form-content';
|
||||||
|
Loading…
Reference in New Issue
Block a user