Bug 19532: Recalls on intranet
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / recalls.js
1 $(document).ready(function() {
2
3         $(".cancel_recall").click(function(e){
4             if (confirmDelete(__("Are you sure you want to remove this recall?"))){
5                 var $self = $(this);
6                 var $recall_id = $(this).data('id');
7                 var $action = $(this).data('action');
8                 var ajaxData = {
9                     'recall_id': $recall_id,
10                     'action'   : $action,
11                 };
12
13                 $.ajax({
14                     url: '/cgi-bin/koha/svc/recall',
15                     type: 'POST',
16                     dataType: 'json',
17                     data: ajaxData,
18                 })
19                 .done(function(data) {
20                     var message = "";
21                     if(data.success == 0) {
22                         message = __("The recall may have already been cancelled. Please refresh the page.");
23                     } else {
24                         message = __("Cancelled");
25                     }
26                     $self.parent().parent().parent().parent().html(message);
27                 });
28             }
29         });
30
31         $(".expire_recall").click(function(e){
32             if (confirmDelete(__("Are you sure you want to expire this recall?"))){
33                 var $self = $(this);
34                 var $recall_id = $(this).data('id');
35                 var $action = $(this).data('action');
36                 var ajaxData = {
37                     'recall_id': $recall_id,
38                     'action'   : $action,
39                 };
40
41                 $.ajax({
42                     url: '/cgi-bin/koha/svc/recall',
43                     type: 'POST',
44                     dataType: 'json',
45                     data: ajaxData,
46                 })
47                 .done(function(data) {
48                     var message = "";
49                     if(data.success == 0) {
50                         message = __("The recall may have already been expired. Please refresh the page.");
51                     } else {
52                         message = __("Expired");
53                     }
54                     $self.parent().parent().parent().parent().html(message);
55                 });
56             }
57         });
58
59         $(".revert_recall").click(function(e){
60             if (confirmDelete(__("Are you sure you want to revert the waiting status of this recall?"))){
61                 var $self = $(this);
62                 var $recall_id = $(this).data('id');
63                 var $action = $(this).data('action');
64                 var ajaxData = {
65                     'recall_id': $recall_id,
66                     'action'   : $action,
67                 };
68
69                 $.ajax({
70                     url: '/cgi-bin/koha/svc/recall',
71                     type: 'POST',
72                     dataType: 'json',
73                     data: ajaxData,
74                 })
75                 .done(function(data) {
76                     var message = "";
77                     if(data.success == 0) {
78                         message = __("The recall waiting status may have already been reverted. Please refresh the page.");
79                     } else {
80                         message = __("Status updated");
81                     }
82                     $self.parent().parent().parent().parent().html(message);
83                 });
84             }
85         });
86
87         $(".overdue_recall").click(function(e){
88             if (confirmDelete(__("Are you sure you want to mark this recall as overdue?"))){
89                 var $self = $(this);
90                 var $recall_id = $(this).data('id');
91                 var $action = $(this).data('action');
92                 var ajaxData = {
93                     'recall_id': $recall_id,
94                     'action'   : $action,
95                 };
96
97                 $.ajax({
98                     url: '/cgi-bin/koha/svc/recall',
99                     type: 'POST',
100                     dataType: 'json',
101                     data: ajaxData,
102                 })
103                 .done(function(data) {
104                     var message = "";
105                     if(data.success == 0) {
106                         message = __("The recall may have already been marked as overdue. Please refresh the page.");
107                     } else {
108                         message = __("Marked overdue");
109                     }
110                     $self.parent().parent().parent().parent().html(message);
111                 });
112             }
113         });
114
115         $(".transit_recall").click(function(e){
116             if (confirmDelete(__("Are you sure you want to remove this recall and return the item to it's home library?"))){
117                 var $self = $(this);
118                 var $recall_id = $(this).data('id');
119                 var $action = $(this).data('action');
120                 var ajaxData = {
121                     'recall_id': $recall_id,
122                     'action'   : $action,
123                 };
124
125                 $.ajax({
126                     url: '/cgi-bin/koha/svc/recall',
127                     type: 'POST',
128                     dataType: 'json',
129                     data: ajaxData,
130                 })
131                 .done(function(data) {
132                     var message = "";
133                     if(data.success == 0) {
134                         message = __("The recall may have already been removed. Please refresh the page.");
135                     } else {
136                         message = __("Cancelled");
137                     }
138                     $self.parent().parent().parent().parent().html(message);
139                 });
140             }
141         });
142
143         $("#recalls-table").dataTable($.extend(true, {}, dataTablesDefaults, {
144             "aoColumnDefs": [
145                 { 'bSortable': false, 'aTargets': [ 'nosort' ] },
146                 { "sType": "title-string", "aTargets" : [ "title-string" ] },
147                 { "sType": "anti-the", "aTargets": [ "anti-the" ] }
148             ],
149             "sPaginationType": "full_numbers"
150         }));
151
152         $("#cancel_selected").click(function(e){
153             if ($("input[name='recall_ids']:checked").length > 0){
154                 return confirmDelete(__("Are you sure you want to remove the selected recall(s)?"));
155             } else {
156                 alert(__("Please make a selection."));
157             }
158         });
159
160         $("#select_all").click(function(){
161             if ($("#select_all").prop("checked")){
162                 $("input[name='recall_ids']").prop("checked", true);
163             } else {
164                 $("input[name='recall_ids']").prop("checked", false);
165             }
166         });
167
168         $("#hide_old").click(function(){
169             if ($("#hide_old").prop("checked")){
170                 $(".old").show();
171             } else {
172                 $(".old").hide();
173             }
174         });
175 });