Add PDF export/printing for list of played songs

This commit is contained in:
Phillip Kühne 2019-06-29 02:12:23 +02:00
parent 5f551ac092
commit 703382cb1a
3 changed files with 46 additions and 16 deletions

View File

@ -4,11 +4,13 @@
{% block title %}Home{% endblock %} {% block title %}Home{% endblock %}
{% block content %} {% block content %}
<table class="table"> <table class="table">
<tr> <thead>
<th scope="col">Name</th> <tr>
<th scope="col">Song</th> <th scope="col">Name</th>
<th scope="col">Künstler</th> <th scope="col">Song</th>
</tr> <th scope="col">Künstler</th>
</tr>
</thead>
{% for entry in list: %} {% for entry in list: %}
<tr> <tr>
<td> <td>

View File

@ -17,12 +17,14 @@
</div> </div>
<div class="row"> <div class="row">
<table class="table"> <table class="table">
<tr> <thead>
<th scope="col">Name</th> <tr>
<th scope="col">Song</th> <th scope="col">Name</th>
<th scope="col">Künstler</th> <th scope="col">Song</th>
<th scope="col">Aktionen</th> <th scope="col">Künstler</th>
</tr> <th scope="col">Aktionen</th>
</tr>
</thead>
{% for entry in list: %} {% for entry in list: %}
<tr> <tr>
<td> <td>

View File

@ -5,13 +5,18 @@
<div class="card-body"> <div class="card-body">
<button type="button" class="topbutton btn btn-danger" onclick="confirmDeleteAllEntries()"><i <button type="button" class="topbutton btn btn-danger" onclick="confirmDeleteAllEntries()"><i
class="fas fa-trash mr-2"></i>Abspielliste löschen</button> class="fas fa-trash mr-2"></i>Abspielliste löschen</button>
<button type="button" class="topbutton btn" onclick="printPDF()"><i class="fas fa-print mr-2"></i>Drucken</button>
<button type="button" class="topbutton btn" onclick="exportPDF()"><i class="fas fa-file-pdf mr-2"></i>Als PDF
herunterladen</button>
</div> </div>
</div> </div>
<table class="table"> <table class="table" id="table">
<tr> <thead>
<th scope="col">Song</th> <tr>
<th scope="col">Wiedergaben</th> <th scope="col">Song</th>
</tr> <th scope="col">Wiedergaben</th>
</tr>
</thead>
{% for entry in list: %} {% for entry in list: %}
<tr> <tr>
<td> <td>
@ -26,6 +31,8 @@
</table> </table>
{% endblock %} {% endblock %}
{% block extrajs %} {% block extrajs %}
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
<script src="https://unpkg.com/jspdf-autotable@3.1.1/dist/jspdf.plugin.autotable.js"></script>
<script> <script>
function confirmDeleteAllEntries() { function confirmDeleteAllEntries() {
bootbox.confirm({ bootbox.confirm({
@ -57,5 +64,24 @@
}); });
location.reload(); location.reload();
} }
function exportPDF() {
var doc = new jsPDF();
doc.autoTable({
html: '#table',
theme: 'grid'
});
doc.save('Abspielliste.pdf');
}
function printPDF() {
var doc = new jsPDF();
doc.autoTable({
html: '#table',
theme: 'grid'
});
doc.autoPrint();
doc.output('dataurlnewwindow');
}
</script> </script>
{% endblock %} {% endblock %}