forked from CGM_Public/pretix_original
Reordering questions with drag'n'drop (#1433)
* Reordering questions with drag'n'drop * Add permission check * Test permissions for question reordering * Handle malformed requests for question reordering * Show first up arrow and last down arrow * Provide page offset * Revert "Provide page offset" This reverts commit 8090bd573f851a74cca442f4651c111b8750948d. * Reorder questions endpoint with pagination support * Rudimentary test for reordering endpoint * Make reordering questions atomic * cache questions * Properly support pagination for reorder_questions * appease linter * Fix test
This commit is contained in:
45
src/pretix/static/pretixcontrol/js/ui/dragndroplist.js
Normal file
45
src/pretix/static/pretixcontrol/js/ui/dragndroplist.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/*global $, Sortable*/
|
||||
$(function () {
|
||||
$("[data-dnd-url]").each(function(){
|
||||
var container = $(this),
|
||||
url = container.data("dnd-url"),
|
||||
up = container.find("a:has(.fa-arrow-up)"),
|
||||
handle = $('<span class="btn btn-default btn-sm dnd-sort-handle"><i class="fa fa-arrows"></i></span>');
|
||||
|
||||
function hideArrows(container){
|
||||
var up = container.find("a:has(.fa-arrow-up)"),
|
||||
firstUp = up.first(),
|
||||
down = container.find("a:has(.fa-arrow-down)"),
|
||||
lastDown = down.last();
|
||||
up.not(firstUp).css("display","none");
|
||||
down.not(lastDown).css("display","none");
|
||||
firstUp.css("display","inline-block");
|
||||
lastDown.css("display","inline-block");
|
||||
}
|
||||
up.after(handle);
|
||||
hideArrows(container);
|
||||
|
||||
Sortable.create(container.get(0), {
|
||||
handle: ".dnd-sort-handle",
|
||||
onSort: function(evt){
|
||||
var container = $(evt.to),
|
||||
ids = container.find("[data-dnd-id]").toArray().map(e => e.dataset.dndId);
|
||||
|
||||
hideArrows(container);
|
||||
|
||||
$.ajax(
|
||||
{
|
||||
'type': 'POST',
|
||||
'url': url,
|
||||
'headers': {'X-CSRFToken': $("input[name=csrfmiddlewaretoken]").val()},
|
||||
'data': JSON.stringify({
|
||||
ids: ids
|
||||
}),
|
||||
'contentType': "application/json",
|
||||
'timeout': 30000
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
3703
src/pretix/static/sortable/Sortable.js
Normal file
3703
src/pretix/static/sortable/Sortable.js
Normal file
File diff suppressed because it is too large
Load Diff
2
src/pretix/static/sortable/Sortable.min.js
vendored
Normal file
2
src/pretix/static/sortable/Sortable.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user