Bug 23013: Upgrade DataTables in the staff client
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / pages / tags-review.js
1 $.ajaxSetup({
2     url: "/cgi-bin/koha/tags/review.pl",
3     type: "POST",
4     dataType: "script"
5 });
6
7 var ok_count  = 0;
8 var nok_count = 0;
9 var rej_count = 0;
10 var alerted = 0;
11
12 function pull_counts () {
13     ok_count  = parseInt(document.getElementById("terms_summary_approved_count"  ).innerHTML);
14     nok_count = parseInt(document.getElementById("terms_summary_unapproved_count").innerHTML);
15     rej_count = parseInt(document.getElementById("terms_summary_rejected_count"  ).innerHTML);
16 }
17
18 function count_approve () {
19     pull_counts();
20     if (nok_count > 0) {
21         $("#terms_summary_unapproved_count").html(nok_count -1);
22         $("#terms_summary_approved_count"  ).html( ok_count +1);
23     }
24 }
25
26 function count_reject () {
27     pull_counts();
28     if (nok_count > 0) {
29         $("#terms_summary_unapproved_count").html(nok_count -1);
30         $("#terms_summary_rejected_count"  ).html(rej_count +1);
31     }
32 }
33
34 var success_approve = function(tag){
35     // window.alert(_("AJAX approved tag: ") + tag);
36 };
37 var failure_approve = function(tag){
38     window.alert(MSG_AJAX_APPROVE_FAILED.format(decodeURIComponent( tag )));
39 };
40 var success_reject  = function(tag){
41     // window.alert(_("AJAX rejected tag: ") + tag);
42 };
43 var failure_reject  = function(tag){
44     window.alert(MSG_AJAX_REJECTION_FAILED.format(decodeURIComponent( tag )));
45 };
46 var success_test    = function(tag){
47     $('#verdict').html(MSG_AJAX_TAG_PERMITTED.format( decodeURIComponent( tag ) ));
48 };
49 var failure_test    = function(tag){
50     $('#verdict').html(MSG_AJAX_TAG_PROHIBITED.format( decodeURIComponent( tag ) ));
51 };
52 var indeterminate_test = function(tag){
53     $('#verdict').html(MSG_AJAX_TAG_UNCLASSIFIED.format( decodeURIComponent( tag ) ));
54 };
55
56 var success_test_call = function() {
57     $('#test_button').prop('disabled', false);
58     $('#test_button').html("<i class='fa fa-check-square-o' aria-hidden='true'></i>" +_(" Test"));
59 };
60
61 $(document).ready(function() {
62     $("#tagst").dataTable($.extend(true, {}, dataTablesDefaults, {
63         "aoColumnDefs": [
64             { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
65             { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
66             { "sType": "title-string", "aTargets" : [ "title-string" ] }
67         ],
68         "aaSorting": [[ 4, "desc" ]],
69         "sPaginationType": "full"
70     }));
71     $('.ajax_buttons' ).css({visibility:"visible"});
72     $("p.check").html("<div id=\"searchheader\"><a id=\"CheckAll\" href=\"/cgi-bin/koha/tags/review.pl\"><i class=\"fa fa-check\"><\/i> "+ LABEL_SELECT_ALL +"<\/a> | <a id=\"CheckNone\" href=\"/cgi-bin/koha/tags/review.pl\"><i class=\"fa fa-remove\"><\/i> "+ LABEL_CLEAR_ALL +"<\/a> | <a id=\"CheckPending\" href=\"/cgi-bin/koha/tags/review.pl\"> "+ LABEL_SELECT_ALL_PENDING +"<\/a><\/div>");
73     $("#CheckAll").click(function(){
74         $(".checkboxed").checkCheckboxes();
75         return false;
76     });
77     $("#CheckNone").click(function(){
78         $(".checkboxed").unCheckCheckboxes();
79         return false;
80     });
81     $("#CheckPending").click(function(){
82         $(".checkboxed").checkCheckboxes(".pending");
83         return false;
84     });
85     $(".approval_btn").on('click',function(event) {
86         event.preventDefault();
87         pull_counts();
88         var getelement;
89         var gettitle;
90         // window.alert(_("Click detected on ") + event.target + ": " + $(event.target).html);
91         if ($(event.target).is('.ok')) {
92             $.ajax({
93                 data: {
94                     ok: $(event.target).attr("title")
95                 },
96                 success: count_approve // success_approve
97             });
98             $(event.target).next(".rej").prop('disabled', false).css("color","#000");
99             $(event.target).next(".rej").html("<i class='fa fa-remove'></i> " + _("Reject"));
100             $(event.target).prop('disabled', true).css("color","#666");
101             $(event.target).html("<i class='fa fa-check'></i> " + LABEL_APPROVED );
102             getelement = $(event.target).data("num");
103             gettitle = ".status" + getelement;
104             $(gettitle).text( LABEL_APPROVED );
105             if ($(gettitle).hasClass("pending") ){
106                 $(gettitle).toggleClass("pending approved");
107             } else {
108                 $(gettitle).toggleClass("rejected approved");
109             }
110         }
111         if ($(event.target).is('.rej')) {
112             $.ajax({
113                 data: {
114                     rej: $(event.target).attr("title")
115                 },
116                 success: count_reject // success_reject
117             });
118             $(event.target).prev(".ok").prop('disabled', false).css("color","#000");
119             $(event.target).prev(".ok").html("<i class='fa fa-check'></i> " + LABEL_APPROVE );
120             $(event.target).prop('disabled', true).css("color","#666");
121             $(event.target).html("<i class='fa fa-remove'></i> " + LABEL_REJECTED );
122             getelement = $(event.target).data("num");
123             gettitle = ".status" + getelement;
124             $(gettitle).text( LABEL_REJECTED );
125             if ($(gettitle).hasClass("pending") ){
126                 $(gettitle).toggleClass("pending rejected");
127             } else {
128                 $(gettitle).toggleClass("approved rejected");
129             }
130             return false;   // cancel submit
131         }
132         if ($(event.target).is('#test_button')) {
133             $(event.target).text( LABEL_TESTING ).prop('disabled', true);
134             $.ajax({
135                 data: {
136                     test: $('#test').attr("value")
137                 },
138                 success: success_test_call // success_reject
139             });
140             return false;   // cancel submit
141         }
142     });
143     $("*").ajaxError(function(evt, request, settings){
144         if ((alerted +=1) <= 1){ window.alert(MSG_AJAX_ERROR.format(alerted)); }
145     });
146
147     var reviewerField = $("#approver");
148     reviewerField.autocomplete({
149         source: "/cgi-bin/koha/circ/ysearch.pl",
150         minLength: 3,
151         select: function( event, ui ) {
152             reviewerField.val( ui.item.borrowernumber );
153             return false;
154         }
155     })
156     .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
157         return $( "<li></li>" )
158         .data( "ui-autocomplete-item", item )
159         .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
160         .appendTo( ul );
161     };
162 });