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