Bug 28069: (bug 27715 follow-up) Fix sort for lists
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / virtualshelves / shelves.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% SET PRIVATE = 1 %]
6 [% SET PUBLIC = 2 %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>Koha &rsaquo; [% IF op == 'view' %]Lists &rsaquo; Contents of [% shelf.shelfname | html %][% ELSE %]Lists[% END %][% IF op == 'add_form' %] &rsaquo; Create new list[% END %][% IF op == 'edit_form' %] &rsaquo; Edit list [% shelf.shelfname | html %][% END %]</title>
10 [% INCLUDE 'doc-head-close.inc' %]
11 <style>textarea { width: 100%; }</style>
12
13 [% BLOCK list_permissions %]
14     <li>
15         <label for="allow_changes_from">Allow changes to contents from: </label>
16         <select name="allow_changes_from" id="allow_changes_from" onchange="AdjustRemark()">
17
18             [% IF shelf.allow_change_from_owner %]<option value="0">Nobody</option>[% ELSE %]<option value="0" selected="selected">Nobody</option>[% END %]
19
20             [% IF shelf.allow_change_from_owner && (( !shelf.is_public && !shelf.is_shared ) || !shelf.allow_change_from_others ) %]
21                 <option value="1" selected="selected">Owner only</option>
22             [% ELSE %]
23                 <option value="1">Owner only</option>
24             [% END %]
25
26             [% IF shelf.allow_change_from_others %]<option value="2" selected="selected">Anyone seeing this list</option>[% ELSE %]<option value="2">Anyone seeing this list</option>[% END %]
27
28         </select>
29         &emsp; <span id="anyone_remark" style="display:none;color:red;">The Anyone permission has no actual effect while this list is strictly private.</span>
30     </li>
31 [% END %]
32 </head>
33
34 <body id="lists_shelves" class="lists">
35 [% INCLUDE 'header.inc' %]
36 [% INCLUDE 'cat-search.inc' %]
37
38 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
39     <ol>
40         <li>
41             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
42         </li>
43
44         [% IF op != 'list' %]
45             <li>
46                 <a href="/cgi-bin/koha/virtualshelves/shelves.pl">Lists</a>
47             </li>
48         [% ELSE %]
49             <li>
50                 <a href="#" aria-current="page">
51                     Lists
52                 </a>
53             </li>
54         [% END %]
55
56         [% IF shelf AND shelf.is_private %]
57             [% IF op == 'view' OR op == 'edit_form' %]
58                 <li>
59                     <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PRIVATE | uri %]">Your lists</a>
60                 </li>
61             [% ELSE %]
62                 <li>
63                     <a href="#" aria-current="page">
64                         Your lists
65                     </a>
66                 </li>
67             [% END %]
68
69         [% ELSIF shelf AND shelf.is_public %]
70             [% IF op == 'view' %]
71                 <li>
72                     <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PUBLIC | uri %]">Public lists</a>
73                 </li>
74             [% ELSE %]
75                 <li>
76                     <a href="#" aria-current="page">
77                         Public lists
78                     </a>
79                 </li>
80             [% END %]
81         [% END %]
82
83         [% IF op == 'view' %]
84             <li>
85                 <a href="#" aria-current="page">
86             Contents of <em>[% shelf.shelfname | html %]</em>
87                 </a>
88             </li>
89         [% END %]
90
91         [% IF op == 'add_form' %]
92             <li>
93                 <a href="#" aria-current="page">
94                     Create new list
95                 </a>
96             </li>
97         [% END %]
98
99         [% IF op == 'edit_form' %]
100             <li>
101                 <a href="#" aria-current="page">
102                     Edit list <em>[% shelf.shelfname | html %]</em>
103                 </a>
104             </li>
105         [% END %]
106     </ol>
107 </nav>
108
109     <div class="main container-fluid">
110         <div class="row">
111             <div class="col-sm-10 col-sm-push-1">
112                 <main>
113
114                 [% INCLUDE 'virtualshelves-toolbar.inc' %]
115
116 [% FOR m IN messages %]
117     <div class="dialog [% m.type | html %]">
118         [% SWITCH m.code %]
119         [% CASE 'error_on_update' %]
120             <span>An error occurred when updating this list.</span>
121         [% CASE 'error_on_insert' %]
122             <span>An error occurred when creating this list.</span>
123         [% CASE 'error_on_delete' %]
124             <span>An error occurred when deleting this list.</span>
125         [% CASE 'error_on_add_biblio' %]
126             [% IF m.item_barcode %]
127                <span>The item ([% m.item_barcode | html %]) has not been added to the list. Please verify it is not already in the list.</span>
128             [% ELSE %]
129                 <span>The record ([% m.bibnum | html %]) has not been added to the list. Please verify it is not already in the list.</span>
130             [% END %]
131         [% CASE 'success_on_update' %]
132             <span>List updated.</span>
133         [% CASE 'success_on_insert' %]
134             <span>List created.</span>
135         [% CASE 'success_on_delete' %]
136             <span>List deleted.</span>
137         [% CASE 'success_on_add_biblio' %]
138             [% IF m.item_barcode %]
139                 <span>The item ([% m.item_barcode | html %]) has been added to the list.</span>
140             [% ELSE %]
141                 <span>The record ([% m.bibnum | html %]) has been added to the list.</span>
142             [% END %]
143         [% CASE 'success_on_remove_biblios' %]
144             <span>The item has been removed from the list.</span>
145         [% CASE 'does_not_exist' %]
146             <span>This list does not exist.</span>
147         [% CASE 'item_does_not_exist' %]
148             [% IF m.item_barcode %]
149                 <span>The item ([% m.item_barcode | html %]) does not exist.</span>
150             [% ELSE %]
151                 <span>The record ([% m.bibnum | html %]) does not exist.</span>
152             [% END %]
153         [% CASE 'unauthorized_on_view' %]
154             <span>You do not have permission to view this list.</span>
155         [% CASE 'unauthorized_on_update' %]
156             <span>You do not have permission to update this list.</span>
157         [% CASE 'unauthorized_on_delete' %]
158            <span>You do not have permission to delete this list.</span>
159         [% CASE 'unauthorized_on_add_biblio' %]
160             <span>You do not have permission to add a record to this list.</span>
161         [% CASE 'no_biblio_removed' %]
162             <span>No record was removed.</span>
163         [% CASE 'Koha::Exceptions::Virtualshelves::DuplicateObject' %]
164             <span>An error occurred when creating this list. The name [% shelfname | html %] already exists.</span>
165         [% CASE 'Koha::Exceptions::Virtualshelves::UseDbAdminAccount' %]
166             <span>List could not be created. (Do not use the database administrator account.)</span>
167         [% CASE 'DBIx::Class::Exception' %]
168             [% m.msg | html %]
169         [% CASE %]
170             [% m.code | html %] [% m.msg | html %]
171         [% END %]
172     </div>
173 [% END %]
174
175 [% IF op == 'view' %]
176     [% IF itemsloop %]
177
178     <h3>Contents of <em>[% shelf.shelfname | html %]</em></h3>
179     <div class="pages">[% pagination_bar | $raw %]</div>
180     <form action="/cgi-bin/koha/virtualshelves/shelves.pl" id="listform" method="post">
181         <input type="hidden" name="op" value="remove_biblios" />
182         <input type="hidden" name="referer" value="view" />
183         <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
184
185 [% IF direction == 'asc' %]
186     [% SET new_direction = 'desc' %]
187 [% ELSE %]
188     [% SET direction = 'desc' %]
189     [% SET new_direction = 'asc' %]
190 [% END %]
191
192 [% IF itemsloop %]
193     <div id="searchheader" class="searchheader noprint">
194         <div id="selection_ops"><span class="checkall"></span> |
195         <span class="clearall"></span>
196
197         <span class="addto">| </span>
198         &nbsp;
199         [% IF CAN_user_reserveforothers && Koha.Preference('DisplayMultiPlaceHold') %]
200             <div class="btn-group"><button class="btn btn-default btn-xs placehold"><i class="fa fa-sticky-note-o"></i> Place hold</button></div>
201         [% END %]
202         [% IF can_remove_biblios %]
203             <div class="btn-group"><button type="submit" class="btn btn-default btn-xs list-remove"><i class="fa fa-trash"></i> Remove selected</button></div>
204         [% END %]
205         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]<div class="btn-group"><button type="submit" class="btn btn-default btn-xs merge-items"><i class="fa fa-compress"></i> Merge selected</button></div>[% END %]
206         </div>
207     </div>
208 [% END %]
209
210     <table id="searchresults" class="dataTable">
211         <thead>
212             <tr>
213                 [% IF ( itemsloop ) %]<th class="checkall">&nbsp;</th>[% END %]
214
215                 [% UNLESS ( item_level_itypes ) %]<th>Item type</th>[% END %]
216                 [% IF sortfield == 'title' %]
217                     <th class="sorting_[% direction | html %]">
218                 [% ELSE %]
219                     <th class="sorting">
220                 [% END %]
221                     <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&amp;shelfnumber=[% shelf.shelfnumber | uri %]&amp;sortfield=title&amp;direction=[% IF sortfield != 'title' %]asc[% ELSE %][% new_direction | uri %][% END %]">Title</a>
222                 </th>
223                 [% IF sortfield == 'author' %]
224                     <th class="sorting_[% direction | html %]">
225                 [% ELSE %]
226                     <th class="sorting">
227                 [% END %]
228                     <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&amp;shelfnumber=[% shelf.shelfnumber | uri %]&amp;sortfield=author&amp;direction=[% IF sortfield != 'author' %]asc[% ELSE %][% new_direction | uri %][% END %]">Author</a>
229                 </th>
230                 [% IF sortfield == 'dateadded' %]
231                     <th class="sorting_[% direction | html %]">
232                 [% ELSE %]
233                     <th class="sorting">
234                 [% END %]
235                     <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&amp;shelfnumber=[% shelf.shelfnumber | uri %]&amp;sortfield=dateadded&amp;direction=[% IF sortfield != 'dateadded' %]asc[% ELSE %][% new_direction | uri %][% END %]">Date added</a>
236                 </th>
237                 [% IF sortfield == 'itemcallnumber' %]
238                      <th class="sorting_[% direction | html %]">
239                 [% ELSE %]
240                     <th class="sorting">
241                 [% END %]
242                     <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&amp;shelfnumber=[% shelf.shelfnumber | uri %]&amp;sortfield=itemcallnumber&amp;direction=[% IF sortfield != 'itemcallnumber' %]asc[% ELSE %][% new_direction | uri %][% END %]">Call number</a>
243                  </th>
244             </tr>
245         </thead>
246         [% FOREACH itemsloo IN itemsloop %]
247                 <tr>
248             [% IF itemsloop %]
249                 <td>
250                     <input type="checkbox" class="selection" value="[% itemsloo.biblionumber | html %]" name="biblionumber" />
251                 </td>
252             [% END %]
253                         [% UNLESS ( item_level_itypes ) %]<td>
254                 [% UNLESS ( noItemTypeImages || !itemsloo.imageurl ) %]<img src="[% itemsloo.imageurl | html %]" alt="[% itemsloo.description | html %]" title="[% itemsloo.description | html %]" />[% END %][% itemsloo.description | html %]
255                         </td>[% END %]
256                         <td>
257                 [% IF ( itemsloo.XSLTBloc ) %]
258                     [% itemsloo.XSLTBloc | $raw %]
259                 [% ELSE %]
260                         [% INCLUDE 'biblio-title.inc' biblio=itemsloo link = 1 %]
261                     </a>
262                 [% END %]
263                     <p class="hold">
264                         [% IF ( itemsloo.notforloan ) %]
265                             <span class="noholdstext">No holds allowed</span>
266                         [% ELSE %]
267                             [% IF ( itemsloo.ITEM_RESULTS.size ) %]
268                                 <a id="reserve_[% itemsloo.biblionumber | html %]" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% itemsloo.biblionumber | html %]">Holds</a>
269                                 [% IF ( holdfor ) %] <span class="holdforlink">| <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% itemsloo.biblionumber | uri %]&amp;findborrower=[% holdfor_cardnumber | uri %]">Place hold for [% holdfor_firstname | html %] [% holdfor_surname | html %] ([% holdfor_cardnumber | html %])</a></span>[% END %]
270                             [% ELSE %]
271                                 <span class="noholdstext">No holds allowed</span>
272                             [% END %]
273                         [% END %]
274                         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
275                             | <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% itemsloo.biblionumber | uri %]">Edit record</a>
276                         [% END %]
277                         [% IF ( CAN_user_editcatalogue_edit_items ) %]
278                             | <a href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% itemsloo.biblionumber | uri %]">Edit items</a>
279                         [% END %]
280                     </p>
281             </td>
282             <td>[% itemsloo.author | html %]</td>
283             <td>[% itemsloo.dateadded | $KohaDates%]</td>
284             <td>
285                 <ul>
286                 [% FOREACH result IN itemsloo.ITEM_RESULTS %]
287                     <li>
288                         [% result.holdingbranch | html %]
289                         [% IF ( result.location_intranet ) %]<span class="shelvingloc">[% result.location_intranet | html %]</span>[% END %]
290                         [% IF ( result.itemcallnumber ) %]
291                             [<a href="/cgi-bin/koha/catalogue/search.pl?idx=callnum&amp;q=%22[% result.itemcallnumber |uri %]%22">[% result.itemcallnumber | html %]</a>]
292                         [% END %]
293                     </li>
294                 [% END %]
295                 </ul>
296             </td>
297                         </tr>
298                 [% END %]<!-- /itemsloop -->
299     </table>
300     <div class="pages">[% pagination_bar | $raw %]</div>
301 </form>
302
303         [% END %]
304 [% END %]
305
306 [% IF op == 'add_form' OR op == 'edit_form' %]
307
308     <form method="post" action="/cgi-bin/koha/virtualshelves/shelves.pl" class="validated">
309         <fieldset class="rows">
310
311         [% IF op == 'add_form' %]
312             <legend>Create a new list</legend>
313             <input type="hidden" name="op" value="add" />
314         [% ELSE %]
315             <legend>Edit list <em>[% shelf.shelfname | html %]</em></legend>
316             <input type="hidden" name="op" value="edit" />
317         [% END %]
318         <input type="hidden" name="referer" value="[% referer | html %]" />
319         <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
320         <ol>
321             <li>
322                 <label for="shelfname" class="required">Name: </label><input type="text" id="shelfname" name="shelfname" size="25" value="[% shelf.shelfname | html %]" required="required" class="focus required" />
323             <span class="required">Required</span>
324             </li>
325             <li>
326                 <span class="label">Owner: </span>
327                 [% IF op == 'add_form' %]
328                     <input type="hidden" name="owner" id="owner" value="[% loggedinusernumber | html %]" />[% logged_in_user.userid | html %]
329                 [% ELSE %]
330                     [% IF owner %]
331                         <input type="hidden" id="owner" name="owner" value="[% owner.borrowernumber | html %]" />[% owner.firstname _ ' ' _ owner.surname | html %]
332                     [% ELSE %]
333                         <input type="hidden" id="owner" name="owner" value="[% loggedinusernumber | html %]" />[% logged_in_user.userid | html %]
334                     [% END %]
335                 [% END %]
336             </li>
337             <li><label for="sortfield" >Sort this list by: </label>
338             <select name="sortfield">
339             [% IF shelf.sortfield == "title" %]<option value="title" selected="selected">Title</option>[% ELSE %]<option value="title">Title</option>[% END %]
340             [% IF shelf.sortfield == "author" %]<option value="author" selected="selected">Author</option>[% ELSE %]<option value="author">Author</option>[% END %]
341             [% IF shelf.sortfield == "copyrightdate" %]<option value="copyrightdate" selected="selected">Copyrightdate</option>[% ELSE %]<option value="copyrightdate">Copyrightdate</option>[% END %]
342             [% IF shelf.sortfield == "itemcallnumber" %]<option value="itemcallnumber" selected="selected">Call number</option>[% ELSE %]<option value="itemcallnumber">Call number</option>[% END %]
343             [% IF shelf.sortfield == "dateadded" %]<option value="dateadded" selected="selected">Date added</option>[% ELSE %]<option value="dateadded">Date added</option>[% END %]
344             </select></li>
345             <li><label for="category">Category: </label>
346                 <select id="category" name="category" onchange="AdjustRemark()">
347                 [% IF shelf.is_private %]
348                     <option value="1" selected="selected">Private</option>
349                 [% ELSE %]
350                     <option value="1">Private</option>
351                 [% END %]
352                 [% IF shelf.is_public %]
353                     <option value="2" selected="selected">Public</option>
354                 [% ELSE %]
355                     <option value="2">Public</option>
356                 [% END %]
357                            </select></li>
358
359             [% INCLUDE list_permissions %]
360
361         </ol>
362     </fieldset>
363
364     <fieldset class="action">
365         <input type="submit" value="Save" class="submit" />
366         [% IF referer == 'view' %]
367            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&amp;shelfnumber=[% shelf.shelfnumber | uri %]" class="cancel">Cancel</a>
368        [% ELSE %]
369             [% IF category == PUBLIC %]
370                 <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PUBLIC | uri %]" class="cancel">Cancel</a>
371             [% ELSE %]
372                 <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PRIVATE | uri %]" class="cancel">Cancel</a>
373             [% END %]
374         [% END %]
375     </fieldset>
376     </form>
377
378 [% END %]
379
380 [% IF op == 'list' %]
381     <h2>Lists</h2>
382     <div id="tabs" class="toptabs">
383         <ul>
384             <li id="privateshelves_tab" class="active"><a href="#tab_content">Your lists</a></li>
385             <li id="publicshelves_tab" class="active"><a href="#tab_content">Public lists</a></li>
386         </ul>
387
388         <div id="tab_content">
389             <table id="listresultst">
390                 <thead>
391                     <tr>
392                         <th class="NoVisible">Type</th>
393                         <th>List name</th>
394                         <th>Contents</th>
395                         <th>Type</th>
396                         <th>Owner</th>
397                         <th>Sort by</th>
398                         <th>Creation date</th>
399                         <th>Modification date</th>
400                         <th class="noExport">Actions</th>
401                     </tr>
402                     <tr class="filters_row">
403                         <th></th>
404                         <th><input class="filter text_filter" id="searchshelfname_filter" placeholder="List name"></th>
405                         <th></th>
406                         <th></th>
407                         <th><input class="filter text_filter" id="searchowner_filter" placeholder="Owner"></th>
408                         <th>
409                             <select class="filter text_filter" id="searchsortby_filter">
410                                 <option value=""></option>
411                                 <option value="title">Title</option>
412                                 <option value="author">Author</option>
413                                 <option value="copyrightdate">Copyrightdate</option>
414                                 <option value="itemcallnumber">Call number</option>
415                                 <option value="dateadded">Date added</option>
416                             </select>
417                         </th>
418                         <th></th>
419                         <th></th>
420                         <th></th>
421                     </tr>
422                 </thead>
423                 <tbody></tbody>
424             </table>
425         </div>
426     </div>
427 [% END %]
428
429 <form id="hold_form" method="get" action="/cgi-bin/koha/reserve/request.pl">
430     <!-- Value will be set here by placeHold() -->
431     <input id="hold_form_biblios" type="hidden" name="biblionumbers" value="" />
432 </form>
433
434             </main>
435         </div> <!-- /.col-sm-10.col-sm-push-2 -->
436     </div> <!-- /.row -->
437
438 [% IF ( can_add_biblios ) %]
439     <!-- Modal -->
440     <div class="modal" id="addToList" tabindex="-1" role="dialog" aria-labelledby="addToListLabel">
441         <div class="modal-dialog" role="document">
442             <form action="/cgi-bin/koha/virtualshelves/shelves.pl" method="post">
443                 <div class="modal-content">
444                     <div class="modal-header">
445                         <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
446                         <h4 class="modal-title" id="addToListLabel">Add items</h4>
447                     </div>
448                     <div class="modal-body">
449                         <fieldset class="brief">
450                         <ol>
451                             <li>
452                                 <label for="barcodes">Barcodes:</label>
453                                 <textarea name="barcodes" id="barcodes" rows="5"></textarea>
454                                 <input type="hidden" name="op" value="add_biblio" />
455                                 <input type="hidden" name="referer" value="view" />
456                                 <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
457                             </li>
458                             <li>
459                                 <label for="biblionumbers">Biblio numbers:</label>
460                                 <textarea name="biblionumbers" id="biblionumbers" rows="5"></textarea>
461                                 <input type="hidden" name="op" value="add_biblio" />
462                                 <input type="hidden" name="referer" value="view" />
463                                 <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
464                             </li>
465                         </ol>
466                         </fieldset>
467                     </div>
468                     <div class="modal-footer">
469                         <button type="submit" class="btn btn-default">Save</button>
470                         <a href="#" data-dismiss="modal" class="cancel">Cancel</a>
471                     </div>
472                 </div>
473             </form>
474         </div>
475     </div>
476 [% END %]
477
478 [% MACRO jsinclude BLOCK %]
479     [% INCLUDE 'datatables.inc' %]
480     [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
481     [% IF print %]
482         <script>
483             $( document ).ready(function() {
484                 window.print();
485                 setTimeout('window.close()', 1);
486             });
487         </script>
488     [% END %]
489
490     [% IF op == 'view' %]
491         [% Asset.js("lib/hc-sticky.js") | $raw %]
492     [% END %]
493     <script>
494         var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
495         var MSG_REMOVE_FROM_LIST = _("Are you sure you want to remove these items from the list?");
496         var MSG_CONFIRM_DELETE_LIST = _("Are you sure you want to remove this list?");
497
498         [% IF op == 'list' %]
499             $(document).ready(function(){
500                 [% IF category == PUBLIC %]
501                     var type = [% PUBLIC | html %];
502                 [% ELSE %]
503                     var type = [% PRIVATE | html %];
504                 [% END %]
505
506                 var dtListResults = $("#listresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
507                 "aaSorting": [[ 5, "asc" ]],
508                     'bServerSide': true,
509                     'sAjaxSource': "/cgi-bin/koha/svc/virtualshelves/search",
510                     'fnServerData': function(sSource, aoData, fnCallback) {
511                         aoData.push({
512                             'name': 'type',
513                             'value': type,
514                         },{
515                             'name': 'shelfname',
516                             'value': $("#searchshelfname_filter").val(),
517                         },{
518                             'name': 'owner',
519                             'value': $("#searchowner_filter").val(),
520                         },{
521                             'name': 'sortby',
522                             'value': $("#searchsortby_filter").val(),
523                         },{
524                             'name': 'template_path',
525                             'value': 'virtualshelves/tables/shelves_results.tt',
526                         },{
527                             'name': 'shelfname_sorton',
528                             'value': 'vs.shelfname',
529                         },{
530                             'name': 'is_shared_sorton',
531                             'value': 'vs.category',
532                         },{
533                             'name': 'owner_sorton',
534                             'value': 'vs.owner',
535                         },{
536                             'name': 'sortby_sorton',
537                             'value': 'vs.sortfield',
538                         },{
539                             'name': 'created_on_sorton',
540                             'value': 'vs.created_on',
541                         },{
542                             'name': 'modification_time_sorton',
543                             'value': 'vs.lastmodified',
544                         });
545                         $.ajax({
546                             'dataType': 'json',
547                             'type': 'POST',
548                             'url': sSource,
549                             'data': aoData,
550                             'success': function(json){
551                                 fnCallback(json);
552                             }
553                         });
554                     },
555                     'aoColumns':[
556                         { 'mDataProp': 'dt_type' },
557                         { 'mDataProp': 'dt_shelfname' },
558                         { 'mDataProp': 'dt_count' },
559                         { 'mDataProp': 'dt_is_shared' },
560                         { 'mDataProp': 'dt_owner' },
561                         { 'mDataProp': 'dt_sortby' },
562                         { 'mDataProp': 'dt_created_on' },
563                         { 'mDataProp': 'dt_modification_time' },
564                         { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
565                     ],
566                     "aoColumnDefs": [
567                         { "bVisible": false, "aTargets": [ 'NoVisible' ] }
568                     ],
569                     'bAutoWidth': false,
570                     'sPaginationType': 'full_numbers',
571                     'bFilter': false,
572                     "bProcessing": true,
573                     "bSortCellsTop": true
574                 }));
575
576                 dtListResults.fnAddFilters("filter", 750);
577
578                 var tabs = $("#tabs").tabs({
579                     [% IF category == PUBLIC %]
580                         active: 1,
581                     [% ELSE %]
582                         active: 0,
583                     [% END %]
584                     activate: function(e, ui) {
585                         var active = tabs.tabs("option", "active" );
586                         if ( active == 0 ) {
587                             type = [% PRIVATE | html %];
588                             dtListResults.fnDraw();
589                         } else if ( active == 1 ) {
590                             type = [% PUBLIC | html %];
591                             dtListResults.fnDraw();
592                         }
593                     }
594                 });
595                 $("body").on("click", ".deleteshelf", function(){
596                     return confirmDelete(MSG_CONFIRM_DELETE_LIST);
597                 });
598             });
599         [% END %]
600
601         [% IF shelf AND op == 'view' %]
602             var Sticky;
603             $(document).ready(function(){
604                 Sticky = $("#searchheader");
605                 Sticky.hcSticky({
606                     stickTo: "#listform",
607                     stickyClass: "floating"
608                 });
609                 $("span.clearall").html("<a id=\"CheckNone\" href=\"/cgi-bin/koha/shelves.pl\"><i class=\"fa fa-remove\"></i>"+_(" Clear all")+"<\/a>");
610                 $("span.checkall").html("<a id=\"CheckAll\" href=\"/cgi-bin/koha/shelves.pl\"><i class=\"fa fa-check\"></i>"+_(" Select all")+"<\/a>");
611                 $("#CheckAll").click(function(e){
612                     e.preventDefault();
613                     $(".selection").each(function(){
614                         $(this).prop("checked", true);
615                     });
616                 });
617
618                 $("#CheckNone").click(function(e){
619                     e.preventDefault();
620                     $(".selection").each(function(){
621                         $(this).prop("checked", false);
622                     });
623                 });
624                 $(".placehold").on("click",function(e){
625                     placeHold();
626                     e.preventDefault();
627                 });
628                 $(".addtocart").show();
629                 var param1 = "| <label for=\"addto\">"+_("Add to:")+"<\/label><select name=\"addto\" id=\"addto\"><option value=\"\"><\/option>";
630                 [% IF (Koha.Preference("intranetbookbag")) %]
631                      param1 += "<option value=\"addtocart\">"+_("Cart")+"<\/option>";
632                 [% END %]
633                 [% IF Koha.Preference('virtualshelves') %]
634                     [% IF add_to_some_private_shelves.count %]
635                         param1 += "<optgroup label=\""+_("Your lists:")+"\">";
636                         [% SET number_of_private_shelves = 0 %]
637                         [% FOREACH s IN add_to_some_private_shelves %]
638                             [% IF shelfnumber != s.shelfnumber %]
639                                 param1 += "<option id=\"s[% s.shelfnumber | html %]\" value=\"addtolist\">[% s.shelfname | html %]<\/option>";
640                                 [% SET number_of_private_shelves = number_of_private_shelves + 1 %]
641                                 [% IF number_of_private_shelves == 10 %][% LAST %][% END %]
642                             [% END %]
643                         [% END %]
644                         param1 += "<\/optgroup>";
645                     [% END %]
646                     [% IF add_to_some_public_shelves.count %]
647                         param1 += "<optgroup label=\""+_("Public lists:")+"\">";
648                         [% SET number_of_public_shelves = 0 %]
649                         [% FOREACH s IN add_to_some_public_shelves %]
650                             [% IF shelfnumber != s.shelfnumber %]
651                                 param1 += "<option id=\"s[% s.shelfnumber | html %]\" value=\"addtolist\">[% s.shelfname | html %]<\/option>";
652                                 [% SET number_of_public_shelves = number_of_public_shelves + 1 %]
653                                 [% IF number_of_public_shelves == 10 %][% LAST %][% END %]
654                             [% END %]
655                         [% END %]
656                         param1 += "<\/optgroup>";
657                     [% END %]
658                     [% IF add_to_some_private_shelves.count > 10 or add_to_some_public_shelves.count > 10 %]
659                         param1 += "<option value=\"morelists\">[ "+_("More lists")+" ]<\/option>";
660                     [% END %]
661                     param1 +="<option value=\"newlist\">"+_("[ New list ]")+"<\/option>"
662                 [% END %]
663                 param1 += "<\/select> <button id=\"cartsubmit\" type=\"submit\" class=\"btn btn-default btn-xs\">"+_("Save")+"</button>";
664                 $("span.addto").html(param1);
665                 $("#cartsubmit").on("click",function(e){
666                     cartList();
667                     e.preventDefault();
668                 });
669                 $("#addto").change(function(){
670                     cartList();
671                 });
672                 $(".addto").find("input:submit").click(function(e){
673                     e.preventDefault();
674                     cartList();
675                 });
676                 $("#selection_ops").show();
677                 $(".merge-items").on("click",function(e){
678                     e.preventDefault();
679                     MergeItems();
680                 });
681                 $("#listform").on("submit",function(e){
682
683                 });
684                 $(".list-remove").on("click",function(e){
685                     if($(".selection").filter(":checked").length > 0){
686                         return confirm(MSG_REMOVE_FROM_LIST);
687                     } else {
688                         alert(MSG_NO_ITEM_SELECTED);
689                         e.preventDefault();
690                     }
691                 });
692                 $("#addToList").on("shown.bs.modal", function(e){
693                     $("#barcodes").focus();
694                 });
695             });
696         [% END %]
697
698         [% IF shelf AND op == 'edit_form' %]
699             $(document).ready(function(){
700                 AdjustRemark();
701             });
702         [% END %]
703
704         /**
705          * This function checks if the adequate number of records are checked for merging
706          */
707         function MergeItems() {
708             var checkboxes = $("input:checkbox:checked");
709             if (checkboxes.length < 2) {
710                 alert(_("At least two records must be selected for merging."));
711             } else {
712                 var params = [];
713                 $(checkboxes).each(function() {
714                     params.push('biblionumber=' + $(this).val());
715                 });
716                 var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
717                 location.href = url;
718             }
719             return false;
720         }
721
722         /**
723          * This function checks all checkboxes if all are empty,
724          * or unchecks all if any already checked.
725          */
726         function CheckAll(){
727             var checkboxes = document.getElementsByTagName('input');
728             var nbCheckbox = checkboxes.length;
729             var check = areAllChecked();
730             for(var i=0;i<nbCheckbox;i++){
731                 if(checkboxes[i].getAttribute('type') == "checkbox" ){
732                     checkboxes[i].checked = (check) ? 0 : 1;
733                 }
734             }
735         }
736         /**
737          * This function returns true if ALL checkboxes are checked
738          */
739         function areAllChecked(){
740             var checkboxes = document.getElementsByTagName('input');
741             var nbCheckbox = checkboxes.length;
742             for(var i=0;i<nbCheckbox;i++){
743                 if(checkboxes[i].getAttribute('type') == "checkbox" ){
744                     if(checkboxes[i].checked == 0){
745                         return false;
746                     }
747                 }
748             }
749             return true;
750         }
751
752         function placeHold () {
753             var checkedItems = $(".selection:checked");
754             if ($(checkedItems).size() == 0) {
755                 alert(MSG_NO_ITEM_SELECTED);
756                 return false;
757             }
758             var bibs = "";
759             $(checkedItems).each(function() {
760                 bibs += $(this).val() + "/";
761             });
762             $("#hold_form_biblios").val(bibs);
763             $("#hold_form").submit();
764             return false;
765         }
766
767         function cartList(){
768             var checkboxes = $("#searchresults").find(":checkbox");
769             var vshelf = vShelfAdd(checkboxes);
770             if($("#addto").find("option:selected").attr("value") == "addtolist"){
771                 var shelfnumber = $("#addto").find("option:selected").attr("id").replace("s","");
772                 if (vshelf) {
773                      openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&' + vshelf,'popup',500,500);
774                 }
775                 return false;
776             } else if($("#addto").find("option:selected").attr("value") == "newlist"){
777                 if (vshelf) {
778                     openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&' + vshelf,'popup',500,500);
779                 }
780                 return false;
781             } else if($("#addto").find("option:selected").attr("value") == "morelists"){
782                 if (vshelf) {
783                     openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?' + vshelf,'popup',500,500);
784                 }
785                 return false;
786             }
787             if($("#addto").find("option:selected").attr("value") == "addtocart"){
788                 addMultiple(checkboxes);
789                 return false;
790             }
791         }
792
793         function AdjustRemark() {
794             var category = $("#category").val();
795             var perms = $("#allow_changes_from").val();
796
797             if( perms < 2 ) {
798                 $("#anyone_remark").hide();
799             } else if( category==1 ) {
800                 // If we move to Private (without shares), show Anyone remark
801                 // Note: the number of shares is not tested real-time
802                 [% IF !shelf.is_shared %]
803                     $("#anyone_remark").show();
804                 [% ELSE %]
805                     $("#anyone_remark").hide();
806                 [% END %]
807             } else { // category==2
808                 $("#anyone_remark").hide();
809             }
810         }
811         [% IF op == 'view' %]
812
813             function sendList(){
814                 open(CGIBIN+'virtualshelves/sendshelf.pl?shelfid=[% shelf.shelfnumber | html %]','win_form','scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
815              }
816
817              $(document).ready(function() {
818                 $("#sendlist").click(function(){
819                     sendList();
820                     return false;
821                 });
822                 $("#deleteshelf").click(function(e){
823                     if(confirm(_("Are you sure you want to delete this list?"))){
824                         return true;
825                     } else {
826                         e.preventDefault();
827                     }
828                 });
829              });
830
831         [% END %]
832     </script>
833 [% END %]
834
835 [% INCLUDE 'intranet-bottom.inc' %]