Tweak javascript for category detail pages

This commit is contained in:
Oliver 2018-04-28 11:43:26 +10:00
parent bc597d7c21
commit 2e7253ebc4
5 changed files with 58 additions and 24 deletions

View File

@ -1,34 +1,36 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<h3>Part Builds</h3>
<table class='table table-striped'>
<table class='table table-striped' id='build-list' data-sorting='true' data-filtering='true'>
<thead>
<tr>
<th></th>
<th>Build</th>
<th>Part</th>
<th>Quantity</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% if active|length > 0 %}
<tr><td colspan="4"><b>Active Builds</b></td></tr>
{% include "build/build_list.html" with builds=active %}
{% endif %}
{% if complete|length > 0 %}
<tr></tr>
<tr><td colspan="4"><b>Completed Builds</b></td></tr>
{% include "build/build_list.html" with builds=complete %}
{% endif %}
{% if cancelled|length > 0 %}
<tr></tr>
<tr><td colspan="4"><b>Cancelled Builds</b></td></tr>
{% include "build/build_list.html" with builds=cancelled.all %}
{% endif %}
{% include "build/build_list.html" with builds=builds %}
</tbody>
</table>
{% 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 () {
$('#build-list').footable();
});
</script>
{% endblock %}

View File

@ -25,10 +25,12 @@ class BuildIndex(ListView):
context = super(BuildIndex, self).get_context_data(**kwargs).copy()
"""
context['active'] = self.get_queryset().filter(status__in=[Build.PENDING, Build.HOLDING])
context['complete'] = self.get_queryset().filter(status=Build.COMPLETE)
context['cancelled'] = self.get_queryset().filter(status=Build.CANCELLED)
"""
return context

View File

@ -50,24 +50,40 @@ $(document).ready(function (){
);
});
{% if category.parent %}
var categoryRedirect = "{% url 'category-detail' category.parent.id %}";
{% else %}
var categoryRedirect = "{% url 'part-index' %}";
{% endif %}
$("#delete-category").click(function() {
launchDeleteForm("#modal-delete",
"{% url 'category-delete' category.id %}",
{redirect: "{% url 'part-index' %}"});
{
redirect: categoryRedirect
});
});
$("#create-cat").click(function() {
launchModalForm("#modal-form",
"{% url 'category-create' %}",
{data: {category: {{ category.id }}
}});
{
follow: true,
data: {
category: {{ category.id }}
}
});
});
$("#create-part").click( function() {
launchModalForm("#modal-form",
"{% url 'part-create' %}",
{data: {category: {{ category.id }}
}});
{
data: {
category: {{ category.id }}
},
reload: true
});
});
});
</script>

View File

@ -54,6 +54,10 @@ function launchDeleteForm(modal, url, options = {}) {
if (options.success) {
options.success();
}
// Follow the URL returned by the JSON response
else if (options.follow && response.url) {
window.location.href = response.url;
}
else if (options.redirect) {
window.location.href = options.redirect;
}

View File

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block content %}
{% endblock %}
{% block javascript %}
{% endblock %}