From e4af1331eebaf049033c66a389df8a4632cc815b Mon Sep 17 00:00:00 2001 From: John Janus Date: Tue, 16 Apr 2019 01:35:56 +0200 Subject: [PATCH] stableparts view can now load bays dynamically needs some love, especially concerning number of requests.... --- core/templates/core/bay_detail.html | 6 ----- core/templates/core/stablepart_list.html | 25 +++--------------- core/views.py | 4 +-- static/base.js | 32 ++++++++++++++++++++++++ templates/base.html | 1 + 5 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 static/base.js diff --git a/core/templates/core/bay_detail.html b/core/templates/core/bay_detail.html index 9496e41..226fc26 100644 --- a/core/templates/core/bay_detail.html +++ b/core/templates/core/bay_detail.html @@ -1,8 +1,3 @@ -{% extends 'base.html' %} - -{% block title %}Bay {{ object }} - {{ block.super }}{% endblock %} - -{% block main %}

{{ object }}

@@ -15,4 +10,3 @@
-{% endblock %} diff --git a/core/templates/core/stablepart_list.html b/core/templates/core/stablepart_list.html index 284fa00..40625a3 100644 --- a/core/templates/core/stablepart_list.html +++ b/core/templates/core/stablepart_list.html @@ -3,31 +3,14 @@ {% block title %}Stable Parts - {{ block.super }}{% endblock %} {% block main %} - +
{% endblock %} - \ No newline at end of file +{% endblock %} diff --git a/core/views.py b/core/views.py index 23b09c0..9a747f5 100644 --- a/core/views.py +++ b/core/views.py @@ -11,7 +11,7 @@ class StableParts(ListView): class StablePartDetail(DetailView): model = StablePart - - + + class BayDetail(DetailView): model = Bay diff --git a/static/base.js b/static/base.js new file mode 100644 index 0000000..7845bff --- /dev/null +++ b/static/base.js @@ -0,0 +1,32 @@ +function setMainCards( id, cards ) { + document.getElementById(id).innerHTML = cards; + +} + +function generateCard( title, content ) { + return '

'.concat(title).concat('

').concat(content).concat('
'); +} + +function generateCardFromObject(card) { + return generateCard(card.title, card.content); +} + +function generateCards() { + // console.log(this.response); + cards += this.response; + document.getElementById('bays').innerHTML = cards; + // console.log(cards); +} +var cards; +function getBayCards(id, bayIds) { + // console.log(bayIds); + cards = ''; + + for (const bay of bayIds) { + const xhr = new XMLHttpRequest(); + // console.log('loading bay', bay); + xhr.open('GET', '/bay/'.concat(bay)); + xhr.addEventListener('load', generateCards); + xhr.send(); + } +} diff --git a/templates/base.html b/templates/base.html index 7e5e1cf..0c9c994 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,6 +5,7 @@ {% load static %} + {% block title %} Stable Management {% endblock %} -- 2.48.1