Bug 9528: Add delivery branch to the place hold display
[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
68                                     if ( oObj.waiting_here ) {
69                                         data += ITEM_IS_WAITING_HERE;
70                                     } else {
71                                         data += ITEM_IS_WAITING;
72                                         data += " " + AT.format( oObj.waiting_at );
73                                     }
74
75                                 } else if ( oObj.transferred ) {
76                                     data += ITEM_IS_IN_TRANSIT.format( oObj.from_branch, oObj.date_sent );
77                                 } else if ( oObj.not_transferred ) {
78                                     data += NOT_TRANSFERRED_YET.format( oObj.not_transferred_by );
79                                 }
80                                 data += "</em>";
81
82                                 data += " <a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
83                                   + oObj.biblionumber
84                                   + "&itemnumber="
85                                   + oObj.itemnumber
86                                   + "#"
87                                   + oObj.itemnumber
88                                   + "'>"
89                                   + oObj.barcode
90                                   + "</a>";
91                             }
92
93                             return data;
94                         }
95                     },
96                     {
97                         "mDataProp": function( oObj ) {
98                             return oObj.branchcode || "";
99                         }
100                     },
101                     { "mDataProp": "expirationdate_formatted" },
102                     {
103                         "mDataProp": function( oObj ) {
104                             if ( oObj.priority && parseInt( oObj.priority ) && parseInt( oObj.priority ) > 0 ) {
105                                 return oObj.priority;
106                             } else {
107                                 return "";
108                             }
109                         }
110                     },
111                     {
112                         "bSortable": false,
113                         "mDataProp": function( oObj ) {
114                             return "<select name='rank-request'>"
115                                  + "<option value='n'>" + NO + "</option>"
116                                  + "<option value='del'>" + YES  + "</option>"
117                                  + "</select>"
118                                  + "<input type='hidden' name='biblionumber' value='" + oObj.biblionumber + "'>"
119                                  + "<input type='hidden' name='borrowernumber' value='" + borrowernumber + "'>"
120                                  + "<input type='hidden' name='reserve_id' value='" + oObj.reserve_id + "'>";
121                         }
122                     }
123                 ],
124                 "bPaginate": false,
125                 "bProcessing": true,
126                 "bServerSide": false,
127                 "sAjaxSource": '/cgi-bin/koha/svc/holds',
128                 "fnServerData": function ( sSource, aoData, fnCallback ) {
129                     aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
130
131                     $.getJSON( sSource, aoData, function (json) {
132                         fnCallback(json)
133                     } );
134                 },
135             });
136
137             if ( $("#holds-table").length ) {
138                 $("#holds-table_processing").position({
139                     of: $( "#holds-table" ),
140                     collision: "none"
141                 });
142             }
143         }
144     }
145 });