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