Bug 11703: (followup) svc/holds invoked with trailing .pl
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / holds.js
1 $(document).ready(function() {
2     // Don't load holds table unless it is clicked on
3     var holdsTable;
4     $("#holds-tab").click( function() {
5         if ( ! holdsTable ) {
6             holdsTable = $("#holds-table").dataTable({
7                 "bAutoWidth": false,
8                 "sDom": "<'row-fluid'<'span6'><'span6'>r>t<'row-fluid'>t",
9                 "aoColumns": [
10                     {
11                         "mDataProp": "reservedate_formatted"
12                     },
13                     {
14                         "mDataProp": function ( oObj ) {
15                             title = "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber="
16                                   + oObj.biblionumber
17                                   + "'>"
18                                   + oObj.title;
19
20                             $.each(oObj.subtitle, function( index, value ) {
21                                       title += " " + value.subfield;
22                             });
23
24                             title += "</a>";
25
26                             if ( oObj.author ) {
27                                 title += " " + BY.replace( "_AUTHOR_",  oObj.author );
28                             }
29
30                             if ( oObj.itemnotes ) {
31                                 var span_class = "";
32                                 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
33                                     span_class = "circ-hlt";
34                                 }
35                                 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
36                             }
37
38                             return title;
39                         }
40                     },
41                     {
42                         "mDataProp": function( oObj ) {
43                             return oObj.itemcallnumber || "";
44                         }
45                     },
46                     {
47                         "mDataProp": function( oObj ) {
48                             var data = "";
49
50                             if ( oObj.suspend == 1 ) {
51                                 data += "<p>" + HOLD_IS_SUSPENDED;
52                                 if ( oObj.suspend_until ) {
53                                     data += " " + UNTIL.format( oObj.suspend_until_formatted );
54                                 }
55                                 data += "</p>";
56                             }
57
58                             if ( oObj.barcode ) {
59                                 data += "<em>";
60                                 if ( oObj.found == "W" ) {
61                                     data += ITEM_IS_WAITING;
62
63                                     if ( ! oObj.waiting_here ) {
64                                         data += " " + AT.format( oObj.waiting_at );
65                                     }
66                                 } else if ( oObj.transferred ) {
67                                     data += ITEM_IS_IN_TRANSIT.format( oObj.from_branch );
68                                 } else if ( oObj.not_transferred ) {
69                                     data += NOT_TRANSFERRED_YET.format( oObj.not_transferred_by );
70                                 }
71                                 data += "</em>";
72
73                                 data += " <a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
74                                   + oObj.biblionumber
75                                   + "&itemnumber="
76                                   + oObj.itemnumber
77                                   + "#"
78                                   + oObj.itemnumber
79                                   + "'>"
80                                   + oObj.barcode
81                                   + "</a>";
82                             }
83
84                             return data;
85                         }
86                     },
87                     { "mDataProp": "expirationdate_formatted" },
88                     {
89                         "mDataProp": function( oObj ) {
90                             if ( oObj.priority && parseInt( oObj.priority ) && parseInt( oObj.priority ) > 0 ) {
91                                 return oObj.priority;
92                             } else {
93                                 return "";
94                             }
95                         }
96                     },
97                     {
98                         "bSortable": false,
99                         "mDataProp": function( oObj ) {
100                             return "<select name='rank-request'>"
101                                  + "<option value='n'>" + NO + "</option>"
102                                  + "<option value='del'>" + YES  + "</option>"
103                                  + "</select>"
104                                  + "<input type='hidden' name='biblionumber' value='" + oObj.biblionumber + "'>"
105                                  + "<input type='hidden' name='borrowernumber' value='" + borrowernumber + "'>"
106                                  + "<input type='hidden' name='reserve_id' value='" + oObj.reserve_id + "'>";
107                         }
108                     }
109                 ],
110                 "bPaginate": false,
111                 "bProcessing": true,
112                 "bServerSide": false,
113                 "sAjaxSource": '/cgi-bin/koha/svc/holds',
114                 "fnServerData": function ( sSource, aoData, fnCallback ) {
115                     aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
116
117                     $.getJSON( sSource, aoData, function (json) {
118                         fnCallback(json)
119                     } );
120                 },
121             });
122
123             if ( $("#holds-table").length ) {
124                 $("#holds-table_processing").position({
125                     of: $( "#holds-table" ),
126                     collision: "none"
127                 });
128             }
129         }
130     });
131
132 });