2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 05:25:42 +00:00

Implemented tree view

Using library bootstrap-treeview
- part category tree
- stock location tree
- Currenly is functional but looks terrible
This commit is contained in:
Oliver
2018-04-28 23:22:12 +10:00
parent 095492203f
commit 8d0789c37c
13 changed files with 1471 additions and 9 deletions

View File

@ -7,9 +7,17 @@ from rest_framework import generics, permissions
from django.conf.urls import url
from .models import Part
from .models import Part, PartCategory
from .serializers import PartSerializer
from InvenTree.views import TreeSerializer
class PartCategoryTree(TreeSerializer):
title = "Parts"
model = PartCategory
class PartList(generics.ListCreateAPIView):
@ -44,5 +52,7 @@ class PartList(generics.ListCreateAPIView):
part_api_urls = [
url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'),
url(r'^.*$', PartList.as_view(), name='api-part-list'),
]

View File

@ -31,7 +31,6 @@
<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' src="{% static 'script/bootstrap-treeview.js' %}"></script>
{% endblock %}
{% block js_ready %}
$('#part-list').footable();
@ -44,7 +43,36 @@
});
});
function loadTree() {
var requestData = {};
{% if category %}
requestData.category = {{ category.id }};
{% endif %}
$.ajax({
url: "{% url 'api-part-tree' %}",
type: 'get',
dataType: 'json',
data: requestData,
success: function (response) {
if (response.tree) {
$("#part-tree").treeview({
data: response.tree,
enableLinks: true
});
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Error retrieving part tree:\n' + thrownError);
}
});
}
$("#create-part").click(function() {
launchModalForm("#modal-form", "{% url 'part-create' %}");
});
loadTree();
{% endblock %}