mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-14 12:42:20 +01:00
Initial commit.
This commit is contained in:
69
marietje/static/js/manage.js
Normal file
69
marietje/static/js/manage.js
Normal file
@ -0,0 +1,69 @@
|
||||
$(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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user