Bug 23013: Upgrade DataTables in the staff client
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / pages / stockrotation.js
blob19750c19a5ead9d06a72e30e0864f4e9fa6a014e
1 /* global KohaTable columns_settings */
3 function init() {
4     $('#ajax_status').hide();
5     $('#ajax_saving_msg').hide();
6     $('#ajax_saving_icon').hide();
7     $('#ajax_success_icon').hide();
8     $('#ajax_failed_icon').hide();
9     $('#ajax_failed_msg').hide();
12 $(document).ready(function() {
13     var apiEndpoint = '/api/v1/rotas/';
14     init();
15     $('#sortable_stages').sortable({
16         handle: '.drag_handle',
17         placeholder: 'drag_placeholder',
18         update: function(event, ui) {
19             init();
20             $('#sortable_stages').sortable('disable');
21             var rotaId = document.getElementById('sortable_stages').dataset.rotaId;
22             $('#ajax_saving_msg').text(
23                 document.getElementById('ajax_status').dataset.savingMsg
24             );
25             $('#ajax_saving_icon').show();
26             $('#ajax_saving_msg').show();
27             $('#ajax_status').fadeIn();
28             var stageId = ui.item[0].id.replace(/^stage_/, '');
29             var newIndex = ui.item.index();
30             var newPosition = newIndex + 1;
31             $.ajax({
32                 method: 'PUT',
33                 url: apiEndpoint + rotaId + '/stages/' + stageId + '/position',
34                 processData: false,
35                 contentType: 'application/json',
36                 data: newPosition
37             })
38             .done(function(data) {
39                 $('#ajax_success_msg').text(
40                     document.getElementById('ajax_status').dataset.successMsg
41                 );
42                 $('#ajax_saving_icon').hide();
43                 $('#ajax_success_icon').show();
44                 $('#ajax_success_msg').show();
45                 setTimeout(
46                     function() {
47                         $('#ajax_status').fadeOut();
48                     },
49                     700
50                 );
51             })
52             .fail(function(jqXHR, status, error) {
53                 $('#ajax_failed_msg').text(
54                     document.getElementById('ajax_status').dataset.failedMsg +
55                     error
56                 );
57                 $('#ajax_saving_icon').hide();
58                 $('#ajax_failed_icon').show();
59                 $('#ajax_failed_msg').show();
60                 $('#sortable_stages').sortable('cancel');
61             })
62             .always(function() {
63                 $('#sortable_stages').sortable('enable');
64             })
65         }
66     });
68     KohaTable("stock_rotation_manage_items", {
69         "aoColumnDefs": [
70             { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
71             { "sType": "anti-the", "aTargets": [ "anti-the" ] }
72         ],
73         "sPaginationType": "full",
74         "autoWidth": false,
75     }, stock_rotation_items_columns_settings);
77     KohaTable("stock_rotation", {
78         "aoColumnDefs": [
79             { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
80             { "sType": "anti-the", "aTargets": [ "anti-the" ] }
81         ],
82         "sPaginationType": "full",
83         "autoWidth": false,
84     }, stock_rotation_columns_settings);
86 });