-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcsortable.js
50 lines (43 loc) · 1.41 KB
/
dcsortable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
window.AmeotokoDCSortable = {
makeSortable: function(tbody) {
const ds = new Scroller(document.getElement('body'), {
onChange: function(x, y) {
this.element.scrollTo(this.element.getScroll().x, y);
}
});
const list = new Sortables(tbody, {
constrain: true,
opacity: 0.6,
onStart: function(el) {
ds.start();
el.addClass('dragging');
},
onComplete: function(el) {
ds.stop();
el.removeClass('dragging');
},
handle: '.drag-handle'
});
list.active = false;
list.addEvent('start', function() {
list.active = true;
});
list.addEvent('complete', function(el) {
if (!list.active) return;
let id, pid, req, href;
id = el.get('data-id');
if (el.getPrevious('tr')) {
// pid is sorting value of the element, after which we drop
pid = el.getPrevious('tr').get('data-id');
} else if (el.getParent('tbody')) {
// pid is 0 if this is the very top, otherwise same as above but preceding element is the last on the previous page
pid = el.getParent('tbody').get('data-id');
}
if (id && pid) {
req = window.location.search.replace(/id=[0-9]*/, 'id=' + id) + '&act=cut&pid=' + pid;
href = window.location.href.replace(/\?.*$/, '');
new Request.Contao({'url':href + req, 'followRedirects':false}).get();
}
});
}
}