4 [% USE AuthorisedValues %]
6 [%- BLOCK form_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>
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>
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 %]
47 [% FOREACH option IN options %]
48 <option value="[% option.value | html %]">[% option.label | html %]</option>
54 [% BLOCK form_field_select_option %]
55 <option value="[% value | html %]">[% INCLUDE form_label label=value %]</option>
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>
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 %]
82 <option value="marc:[% marcfield | html %]" data-authorised-values-category="[% field.authorised_values_category | html %]">[% field.label | html %] ([% marcfield | html %])</option>
87 <input type="text" name="q" class="form-field-value" value="" />
88 <input type="hidden" name="op" value="like" />
92 [% BLOCK form_field_radio_yes_no %]
93 <div class="form-field">
94 <label class="form-field-label">[% INCLUDE form_label label=name %]:</label>
95 <input type="radio" name="[% name | html %]" id="[% name | html %]_indifferent" value="" checked="checked"/>
96 <label for="[% name | html %]_indifferent">Ignore</label>
97 <input type="radio" name="[% name | html %]" id="[% name | html %]_yes" value="yes" />
98 <label for="[% name | html %]_yes">Yes</label>
99 <input type="radio" name="[% name | html %]" id="[% name | html %]_no" value="no" />
100 <label for="[% name | html %]_no">No</label>
104 [%# We need to escape html characters for 'value' and 'label' %]
105 [%- BLOCK escape_html_value_label -%]
106 [%- SET escaped = [] -%]
107 [%- FOR e IN elts -%]
108 [%- value = BLOCK %][% e.value | html %][% END -%]
109 [%- label = BLOCK %][% e.label | html %][% END -%]
110 [%- escaped.push({ 'value' => value, 'label' => label }) -%]
112 [%- To.json(escaped) | $raw -%]
115 [% notforloans = AuthorisedValues.GetDescriptionsByKohaField({ kohafield = 'items.notforloan' }) %]
116 [% FOREACH nfl IN notforloans %]
117 [% nfl.value = nfl.authorised_value %]
118 [% nfl.label = nfl.lib %]
121 [% locations = AuthorisedValues.GetDescriptionsByKohaField({ kohafield = 'items.location' }) %]
122 [% FOREACH loc IN locations %]
123 [% loc.value = loc.authorised_value %]
124 [% loc.label = loc.lib %]
127 [%# Page starts here %]
129 [% SET footerjs = 1 %]
130 [% INCLUDE 'doc-head-open.inc' %]
131 <title>Koha › Catalog › Item search</title>
132 [% INCLUDE 'doc-head-close.inc' %]
133 [% Asset.css("css/itemsearchform.css") | $raw %]
136 <body id="catalog_itemsearch" class="catalog">
137 [% INCLUDE 'header.inc' %]
138 [% INCLUDE 'home-search.inc' %]
139 <div id="breadcrumbs">
140 <a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> › Item search
143 <div class="main container-fluid">
145 <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
147 <div id="item-search-block">
149 <p><a href="/cgi-bin/koha/catalogue/search.pl">Go to advanced search</a></p>
150 <form action="/cgi-bin/koha/catalogue/itemsearch.pl" method="get" id="itemsearchform">
151 <div id="toolbar" class="btn-toolbar">
152 <fieldset class="action">
153 <div class="btn-group">
154 <button class="btn btn-default"><i class="fa fa-search"></i> Search</button>
159 [% INCLUDE form_field_select name="homebranch" options = branches empty_option = "All libraries" %]
160 [% INCLUDE form_field_select name="holdingbranch" options = branches empty_option = "All libraries" %]
161 [% IF locations.size %]
162 [% INCLUDE form_field_select name="location" options = locations empty_option = "All locations" %]
166 [% INCLUDE form_field_select name="itype" options = itemtypes empty_option = "All item types" %]
168 [% INCLUDE form_field_select name="ccode" options = ccodes empty_option = "All collection codes" %]
170 [% IF notforloans.size %]
171 [% INCLUDE form_field_select name="notforloan" options = notforloans empty_option = "All statuses" %]
173 [% IF itemlosts.size %]
174 [% INCLUDE form_field_select name="itemlost" options = itemlosts empty_option = "All statuses" %]
176 [% IF withdrawns.size %]
177 [% INCLUDE form_field_select name="withdrawn" options = withdrawns empty_option = "All statuses" %]
181 [% INCLUDE form_field_select_text %]
182 <p class="hint">You can use the following wildcard characters: % _</p>
183 <p class="hint">% matches any number of characters</p>
184 <p class="hint">_ matches only a single character</p>
187 <div class="form-field">
188 <label class="form-field-label" for="itemcallnumber_from">From call number:</label>
189 <input type="text" id="itemcallnumber_from" name="itemcallnumber_from" value="" />
190 <span class="hint">(inclusive)</span>
192 <div class="form-field">
193 <label class="form-field-label" for="itemcallnumber_to">To call number:</label>
194 <input type="text" id="itemcallnumber_to" name="itemcallnumber_to" value="" />
195 <span class="hint">(inclusive)</span>
197 [% INCLUDE form_field_radio_yes_no name="damaged" %]
198 [% INCLUDE form_field_radio_yes_no name="new_status" %]
199 <div class="form-field">
200 <label class="form-field-label" for="issues_op">Checkout count:</label>
201 <select id="issues_op" name="issues_op">
202 <option value=">">></option>
203 <option value="<"><</option>
204 <option value="=">=</option>
205 <option value="!=">!=</option>
207 <input type="text" name="issues" />
209 <div class="form-field">
210 <label class="form-field-label" for="datelastborrowed_op">Last checkout date:</label>
211 <select id="datelastborrowed_op" name="datelastborrowed_op">
212 <option value=">">After</option>
213 <option value="<">Before</option>
214 <option value="=">On</option>
216 <input type="text" name="datelastborrowed" />
217 <span class="hint">ISO Format (YYYY-MM-DD)</span>
221 <div class="form-field-radio">
222 <label>Output:</label>
223 <input type="radio" id="format-html" name="format" value="html" checked="checked" /> <label for="format-html">Screen</label>
224 <input type="radio" id="format-csv" name="format" value="csv" /> <label for="format-csv">CSV</label>
225 <input type="radio" id="format-barcodes" name="format" value="barcodes"/> <label for="format-barcodes">Barcodes file</label>
233 <div class="col-md-12">
234 <div id="results-wrapper"></div>
238 [% MACRO jsinclude BLOCK %]
239 [% INCLUDE 'datatables.inc' %]
240 [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
241 [% Asset.js("lib/hc-sticky.js") | $raw %]
243 var authorised_values = [% authorised_values_json | $raw %];
245 function loadAuthorisedValuesSelect(select) {
246 var selected = select.find('option:selected');
247 var category = selected.data('authorised-values-category');
248 var form_field_value = select.siblings('.form-field-value');
249 if (category && category in authorised_values) {
250 var values = authorised_values[category];
251 var html = '<select name="q" class="form-field-value">\n';
253 var value = values[i];
254 html += '<option value="' + value.authorised_value + '">' + value.lib + '</option>\n';
256 html += '</select>\n';
257 var new_form_field_value = $(html);
258 new_form_field_value.val(form_field_value.val());
259 form_field_value.replaceWith(new_form_field_value);
261 if (form_field_value.prop('tagName').toLowerCase() == 'select') {
262 html = '<input name="q" type="text" class="form-field-value" />';
263 var new_form_field_value = $(html);
264 form_field_value.replaceWith(new_form_field_value);
269 function addNewField( link ) {
270 var form_field = $('div.form-field-select-text').last();
271 var copy = form_field.clone(true);
272 copy.find('input,select').not('[type="hidden"]').each(function() {
275 copy.find('.form-field-conjunction').prop('disabled', false).val('and');
276 form_field.after(copy);
278 copy.find('select.form-field-column').change();
281 function submitForm($form) {
284 + ' <th id="items_checkbox"></th>'
285 + ' <th id="items_title">' + _("Title") + '</th>'
286 + ' <th id="items_pubdate">' + _("Publication date") + '</th>'
287 + ' <th id="items_publisher">' + _("Publisher") + '</th>'
288 + ' <th id="items_collection">' + _("Collection") + '</th>'
289 + ' <th id="items_barcode">' + _("Barcode") + '</th>'
290 + ' <th id="items_callno">' + _("Call number") + '</th>'
291 + ' <th id="items_homebranch">' + _("Home library") + '</th>'
292 + ' <th id="items_holdingbranch">' + _("Current library") + '</th>'
293 + ' <th id="items_location">' + _("Shelving location") + '</th>'
294 + ' <th id="items_itype">' + _("Itemtype") + '</th>'
295 + ' <th id="item_inventoryno">' + _("Inventory number") + '</th>'
296 + ' <th id="items_status">' + _("Not for loan status") + '</th>'
297 + ' <th id="items_itemlost">' + _("Lost status") + '</th>'
298 + ' <th id="items_widthdrawn">' + _("Withdrawn status") + '</th>'
299 + ' <th id="items_checkouts">' + _("Checkouts") + '</th>'
303 + '<table id="results">'
304 + ' <thead>' + tr + tr + '</thead>'
308 var advSearchLink = $('<a>')
309 .attr('href', '/cgi-bin/koha/catalogue/search.pl')
310 .html(_("Go to advanced search"));
311 var editSearchLink = $('<a>')
313 .html(_("Edit search"))
314 .addClass('btn btn-default btn-xs')
315 .on('click', function(e) {
317 $('#item-search-block').show();
320 function getCheckedItemnumbers () {
323 itemnumbers = JSON.parse(sessionStorage.getItem('itemsearch_itemnumbers') || '[]');
328 return new Set(itemnumbers);
331 function exportItems(format) {
332 var itemnumbers = getCheckedItemnumbers();
333 if (itemnumbers.size > 0) {
334 var href = '/cgi-bin/koha/catalogue/item-export.pl?format=' + format;
335 href += '&itemnumber=' + Array.from(itemnumbers).join('&itemnumber=');
338 $('#format-' + format).prop('checked', true);
339 $('#itemsearchform').submit();
340 $('#format-html').prop('checked', true);
344 var csvExportLink = $('<a>')
347 .on('click', function(e) {
351 var barcodesExportLink = $('<a>')
353 .html(_("Barcodes file"))
354 .on('click', function(e) {
356 exportItems('barcodes');
359 var exportButton = $('<div>')
360 .addClass('btn-group')
361 .append($('<button>')
362 .addClass('btn btn-default btn-xs dropdown-toggle')
363 .attr('id', 'export-button')
364 .attr('data-toggle', 'dropdown')
365 .attr('aria-haspopup', 'true')
366 .attr('aria-expanded', 'false')
367 .html(_("Export all results to") + ' <span class="caret"></span>'))
369 .addClass('dropdown-menu')
370 .append($('<li>').append(csvExportLink))
371 .append($('<li>').append(barcodesExportLink)));
373 var selectVisibleRows = $('<a>')
375 .append('<i class="fa fa-check"></i> ')
376 .append(_("Select visible rows"))
377 .on('click', function(e) {
379 $('#results input[type="checkbox"]').prop('checked', true).change();
381 var clearSelection = $('<a>')
383 .append('<i class="fa fa-remove"></i> ')
384 .append(_("Clear selection"))
385 .on('click', function(e) {
387 sessionStorage.setItem('itemsearch_itemnumbers', '[]');
388 $('#results input[type="checkbox"]').prop('checked', false).change();
390 var exportLinks = $('<p>')
391 .append(selectVisibleRows)
393 .append(clearSelection)
395 .append(exportButton);
397 var results_heading = $('<div>').addClass('results-heading')
398 .append("<h1>" + _("Item search results") + "</h1>")
399 .append($('<p>').append(advSearchLink))
400 .append($('<p>').append(editSearchLink))
401 .append(exportLinks);
402 $('#results-wrapper').empty()
403 .append(results_heading)
407 $form.find('select:not(:disabled) option:selected,input[type="text"]:not(:disabled),input[type="hidden"]:not(:disabled),input[type="radio"]:checked').each(function() {
408 if ( $(this).prop('tagName').toLowerCase() == 'option' ) {
409 var name = $(this).parents('select').first().attr('name');
410 var value = $(this).val();
411 params.push({ 'name': name, 'value': value });
413 params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
417 $('#results').dataTable($.extend(true, {}, dataTablesDefaults, {
421 'sAjaxSource': '/cgi-bin/koha/catalogue/itemsearch.pl',
422 'fnServerData': function(sSource, aoData, fnCallback) {
423 aoData.push( { 'name': 'format', 'value': 'json' } );
425 aoData.push(params[i]);
432 'success': function(json){
437 'sDom': '<"top pager"ilp>t<"bottom pager"ip>r',
438 'aaSorting': [[1, 'asc']],
440 { 'sName': 'checkbox', 'bSortable': false },
441 { 'sName': 'title' },
442 { 'sName': 'publicationyear' },
443 { 'sName': 'publishercode' },
444 { 'sName': 'ccode' },
445 { 'sName': 'barcode' },
446 { 'sName': 'itemcallnumber' },
447 { 'sName': 'homebranch' },
448 { 'sName': 'holdingbranch' },
449 { 'sName': 'location' },
451 { 'sName': 'stocknumber' },
452 { 'sName': 'notforloan' },
453 { 'sName': 'itemlost' },
454 { 'sName': 'withdrawn' },
455 { 'sName': 'issues' },
456 { 'sName': 'actions', 'bSortable': false }
458 "sPaginationType": "full_numbers"
460 'sPlaceHolder': 'head:after',
467 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => ccodes %] },
473 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
474 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
475 [% IF locations.size %]
476 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => locations %] },
480 [% IF itemtypes.size %]
481 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemtypes %] },
486 [% IF notforloans.size %]
487 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => notforloans %] },
491 [% IF itemlosts.size %]
492 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemlosts %] },
496 [% IF withdrawns.size %]
497 { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => withdrawns %] },
505 $('#results').on('draw.dt', function (e, settings) {
506 var itemnumbers = getCheckedItemnumbers();
507 $(this).find('input[type="checkbox"][name="itemnumber"]').each(function () {
508 var itemnumber = this.value;
509 if (itemnumbers.has(itemnumber)) {
515 sessionStorage.setItem('itemsearch_itemnumbers', '[]');
517 $('#results').on('change', 'input[type="checkbox"]', function() {
518 var itemnumber = this.value;
519 var itemnumbers = getCheckedItemnumbers();
521 itemnumbers.add(itemnumber);
523 itemnumbers.delete(itemnumber);
525 sessionStorage.setItem('itemsearch_itemnumbers', JSON.stringify(Array.from(itemnumbers)));
527 var caret = ' <span class="caret">';
528 if (itemnumbers.size > 0) {
529 $('#export-button').html(_("Export selected results (%s) to").format(itemnumbers.size) + caret);
531 $('#export-button').html(_("Export all results to") + caret);
536 $(document).ready(function () {
537 Sticky = $("#toolbar");
539 stickTo: "#item-search-block",
540 stickyClass: "floating"
542 // Add the "New field" link.
543 var form_field = $('div.form-field-select-text').last()
544 var NEW_FIELD = _("New field");
545 var button_field_new = $('<a href="#" class="button-field-new" title="Add a new field"><i class="fa fa-plus"></i> ' + NEW_FIELD + '</a>');
546 button_field_new.click(function(e) {
548 addNewField( $(this) );
550 form_field.append(button_field_new);
552 // If a field is linked to an authorised values list, display the list.
553 $('div.form-field-select-text select[name="f"]').change(function() {
554 loadAuthorisedValuesSelect($(this));
557 // Prevent user to select the 'All ...' option with other options.
558 $('div.form-field-select').each(function() {
559 $(this).find('select').filter(':last').change(function() {
560 values = $(this).val();
561 if (values.length > 1) {
562 var idx = $.inArray('', values);
564 values.splice(idx, 1);
571 $('#itemsearchform').submit(function() {
572 var searchform = $(this);
573 var format = searchform.find('input[name="format"]:checked').val();
574 if (format == 'html') {
575 submitForm(searchform);
576 $("#item-search-block").hide();
584 [% INCLUDE 'intranet-bottom.inc' %]