mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-13 00:22:22 +01:00
70 lines
2.3 KiB
JavaScript
70 lines
2.3 KiB
JavaScript
$(function () {
|
|
$(document).on('click', '[data-song-id]', function () {
|
|
var songId = $(this).data('song-id');
|
|
window.location.href = "/songs/edit/" + songId;
|
|
return false;
|
|
});
|
|
|
|
$('#search-artist, #search-title, #search-uploader, .pagenum').change(function(){
|
|
getSongs();
|
|
});
|
|
|
|
$('.pagesize').change(function(){
|
|
$('.pagenum').val(1);
|
|
getSongs();
|
|
});
|
|
|
|
$('button.prev').click(function(){
|
|
var pageNumSelect = $('.pagenum');
|
|
pageNumSelect.val(Math.max(parseInt(pageNumSelect.val()) - 1, 1));
|
|
getSongs();
|
|
});
|
|
|
|
$('button.next').click(function(){
|
|
var pageNumSelect = $('.pagenum');
|
|
pageNumSelect.val(Math.min(parseInt(pageNumSelect.val()) + 1, pageNumSelect.children('option:last-child').val()));
|
|
getSongs();
|
|
});
|
|
|
|
$('button.first').click(function(){
|
|
$('.pagenum').val(1);
|
|
getSongs();
|
|
});
|
|
|
|
$('button.last').click(function(){
|
|
var pageNumSelect = $('.pagenum');
|
|
pageNumSelect.val(pageNumSelect.children('option:last-child').val());
|
|
getSongs();
|
|
});
|
|
|
|
getSongs();
|
|
});
|
|
|
|
function getSongs()
|
|
{
|
|
var artist = $('#search-artist').val();
|
|
var title = $('#search-title').val();
|
|
var uploader = $('#search-uploader').val();
|
|
var page = $('.pagenum').val();
|
|
var pagesize = $('.pagesize').val();
|
|
$.post('/api/managesongs', {artist: artist, title: title, page: page, pagesize: pagesize, csrfmiddlewaretoken: csrf_token}, function (result) {
|
|
$('#request-table tbody').empty();
|
|
songs = result.data;
|
|
$.each(songs, function (index, song) {
|
|
var artist = song.artist.trim() === '' ? '?' : song.artist;
|
|
var title = song.title.trim() === '' ? '?' : song.title;
|
|
$('#request-table tbody:last-child').append('<tr><td>' + artist + '</td><td><a href="#" data-song-id="' + song.id + '">' + title + '</a></td></tr>');
|
|
});
|
|
var pageNumSelect = $('.pagenum');
|
|
pageNumSelect.empty();
|
|
for(var i = 1; i < result.last_page + 1; i++)
|
|
{
|
|
pageNumSelect.append($("<option></option>")
|
|
.attr("value", i)
|
|
.text(i));
|
|
}
|
|
pageNumSelect.val(result.current_page);
|
|
$('.pagesize').val(result.per_page);
|
|
});
|
|
}
|