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