Bug 17748: (follow-up) Fix sorting on new columns
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / catalogue / itemsearch.tt
1 [% USE raw %]
2 [% USE To %]
3 [% USE Asset %]
4 [% USE AuthorisedValues %]
5
6 [%- BLOCK form_label -%]
7   [%- SWITCH label -%]
8     [%- CASE 'barcode' %]<span>Barcode</span>
9     [%- CASE 'itemcallnumber' %]<span>Call number</span>
10     [%- CASE 'stocknumber' %]<span>Inventory number</span>
11     [%- CASE 'title' %]<span>Title</span>
12     [%- CASE 'author' %]<span>Author</span>
13     [%- CASE 'publishercode' %]<span>Publisher</span>
14     [%- CASE 'publicationyear' %]<span>Publication date</span>
15     [%- CASE 'collectiontitle' %]<span>Collection title</span>
16     [%- CASE 'isbn' %]<span>ISBN</span>
17     [%- CASE 'issn' %]<span>ISSN</span>
18     [%- CASE 'homebranch' %]<span>Home library</span>
19     [%- CASE 'holdingbranch' %]<span>Current library</span>
20     [%- CASE 'All libraries' %]<span>All libraries</span>
21     [%- CASE 'location' %]<span>Shelving location</span>
22     [%- CASE 'All locations' %]<span>All locations</span>
23     [%- CASE 'itype' %]<span>Item type</span>
24     [%- CASE 'All item types' %]<span>All item types</span>
25     [%- CASE 'ccode' %]<span>Collection</span>
26     [%- CASE 'All collection codes' %]<span>All collections</span>
27     [%- CASE 'notforloan' %]<span>Status</span>
28     [%- CASE 'All statuses' %]<span>All statuses</span>
29     [%- CASE 'damaged' %]<span>Damaged</span>
30     [%- CASE 'itemlost' %]<span>Lost</span>
31     [%- CASE 'withdrawn' %]<span>Withdrawn</span>
32     [%- CASE 'new_status' %]<span>Is new</span>
33   [%- END -%]
34 [%- END -%]
35
36 [% BLOCK form_field_select %]
37   <div class="form-field form-field-select">
38     <label class="form-field-label" for="[% name | html %]">[% INCLUDE form_label label=name %]</label>
39     <select id="[% name | html %]_op" name="[% name | html %]_op">
40       <option value="=">is</option>
41       <option value="!=" >is not</option>
42     </select>
43     <select id="[% name | html %]" name="[% name | html %]" multiple="multiple" size="[% options.size < 4 ? options.size + 1 : 4 | html %]">
44       <option value="" selected="selected">
45         [% IF (empty_option) %][% INCLUDE form_label label=empty_option %][% ELSE %]<span>All</span>[% END %]
46       </option>
47       [% FOREACH option IN options %]
48         <option value="[% option.value | html %]">[% option.label | html %]</option>
49       [% END %]
50     </select>
51   </div>
52 [% END %]
53
54 [% BLOCK form_field_select_option %]
55   <option value="[% value | html %]">[% INCLUDE form_label label=value %]</option>
56 [% END %]
57
58 [% BLOCK form_field_select_text %]
59   <div class="form-field form-field-select-text">
60     <select name="c" class="form-field-conjunction" disabled="disabled">
61       <option value="and">AND</option>
62       <option value="or">OR</option>
63     </select>
64     <select name="f" class="form-field-column">
65       [% INCLUDE form_field_select_option value='barcode' %]
66       [% INCLUDE form_field_select_option value='itemcallnumber' %]
67       [% INCLUDE form_field_select_option value='stocknumber' %]
68       [% INCLUDE form_field_select_option value='title' %]
69       [% INCLUDE form_field_select_option value='author' %]
70       [% INCLUDE form_field_select_option value='publishercode' %]
71       [% INCLUDE form_field_select_option value='publicationyear' %]
72       [% INCLUDE form_field_select_option value='collectiontitle' %]
73       [% INCLUDE form_field_select_option value='isbn' %]
74       [% INCLUDE form_field_select_option value='issn' %]
75       [% IF items_search_fields.size %]
76         <optgroup label="Custom search fields">
77           [% FOREACH field IN items_search_fields %]
78             [% marcfield = field.tagfield %]
79             [% IF field.tagsubfield.defined AND field.tagsubfield != "" %]
80               [% marcfield = marcfield _ '$' _ field.tagsubfield %]
81             [% END %]
82             <option value="marc:[% marcfield | html %]" data-authorised-values-category="[% field.authorised_values_category | html %]">[% field.label | html %] ([% marcfield | html %])</option>
83           [% END %]
84         </optgroup>
85       [% END %]
86     </select>
87     [% IF params.exists('op') %]
88         <select name="op" class="form-field-not">
89            <option value="like">is</option>
90             [% IF params.op == 'not like' %]
91                <option value="not like" selected="selected">is not</option>
92             [% ELSE %]
93                <option value="not like">is not</option>
94             [% END %]
95         </select>
96     [% ELSE %]
97         <select name="op" class="form-field-not">
98            <option value="like">is</option>
99            <option value="not like">is not</option>
100         </select>
101     [% END %]
102     <input type="text" name="q" class="form-field-value" value="" />
103   </div>
104 [% END %]
105
106 [% BLOCK form_field_radio_yes_no %]
107   <div class="form-field [% divclass | html %]">
108     <label class="form-field-label">[% INCLUDE form_label label=name %]:</label>
109     <input type="radio" name="[% name | html %]" id="[% name | html %]_indifferent" value="" checked="checked"/>
110     <label for="[% name | html %]_indifferent">Ignore</label>
111     <input type="radio" name="[% name | html %]" id="[% name | html %]_yes" value="yes" />
112     <label for="[% name | html %]_yes">Yes</label>
113     <input type="radio" name="[% name | html %]" id="[% name | html %]_no" value="no" />
114     <label for="[% name | html %]_no">No</label>
115   </div>
116 [% END %]
117
118 [%# We need to escape html characters for 'value' and 'label' %]
119 [%- BLOCK escape_html_value_label -%]
120     [%- SET escaped = [] -%]
121     [%- FOR e IN elts -%]
122         [%- value = BLOCK %][% e.value | html %][% END -%]
123         [%- label = BLOCK %][% e.label | html %][% END -%]
124         [%- escaped.push({ 'value' => value, 'label' => label }) -%]
125     [%- END -%]
126     [%- To.json(escaped) | $raw -%]
127 [%- END -%]
128
129 [% notforloans = AuthorisedValues.GetDescriptionsByKohaField({ kohafield = 'items.notforloan' }) %]
130 [% FOREACH nfl IN notforloans %]
131     [% nfl.value = nfl.authorised_value %]
132     [% nfl.label = nfl.lib %]
133 [% END %]
134
135 [% locations = AuthorisedValues.GetDescriptionsByKohaField({ kohafield = 'items.location' }) %]
136 [% FOREACH loc IN locations %]
137     [% loc.value = loc.authorised_value %]
138     [% loc.label = loc.lib %]
139 [% END %]
140
141 [%# Page starts here %]
142
143 [% SET footerjs = 1 %]
144 [% INCLUDE 'doc-head-open.inc' %]
145   <title>Item search &rsaquo; Catalog &rsaquo; Koha</title>
146   [% INCLUDE 'doc-head-close.inc' %]
147   [% Asset.css("css/itemsearchform.css") | $raw %]
148 </head>
149
150 <body id="catalog_itemsearch" class="catalog">
151   [% INCLUDE 'header.inc' %]
152   [% INCLUDE 'home-search.inc' %]
153
154 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
155     <ol>
156         <li>
157             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
158         </li>
159         <li>
160             <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>
161         </li>
162         <li>
163             <a href="#" aria-current="page">
164                 Item search
165             </a>
166         </li>
167     </ol>
168 </nav>
169
170 <div class="main container-fluid">
171     <div class="row">
172         <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
173
174     <div id="item-search-block">
175       <h1>Item search</h1>
176
177       <p><a href="/cgi-bin/koha/catalogue/search.pl">Go to advanced search</a></p>
178       <form action="/cgi-bin/koha/catalogue/itemsearch.pl" method="get" id="itemsearchform">
179           <div id="toolbar" class="btn-toolbar">
180               <fieldset class="action">
181                   <div class="btn-group">
182                       <button class="btn btn-default"><i class="fa fa-search"></i> Search</button>
183                   </div>
184               </fieldset>
185           </div>
186           <fieldset>
187             [% INCLUDE form_field_select name="homebranch" options = branches empty_option = "All libraries" %]
188             [% INCLUDE form_field_select name="holdingbranch" options = branches empty_option = "All libraries" %]
189             [% IF locations.size %]
190                 [% INCLUDE form_field_select name="location" options = locations empty_option = "All locations" %]
191             [% END %]
192           </fieldset>
193           <fieldset>
194             [% INCLUDE form_field_select name="itype" options = itemtypes empty_option = "All item types" %]
195             [% IF ccodes.size %]
196                 [% INCLUDE form_field_select name="ccode" options = ccodes empty_option = "All collection codes" %]
197             [% END %]
198             [% IF notforloans.size %]
199                 [% INCLUDE form_field_select name="notforloan" options = notforloans empty_option = "All statuses" %]
200             [% END %]
201             [% IF itemlosts.size %]
202                 [% INCLUDE form_field_select name="itemlost" options = itemlosts empty_option = "All statuses" %]
203             [% END %]
204             [% IF withdrawns.size %]
205                 [% INCLUDE form_field_select name="withdrawn" options = withdrawns empty_option = "All statuses" %]
206             [% END %]
207             <div class="form-field">
208                 <label class="form-field-label">Availability:</label>
209                 <input type="radio" name="onloan" id="onloan_indifferent" value="" checked="checked"/>
210                 <label for="onloan_indifferent">Ignore</label>
211                 <input type="radio" name="onloan" id="onloan_yes" value="IS NOT NULL" />
212                 <label for="onloan_yes">Checked out</label>
213                 <input type="radio" name="onloan" id="onloan_no" value="IS NULL" />
214                 <label for="onloan_no">Available</label>
215             </div>
216           </fieldset>
217           <fieldset>
218             [% INCLUDE form_field_select_text %]
219             <p class="hint">You can use the following wildcard characters: % _</p>
220             <p class="hint">% matches any number of characters</p>
221             <p class="hint">_ matches only a single character</p>
222           </fieldset>
223           <fieldset>
224             <div class="form-field">
225               <label class="form-field-label" for="itemcallnumber_from">From call number:</label>
226               <input type="text" id="itemcallnumber_from" name="itemcallnumber_from" value="" />
227               <span class="hint">(inclusive)</span>
228             </div>
229             <div class="form-field">
230               <label class="form-field-label" for="itemcallnumber_to">To call number:</label>
231               <input type="text" id="itemcallnumber_to" name="itemcallnumber_to" value="" />
232               <span class="hint">(inclusive)</span>
233             </div>
234             [% INCLUDE form_field_radio_yes_no name="damaged" %]
235             [% IF ( has_new_status ) %]
236                 [% INCLUDE form_field_radio_yes_no name="new_status" divclass='item-new-status' %]
237             [% END %]
238             <div class="form-field">
239               <label class="form-field-label" for="issues_op">Checkout count:</label>
240               <select id="issues_op" name="issues_op">
241                 <option value=">">&gt;</option>
242                 <option value="<">&lt;</option>
243                 <option value="=">=</option>
244                 <option value="!=">!=</option>
245               </select>
246               <input type="text" name="issues" />
247             </div>
248             <div class="form-field">
249               <label class="form-field-label" for="datelastborrowed_op">Last checkout date:</label>
250               <select id="datelastborrowed_op" name="datelastborrowed_op">
251                 <option value=">">After</option>
252                 <option value="<">Before</option>
253                 <option value="=">On</option>
254               </select>
255               <input type="text" name="datelastborrowed" />
256               <span class="hint">ISO Format (YYYY-MM-DD)</span>
257             </div>
258           </fieldset>
259           <fieldset>
260             <div class="form-field-radio">
261               <label>Output:</label>
262               <input type="radio" id="format-html" name="format" value="html" checked="checked" /> <label for="format-html">Screen</label>
263               <input type="radio" id="format-csv" name="format" value="csv" /> <label for="format-csv">CSV</label>
264               <input type="radio" id="format-barcodes" name="format" value="barcodes"/> <label for="format-barcodes">Barcodes file</label>
265             </div>
266           </fieldset>
267       </form>
268     </div>
269     </div>
270   </div>
271     <div class="row">
272         <div class="col-md-12">
273       <div id="results-wrapper"></div>
274         </div>
275       </div>
276
277 [% MACRO jsinclude BLOCK %]
278     [% INCLUDE 'datatables.inc' %]
279     [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
280     [% Asset.js("lib/hc-sticky.js") | $raw %]
281     <script>
282         var authorised_values = [% authorised_values_json | $raw %];
283
284         function loadAuthorisedValuesSelect(select) {
285             var selected = select.find('option:selected');
286             var category = selected.data('authorised-values-category');
287             var form_field_value = select.siblings('.form-field-value');
288             if (category && category in authorised_values) {
289                 var values = authorised_values[category];
290                 var html = '<select name="q" class="form-field-value">\n';
291                 for (i in values) {
292                     var value = values[i];
293                     html += '<option value="' + value.authorised_value + '">' + value.lib + '</option>\n';
294                 }
295                 html += '</select>\n';
296                 var new_form_field_value = $(html);
297                 new_form_field_value.val(form_field_value.val());
298                 form_field_value.replaceWith(new_form_field_value);
299             } else {
300                 if (form_field_value.prop('tagName').toLowerCase() == 'select') {
301                     html = '<input name="q" type="text" class="form-field-value" />';
302                     var new_form_field_value = $(html);
303                     form_field_value.replaceWith(new_form_field_value);
304                 }
305             }
306         }
307
308     function addNewField( link ) {
309             var form_field = $('div.form-field-select-text').last();
310             var copy = form_field.clone(true);
311             copy.find('input,select').not('[type="hidden"]').each(function() {
312                 $(this).val('');
313             });
314             copy.find('.form-field-conjunction').prop('disabled', false).val('and');
315             form_field.after(copy);
316       link.remove();
317             copy.find('select.form-field-column').change();
318         }
319
320         function submitForm($form) {
321             var tr = ''
322                 + '    <tr>'
323                 + '      <th id="items_checkbox"></th>'
324                 + '      <th id="items_title">' + _("Title") + '</th>'
325                 + '      <th id="items_pubdate">' + _("Publication date") + '</th>'
326                 + '      <th id="items_publisher">' + _("Publisher") + '</th>'
327                 + '      <th id="items_collection">' + _("Collection") + '</th>'
328                 + '      <th id="items_barcode">' + _("Barcode") + '</th>'
329                 + '      <th id="items_callno">' + _("Call number") + '</th>'
330                 + '      <th id="items_homebranch">' + _("Home library") + '</th>'
331                 + '      <th id="items_holdingbranch">' + _("Current library") + '</th>'
332                 + '      <th id="items_location">' + _("Shelving location") + '</th>'
333                 + '      <th id="items_itype">' + _("Itemtype") + '</th>'
334                 + '      <th id="item_inventoryno">' + _("Inventory number") + '</th>'
335                 + '      <th id="items_status">' + _("Not for loan status") + '</th>'
336                 + '      <th id="items_itemlost">' + _("Lost status") + '</th>'
337                 + '      <th id="items_widthdrawn">' + _("Withdrawn status") + '</th>'
338                 + '      <th id="items_checkouts">' + _("Checkouts") + '</th>'
339                 + '      <th id="items_availability">' + _("Availability") + '</th>'
340                 + '      <th id="items_date_due">' + _("Due date") + '</th>'
341                 + '      <th id=""></th>'
342                 + '    </tr>'
343             var table = ''
344                 + '<table id="results">'
345                 + '  <thead>' + tr + tr + '</thead>'
346                 + '  <tbody></tbody>'
347                 + '</table>';
348
349             var advSearchLink = $('<a>')
350                 .attr('href', '/cgi-bin/koha/catalogue/search.pl')
351                 .html(_("Go to advanced search"));
352             var editSearchLink = $('<a>')
353                 .attr('href', '#')
354                 .html(_("Edit search"))
355                 .addClass('btn btn-default btn-xs')
356                 .on('click', function(e) {
357                     e.preventDefault();
358                     $('#item-search-block').show();
359                 });
360
361             function getCheckedItemnumbers () {
362                 var itemnumbers;
363                 try {
364                     itemnumbers = JSON.parse(sessionStorage.getItem('itemsearch_itemnumbers') || '[]');
365                 } catch (e) {
366                     itemnumbers = [];
367                 }
368
369                 return new Set(itemnumbers);
370             }
371
372             function exportItems(format) {
373               var itemnumbers = getCheckedItemnumbers();
374               if (itemnumbers.size > 0) {
375                 var href = '/cgi-bin/koha/catalogue/item-export.pl?format=' + format;
376                 href += '&itemnumber=' + Array.from(itemnumbers).join('&itemnumber=');
377                 location = href;
378               } else {
379                 $('#format-' + format).prop('checked', true);
380                 $('#itemsearchform').submit();
381                 $('#format-html').prop('checked', true);
382               }
383             }
384
385             var csvExportLink = $('<a>')
386                 .attr('href', '#')
387                 .html("CSV")
388                 .on('click', function(e) {
389                     e.preventDefault();
390                     exportItems('csv');
391                 });
392             var barcodesExportLink = $('<a>')
393                 .attr('href', '#')
394                 .html(_("Barcodes file"))
395                 .on('click', function(e) {
396                     e.preventDefault();
397                     exportItems('barcodes');
398               });
399
400             var exportButton = $('<div>')
401               .addClass('btn-group')
402               .append($('<button>')
403                   .addClass('btn btn-default btn-xs dropdown-toggle')
404                   .attr('id', 'export-button')
405                   .attr('data-toggle', 'dropdown')
406                   .attr('aria-haspopup', 'true')
407                   .attr('aria-expanded', 'false')
408                   .html(_("Export all results to") + ' <span class="caret"></span>'))
409               .append($('<ul>')
410                   .addClass('dropdown-menu')
411                   .append($('<li>').append(csvExportLink))
412                   .append($('<li>').append(barcodesExportLink)));
413
414             var selectVisibleRows = $('<a>')
415               .attr('href', '#')
416               .append('<i class="fa fa-check"></i> ')
417               .append(_("Select visible rows"))
418               .on('click', function(e) {
419                   e.preventDefault();
420                   $('#results input[type="checkbox"]').prop('checked', true).change();
421               });
422             var clearSelection = $('<a>')
423               .attr('href', '#')
424               .append('<i class="fa fa-remove"></i> ')
425               .append(_("Clear selection"))
426               .on('click', function(e) {
427                   e.preventDefault();
428                   sessionStorage.setItem('itemsearch_itemnumbers', '[]');
429                   $('#results input[type="checkbox"]').prop('checked', false).change();
430               });
431             var exportLinks = $('<p>')
432               .append(selectVisibleRows)
433               .append(' ')
434               .append(clearSelection)
435               .append(' | ')
436               .append(exportButton);
437
438             var results_heading = $('<div>').addClass('results-heading')
439                 .append("<h1>" + _("Item search results") + "</h1>")
440                 .append($('<p>').append(advSearchLink))
441                 .append($('<p>').append(editSearchLink))
442                 .append(exportLinks);
443             $('#results-wrapper').empty()
444                 .append(results_heading)
445                 .append(table);
446
447             var params = [];
448             $form.find('select:not(:disabled) option:selected,input[type="text"]:not(:disabled),input[type="hidden"]:not(:disabled),input[type="radio"]:checked').each(function() {
449                 if ( $(this).prop('tagName').toLowerCase() == 'option' ) {
450                     var name = $(this).parents('select').first().attr('name');
451                     var value = $(this).val();
452                     params.push({ 'name': name, 'value': value });
453                 } else {
454                     params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
455                 }
456             });
457
458             $('#results').dataTable($.extend(true, {}, dataTablesDefaults, {
459                 'bDestroy': true,
460                 'bServerSide': true,
461                 'bProcessing': true,
462                 'sAjaxSource': '/cgi-bin/koha/catalogue/itemsearch.pl',
463                 'fnServerData': function(sSource, aoData, fnCallback) {
464                     aoData.push( { 'name': 'format', 'value': 'json' } );
465                     for (i in params) {
466                         aoData.push(params[i]);
467                     }
468                     $.ajax({
469                         'dataType': 'json',
470                         'type': 'POST',
471                         'url': sSource,
472                         'data': aoData,
473                         'success': function(json){
474                             fnCallback(json);
475                         }
476                     });
477                 },
478                 'sDom': '<"top pager"ilp>t<"bottom pager"ip>r',
479                 'aaSorting': [[1, 'asc']],
480                 'aoColumns': [
481                     { 'sName': 'checkbox', 'bSortable': false },
482                     { 'sName': 'title' },
483                     { 'sName': 'publicationyear' },
484                     { 'sName': 'publishercode' },
485                     { 'sName': 'ccode' },
486                     { 'sName': 'barcode' },
487                     { 'sName': 'itemcallnumber' },
488                     { 'sName': 'homebranch' },
489                     { 'sName': 'holdingbranch' },
490                     { 'sName': 'location' },
491                     { 'sName': 'itype'},
492                     { 'sName': 'stocknumber' },
493                     { 'sName': 'notforloan' },
494                     { 'sName': 'itemlost' },
495                     { 'sName': 'withdrawn' },
496                     { 'sName': 'issues' },
497                     { 'sName': 'availability' },
498                     { 'sName': 'date_due' },
499                     { 'sName': 'actions', 'bSortable': false }
500                 ],
501                 "sPaginationType": "full_numbers",
502                 fixedHeader: false // There is a bug on this view
503             })).columnFilter({
504                 'sPlaceHolder': 'head:after',
505                 'aoColumns': [
506                     null,
507                     { 'type': 'text' },
508                     { 'type': 'text' },
509                     { 'type': 'text' },
510                     [% IF ccodes.size %]
511                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => ccodes %] },
512                     [% ELSE %]
513                         null,
514                     [% END %]
515                     { 'type': 'text' },
516                     { 'type': 'text' },
517                     { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
518                     { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
519                     [% IF locations.size %]
520                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => locations %] },
521                     [% ELSE %]
522                         null,
523                     [% END %]
524                     [% IF itemtypes.size %]
525                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemtypes %] },
526                     [% ELSE %]
527                         null,
528                     [% END %]
529                     { 'type': 'text' },
530                     [% IF notforloans.size %]
531                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => notforloans %] },
532                     [% ELSE %]
533                         null,
534                     [% END %]
535                     [% IF itemlosts.size %]
536                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemlosts %] },
537                     [% ELSE %]
538                         null,
539                     [% END %]
540                     [% IF withdrawns.size %]
541                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => withdrawns %] },
542                     [% ELSE %]
543                         null,
544                     [% END %]
545                     { 'type': 'text' },
546                     { 'type': 'text' },
547                     { 'type': 'text' },
548                     null
549                 ]
550             });
551             $('#results').on('draw.dt', function (e, settings) {
552                 var itemnumbers = getCheckedItemnumbers();
553                 $(this).find('input[type="checkbox"][name="itemnumber"]').each(function () {
554                     var itemnumber = this.value;
555                     if (itemnumbers.has(itemnumber)) {
556                         this.checked = true;
557                     }
558                 });
559             });
560
561             sessionStorage.setItem('itemsearch_itemnumbers', '[]');
562
563             $('#results').on('change', 'input[type="checkbox"]', function() {
564               var itemnumber = this.value;
565               var itemnumbers = getCheckedItemnumbers();
566               if (this.checked) {
567                   itemnumbers.add(itemnumber);
568               } else {
569                   itemnumbers.delete(itemnumber);
570               }
571               sessionStorage.setItem('itemsearch_itemnumbers', JSON.stringify(Array.from(itemnumbers)));
572
573               var caret = ' <span class="caret">';
574               if (itemnumbers.size > 0) {
575                 $('#export-button').html(_("Export selected results (%s) to").format(itemnumbers.size) + caret);
576               } else {
577                 $('#export-button').html(_("Export all results to") + caret);
578               }
579             });
580         }
581         var Sticky;
582         $(document).ready(function () {
583             Sticky = $("#toolbar");
584             Sticky.hcSticky({
585                 stickTo: "#item-search-block",
586                 stickyClass: "floating"
587             });
588             // Add the "New field" link.
589             var form_field = $('div.form-field-select-text').last()
590             var NEW_FIELD = _("New field");
591       var button_field_new = $('<a href="#" class="button-field-new" title="Add a new field"><i class="fa fa-plus"></i> ' + NEW_FIELD + '</a>');
592       button_field_new.click(function(e) {
593           e.preventDefault();
594           addNewField( $(this) );
595             });
596       form_field.append(button_field_new);
597
598             // If a field is linked to an authorised values list, display the list.
599             $('div.form-field-select-text select[name="f"]').change(function() {
600                 loadAuthorisedValuesSelect($(this));
601             }).change();
602
603             // Prevent user to select the 'All ...' option with other options.
604             $('div.form-field-select').each(function() {
605                 $(this).find('select').filter(':last').change(function() {
606                     values = $(this).val();
607                     if (values.length > 1) {
608                         var idx = $.inArray('', values);
609                         if (idx != -1) {
610                             values.splice(idx, 1);
611                             $(this).val(values);
612                         }
613                     }
614                 });
615             });
616
617             $('#itemsearchform').submit(function() {
618                 var searchform = $(this);
619                 var format = searchform.find('input[name="format"]:checked').val();
620                 if (format == 'html') {
621                     submitForm(searchform);
622                     $("#item-search-block").hide();
623                     return false;
624                 }
625             });
626         });
627     </script>
628 [% END %]
629
630 [% INCLUDE 'intranet-bottom.inc' %]