mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
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 8090bd573f.
* 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
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user