backend.js
2.44 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Checkbox event
$(document).ready(function () {
$('.i-checks').iCheck({
checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green',
});
});
// Save and Exit POST value
$('.action_save_and_exit').click(function () {
$('input[name=\"save_and_exit\"]').val(1);
});
// Ajax checkbox
$('.ajax-switcher').on('ifChanged', function () {
jQuery.ajax({
'url': $(this).data('url'),
'cache': false,
'data': {
id: $(this).data('id'),
},
success: function (data) {
},
error: function (err) {
console.log(err);
}
});
});
// Ajax status switcher
$('.ajax-status-switcher').on('click', function () {
var obj = this;
jQuery.ajax({
'url': $(obj).data('url'),
'cache': false,
'data': {
id: $(obj).data('id'),
},
success: function (data) {
var switches = $(obj).parent().find('.ajax-status-switcher');
//console.log($(obj).parent(), switches);
switches.each(function () {
var style = $(this).css('display');
//console.log(style);
$(this).css('display', style == 'inline' ? 'none' : 'inline');
});
},
error: function (err) {
console.log(err);
}
});
});
// Sortable rows
var sorted_table_cache = {};
$('.sorted_table').sortable({
containerSelector: 'table',
itemPath: '> tbody',
itemSelector: 'tr',
placeholder: '<td class="sortplace"/>',
delay: 500,
onDrop: function ($item, container, _super) {
var sort_url = $item.closest('table').attr('data-sortableurl');
var csrf = $item.closest('table').attr('data-csrf');
var tableid = $item.closest('table').attr('id');
console.log(sort_url);
var rows_data = [];
$item.closest('table').find('tbody tr').each(function (i, row) {
var row = $(row).attr('data-key');
if (row != undefined) {
console.log(row);
rows_data.push(row);
}
});
//вставить проверку одинаковый ли массив, если нет, то отослать сохранение в БД
sorted_table_cache[tableid] = rows_data;
console.log(sorted_table_cache);
$.post(sort_url, {rows_data: rows_data, _csrf: csrf});
_super($item, container);
}
});