Bug 34913: DataTables upgrade: Update CSS and option names
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / pages / stockrotation.js
1 /* global KohaTable columns_settings Sortable */
2
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();
10 }
11
12 $(document).ready(function() {
13     var apiEndpoint = '/api/v1/rotas/';
14     init();
15     var sortable = document.getElementById("sortable_stages");
16     if( sortable ){
17         var sortable_stages = new Sortable( sortable, {
18             handle: ".drag_handle",
19             ghostClass: "drag_placeholder",
20             onUpdate: function(e) {
21                 init();
22                 sortable_stages.option("disabled", true );
23                 var rotaId = document.getElementById('sortable_stages').dataset.rotaId;
24                 $('#ajax_saving_msg').text(
25                     document.getElementById('ajax_status').dataset.savingMsg
26                 );
27                 $('#ajax_saving_icon').show();
28                 $('#ajax_saving_msg').show();
29                 $('#ajax_status').fadeIn();
30                 var stageId = e.item.id.replace(/^stage_/, '');
31                 var newIndex = e.newIndex;
32                 var newPosition = newIndex + 1;
33                 $.ajax({
34                     method: 'PUT',
35                     url: apiEndpoint + rotaId + '/stages/' + stageId + '/position',
36                     processData: false,
37                     contentType: 'application/json',
38                     data: newPosition
39                 })
40                     .done(function() {
41                         $('#ajax_success_msg').text(
42                             document.getElementById('ajax_status').dataset.successMsg
43                         );
44                         $('#ajax_saving_icon').hide();
45                         $('#ajax_success_icon').show();
46                         $('#ajax_success_msg').show();
47                         setTimeout(
48                             function() {
49                                 $('#ajax_status').fadeOut();
50                             },
51                             700
52                         );
53                     })
54                     .fail(function(jqXHR, status, error) {
55                         $('#ajax_failed_msg').text(
56                             document.getElementById('ajax_status').dataset.failedMsg +
57                             error
58                         );
59                         $('#ajax_saving_icon').hide();
60                         $('#ajax_failed_icon').show();
61                         $('#ajax_failed_msg').show();
62                     })
63                     .always(function() {
64                         sortable_stages.option("disabled", false );
65                     });
66             }
67         });
68     }
69
70     KohaTable("stock_rotation_manage_items", {
71         "columnDefs":  [
72             { "orderable":  false, "searchable":  false, "targets":  [ 'NoSort' ] },
73             { "type":  "anti-the", "targets":  [ "anti-the" ] }
74         ],
75         "pagingType":  "full",
76         "autoWidth": false,
77     }, stock_rotation_items_table_settings);
78
79     KohaTable("stock_rotation", {
80         "columnDefs":  [
81             { "orderable":  false, "searchable":  false, "targets":  [ 'NoSort' ] },
82             { "type":  "anti-the", "targets":  [ "anti-the" ] }
83         ],
84         "pagingType":  "full",
85         "autoWidth": false,
86     }, stock_rotation_table_settings);
87
88 });