Bug 22424: (follow-up) Show blank value for empty status
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / catalogue / itemsearch.tt
1 [% USE raw %]
2 [% USE To %]
3 [% USE Asset %]
4
5 [% BLOCK form_label %]
6   [% SWITCH label %]
7     [% CASE 'barcode' %]<span>Barcode</span>
8     [% CASE 'itemcallnumber' %]<span>Call number</span>
9     [% CASE 'stocknumber' %]<span>Inventory number</span>
10     [% CASE 'title' %]<span>Title</span>
11     [% CASE 'author' %]<span>Author</span>
12     [% CASE 'publishercode' %]<span>Publisher</span>
13     [% CASE 'publicationyear' %]<span>Publication date</span>
14     [% CASE 'collectiontitle' %]<span>Collection</span>
15     [% CASE 'isbn' %]<span>ISBN</span>
16     [% CASE 'issn' %]<span>ISSN</span>
17     [% CASE 'homebranch' %]<span>Home library</span>
18     [% CASE 'holdingbranch' %]<span>Current location</span>
19     [% CASE 'All libraries' %]<span>All libraries</span>
20     [% CASE 'location' %]<span>Shelving location</span>
21     [% CASE 'All locations' %]<span>All locations</span>
22     [% CASE 'itype' %]<span>Item type</span>
23     [% CASE 'All item types' %]<span>All item types</span>
24     [% CASE 'ccode' %]<span>Collection code</span>
25     [% CASE 'All collection codes' %]<span>All collection codes</span>
26     [% CASE 'notforloan' %]<span>Status</span>
27     [% CASE 'All statuses' %]<span>All statuses</span>
28     [% CASE 'damaged' %]<span>Damaged</span>
29     [% CASE 'itemlost' %]<span>Lost</span>
30   [% END %]
31 [% END %]
32
33 [% BLOCK form_field_select %]
34   <div class="form-field form-field-select">
35     <label class="form-field-label" for="[% name | html %]">[% INCLUDE form_label label=name %]</label>
36     <select id="[% name | html %]_op" name="[% name | html %]_op">
37       <option value="=">is</option>
38       <option value="!=" >is not</option>
39     </select>
40     <select id="[% name | html %]" name="[% name | html %]" multiple="multiple" size="[% options.size < 4 ? options.size + 1 : 4 | html %]">
41       <option value="" selected="selected">
42         [% IF (empty_option) %][% INCLUDE form_label label=empty_option %][% ELSE %]<span>All</span>[% END %]
43       </option>
44       [% FOREACH option IN options %]
45         <option value="[% option.value | html %]">[% option.label | html %]</option>
46       [% END %]
47     </select>
48   </div>
49 [% END %]
50
51 [% BLOCK form_field_select_option %]
52   <option value="[% value | html %]">[% INCLUDE form_label label=value %]</option>
53 [% END %]
54
55 [% BLOCK form_field_select_text %]
56   <div class="form-field form-field-select-text">
57     <select name="c" class="form-field-conjunction" disabled="disabled">
58       <option value="and">AND</option>
59       <option value="or">OR</option>
60     </select>
61     <select name="f" class="form-field-column">
62       [% INCLUDE form_field_select_option value='barcode' %]
63       [% INCLUDE form_field_select_option value='itemcallnumber' %]
64       [% INCLUDE form_field_select_option value='stocknumber' %]
65       [% INCLUDE form_field_select_option value='title' %]
66       [% INCLUDE form_field_select_option value='author' %]
67       [% INCLUDE form_field_select_option value='publishercode' %]
68       [% INCLUDE form_field_select_option value='publicationyear' %]
69       [% INCLUDE form_field_select_option value='collectiontitle' %]
70       [% INCLUDE form_field_select_option value='isbn' %]
71       [% INCLUDE form_field_select_option value='issn' %]
72       [% IF items_search_fields.size %]
73         <optgroup label="Custom search fields">
74           [% FOREACH field IN items_search_fields %]
75             [% marcfield = field.tagfield %]
76             [% IF field.tagsubfield %]
77               [% marcfield = marcfield _ '$' _ field.tagsubfield %]
78             [% END %]
79             <option value="marc:[% marcfield | html %]" data-authorised-values-category="[% field.authorised_values_category | html %]">[% field.label | html %] ([% marcfield | html %])</option>
80           [% END %]
81         </optgroup>
82       [% END %]
83     </select>
84     <input type="text" name="q" class="form-field-value" value="" />
85     <input type="hidden" name="op" value="like" />
86   </div>
87 [% END %]
88
89 [% BLOCK form_field_radio_yes_no %]
90   <div class="form-field">
91     <label class="form-field-label">[% INCLUDE form_label label=name %]:</label>
92     <input type="radio" name="[% name | html %]" id="[% name | html %]_indifferent" value="" checked="checked"/>
93     <label for="[% name | html %]_indifferent">Ignore</label>
94     <input type="radio" name="[% name | html %]" id="[% name | html %]_yes" value="yes" />
95     <label for="[% name | html %]_yes">Yes</label>
96     <input type="radio" name="[% name | html %]" id="[% name | html %]_no" value="no" />
97     <label for="[% name | html %]_no">No</label>
98   </div>
99 [% END %]
100
101 [%# We need to escape html characters for 'value' and 'label' %]
102 [%- BLOCK escape_html_value_label -%]
103     [%- SET escaped = [] -%]
104     [%- FOR e IN elts -%]
105         [%- value = BLOCK %][% e.value | html %][% END -%]
106         [%- label = BLOCK %][% e.label | html %][% END -%]
107         [%- escaped.push({ 'value' => value, 'label' => label }) -%]
108     [%- END -%]
109     [%- To.json(escaped) | $raw -%]
110 [%- END -%]
111
112 [%# Page starts here %]
113
114 [% SET footerjs = 1 %]
115 [% INCLUDE 'doc-head-open.inc' %]
116   <title>Koha &rsaquo; Catalog &rsaquo; Item search</title>
117   [% INCLUDE 'doc-head-close.inc' %]
118   [% Asset.css("css/itemsearchform.css") | $raw %]
119 </head>
120
121 <body id="catalog_itemsearch" class="catalog">
122   [% INCLUDE 'header.inc' %]
123   [% INCLUDE 'home-search.inc' %]
124   <div id="breadcrumbs">
125     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> &rsaquo; Item search
126   </div>
127
128 <div class="main container-fluid">
129     <div class="row">
130         <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
131
132     <div id="item-search-block">
133       <h1>Item search</h1>
134       <p><a href="/cgi-bin/koha/catalogue/search.pl">Go to advanced search</a></p>
135       <form action="/cgi-bin/koha/catalogue/itemsearch.pl" method="get" id="itemsearchform">
136           <div id="toolbar" class="btn-toolbar">
137               <fieldset class="action">
138                   <div class="btn-group">
139                       <button class="btn btn-default"><i class="fa fa-search"></i> Search</button>
140                   </div>
141               </fieldset>
142           </div>
143           <fieldset>
144             [% INCLUDE form_field_select name="homebranch" options = branches empty_option = "All libraries" %]
145             [% INCLUDE form_field_select name="holdingbranch" options = branches empty_option = "All libraries" %]
146             [% IF locations.size %]
147                 [% INCLUDE form_field_select name="location" options = locations empty_option = "All locations" %]
148             [% END %]
149           </fieldset>
150           <fieldset>
151             [% INCLUDE form_field_select name="itype" options = itemtypes empty_option = "All item types" %]
152             [% IF ccodes.size %]
153                 [% INCLUDE form_field_select name="ccode" options = ccodes empty_option = "All collection codes" %]
154             [% END %]
155             [% IF notforloans.size %]
156                 [% INCLUDE form_field_select name="notforloan" options = notforloans empty_option = "All statuses" %]
157             [% END %]
158             [% IF itemlosts.size %]
159                 [% INCLUDE form_field_select name="itemlost" options = itemlosts empty_option = "All statuses" %]
160             [% END %]
161           </fieldset>
162           <fieldset>
163             [% INCLUDE form_field_select_text %]
164             <p class="hint">You can use the following wildcard characters: % _</p>
165             <p class="hint">% matches any number of characters</p>
166             <p class="hint">_ matches only a single character</p>
167           </fieldset>
168           <fieldset>
169             <div class="form-field">
170               <label class="form-field-label" for="itemcallnumber_from">From call number:</label>
171               <input type="text" id="itemcallnumber_from" name="itemcallnumber_from" value="" />
172               <span class="hint">(inclusive)</span>
173             </div>
174             <div class="form-field">
175               <label class="form-field-label" for="itemcallnumber_to">To call number:</label>
176               <input type="text" id="itemcallnumber_to" name="itemcallnumber_to" value="" />
177               <span class="hint">(inclusive)</span>
178             </div>
179             [% INCLUDE form_field_radio_yes_no name="damaged" %]
180             <div class="form-field">
181               <label class="form-field-label" for="issues_op">Checkout count:</label>
182               <select id="issues_op" name="issues_op">
183                 <option value=">">&gt;</option>
184                 <option value="<">&lt;</option>
185                 <option value="=">=</option>
186                 <option value="!=">!=</option>
187               </select>
188               <input type="text" name="issues" />
189             </div>
190             <div class="form-field">
191               <label class="form-field-label" for="datelastborrowed_op">Last checkout date:</label>
192               <select id="datelastborrowed_op" name="datelastborrowed_op">
193                 <option value=">">After</option>
194                 <option value="<">Before</option>
195                 <option value="=">On</option>
196               </select>
197               <input type="text" name="datelastborrowed" />
198               <span class="hint">ISO Format (YYYY-MM-DD)</span>
199             </div>
200           </fieldset>
201           <fieldset>
202             <div class="form-field-radio">
203               <label>Output:</label>
204               <input type="radio" id="format-html" name="format" value="html" checked="checked" /> <label for="format-html">Screen</label>
205               <input type="radio" id="format-csv" name="format" value="csv" /> <label for="format-csv">CSV</label>
206               <input type="radio" id="format-barcodes" name="format" value="barcodes"/> <label for="format-barcodes">Barcodes file</label>
207             </div>
208           </fieldset>
209       </form>
210     </div>
211     </div>
212   </div>
213     <div class="row">
214         <div class="col-md-12">
215       <div id="results-wrapper"></div>
216         </div>
217       </div>
218
219 [% MACRO jsinclude BLOCK %]
220     [% INCLUDE 'datatables.inc' %]
221     [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
222     [% Asset.js("lib/hc-sticky.js") | $raw %]
223     <script type="text/javascript">
224         var authorised_values = [% authorised_values_json | $raw %];
225
226         function loadAuthorisedValuesSelect(select) {
227             var selected = select.find('option:selected');
228             var category = selected.data('authorised-values-category');
229             var form_field_value = select.siblings('.form-field-value');
230             if (category && category in authorised_values) {
231                 var values = authorised_values[category];
232                 var html = '<select name="q" class="form-field-value">\n';
233                 for (i in values) {
234                     var value = values[i];
235                     html += '<option value="' + value.authorised_value + '">' + value.lib + '</option>\n';
236                 }
237                 html += '</select>\n';
238                 var new_form_field_value = $(html);
239                 new_form_field_value.val(form_field_value.val());
240                 form_field_value.replaceWith(new_form_field_value);
241             } else {
242                 if (form_field_value.prop('tagName').toLowerCase() == 'select') {
243                     html = '<input name="q" type="text" class="form-field-value" />';
244                     var new_form_field_value = $(html);
245                     form_field_value.replaceWith(new_form_field_value);
246                 }
247             }
248         }
249
250     function addNewField( link ) {
251             var form_field = $('div.form-field-select-text').last();
252             var copy = form_field.clone(true);
253             copy.find('input,select').not('[type="hidden"]').each(function() {
254                 $(this).val('');
255             });
256             copy.find('.form-field-conjunction').prop('disabled', false);
257             form_field.after(copy);
258       link.remove();
259             copy.find('select.form-field-column').change();
260         }
261
262         function submitForm($form) {
263             var tr = ''
264                 + '    <tr>'
265                 + '      <th id="items_title">' + _("Title") + '</th>'
266                 + '      <th id="items_pubdate">' + _("Publication date") + '</th>'
267                 + '      <th id="items_publisher">' + _("Publisher") + '</th>'
268                 + '      <th id="items_collection">' + _("Collection") + '</th>'
269                 + '      <th id="items_barcode">' + _("Barcode") + '</th>'
270                 + '      <th id="items_callno">' + _("Call number") + '</th>'
271                 + '      <th id="items_homebranch">' + _("Home library") + '</th>'
272                 + '      <th id="items_holdingbranch">' + _("Current location") + '</th>'
273                 + '      <th id="items_location">' + _("Shelving location") + '</th>'
274                 + '      <th id="items_itype">' + _("Itemtype") + '</th>'
275                 + '      <th id="item_inventoryno">' + _("Inventory number") + '</th>'
276                 + '      <th id="items_status">' + _("Not for loan status") + '</th>'
277                 + '      <th id="items_itemlost">' + _("Lost status") + '</th>'
278                 + '      <th id="items_checkouts">' + _("Checkouts") + '</th>'
279                 + '      <th id=""></th>'
280                 + '    </tr>'
281             var table = ''
282                 + '<table id="results">'
283                 + '  <thead>' + tr + tr + '</thead>'
284                 + '  <tbody></tbody>'
285                 + '</table>';
286
287             var advSearchLink = $('<a>')
288                 .attr('href', '/cgi-bin/koha/catalogue/search.pl')
289                 .html(_("Go to advanced search"));
290             var editSearchLink = $('<a>')
291                 .attr('href', '#')
292                 .html(_("Edit search"))
293                 .addClass('btn btn-default btn-xs')
294                 .on('click', function(e) {
295                     e.preventDefault();
296                     $('#item-search-block').show();
297                 });
298
299             var csvExportLink = $('<a>')
300                 .attr('href', '#')
301                 .html(_("Export results to CSV"))
302                 .addClass('btn btn-default btn-xs')
303                 .on('click', function(e) {
304                     e.preventDefault();
305                     $('#format-csv').prop('checked', true);
306                     $('#itemsearchform').submit();
307                     $('#format-html').prop('checked', true);
308                 });
309             var barcodesExportLink = $('<a>')
310                 .attr('href', '#')
311                 .html(_("Export results to barcodes file"))
312                 .addClass('btn btn-default btn-xs')
313                 .on('click', function(e) {
314                     e.preventDefault();
315                     $('#format-barcodes').prop('checked', true);
316                     $('#itemsearchform').submit();
317                     $('#format-html').prop('checked', true);
318               });
319
320             var editSearchAndExportLinks = $('<p>')
321                 .append(editSearchLink)
322                 .append(' | ')
323                 .append(csvExportLink)
324                 .append(' ')
325                 .append(barcodesExportLink);
326
327             var results_heading = $('<div>').addClass('results-heading')
328                 .append("<h1>" + _("Item search results") + "</h1>")
329                 .append($('<p>').append(advSearchLink))
330                 .append(editSearchAndExportLinks);
331             $('#results-wrapper').empty()
332                 .append(results_heading)
333                 .append(table);
334
335             var params = [];
336             $form.find('select:not(:disabled) option:selected,input[type="text"]:not(:disabled),input[type="hidden"]:not(:disabled),input[type="radio"]:checked').each(function() {
337                 if ( $(this).prop('tagName').toLowerCase() == 'option' ) {
338                     var name = $(this).parents('select').first().attr('name');
339                     var value = $(this).val();
340                     params.push({ 'name': name, 'value': value });
341                 } else {
342                     params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
343                 }
344             });
345
346             $('#results').dataTable($.extend(true, {}, dataTablesDefaults, {
347                 'bDestroy': true,
348                 'bServerSide': true,
349                 'bProcessing': true,
350                 'sAjaxSource': '/cgi-bin/koha/catalogue/itemsearch.pl',
351                 'fnServerData': function(sSource, aoData, fnCallback) {
352                     aoData.push( { 'name': 'format', 'value': 'json' } );
353                     for (i in params) {
354                         aoData.push(params[i]);
355                     }
356                     $.ajax({
357                         'dataType': 'json',
358                         'type': 'POST',
359                         'url': sSource,
360                         'data': aoData,
361                         'success': function(json){
362                             fnCallback(json);
363                         }
364                     });
365                 },
366                 'sDom': '<"top pager"ilp>t<"bottom pager"ip>r',
367                 'aoColumns': [
368                     { 'sName': 'title' },
369                     { 'sName': 'publicationyear' },
370                     { 'sName': 'publishercode' },
371                     { 'sName': 'ccode' },
372                     { 'sName': 'barcode' },
373                     { 'sName': 'itemcallnumber' },
374                     { 'sName': 'homebranch' },
375                     { 'sName': 'holdingbranch' },
376                     { 'sName': 'location' },
377                     { 'sName': 'itype'},
378                     { 'sName': 'stocknumber' },
379                     { 'sName': 'notforloan' },
380                     { 'sName': 'itemlost' },
381                     { 'sName': 'issues' },
382                     { 'sName': 'checkbox', 'bSortable': false }
383                 ],
384                 "sPaginationType": "full_numbers"
385             })).columnFilter({
386                 'sPlaceHolder': 'head:after',
387                 'aoColumns': [
388                     { 'type': 'text' },
389                     { 'type': 'text' },
390                     { 'type': 'text' },
391                     [% IF ccodes.size %]
392                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => ccodes %] },
393                     [% ELSE %]
394                         null,
395                     [% END %]
396                     { 'type': 'text' },
397                     { 'type': 'text' },
398                     { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
399                     { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
400                     [% IF locations.size %]
401                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => locations %] },
402                     [% ELSE %]
403                         null,
404                     [% END %]
405                     [% IF itemtypes.size %]
406                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemtypes %] },
407                     [% ELSE %]
408                         null,
409                     [% END %]
410                     { 'type': 'text' },
411                     [% IF notforloans.size %]
412                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => notforloans %] },
413                     [% ELSE %]
414                         null,
415                     [% END %]
416                     [% IF itemlosts.size %]
417                         { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemlosts %] },
418                     [% ELSE %]
419                         null,
420                     [% END %]
421                     { 'type': 'text' },
422                     null
423                 ]
424             });
425         }
426         var Sticky;
427         $(document).ready(function () {
428             Sticky = $("#toolbar");
429             Sticky.hcSticky({
430                 stickTo: "#item-search-block",
431                 stickyClass: "floating"
432             });
433             // Add the "New field" link.
434             var form_field = $('div.form-field-select-text').last()
435             var NEW_FIELD = _("New field");
436       var button_field_new = $('<a href="#" class="button-field-new" title="Add a new field"><i class="fa fa-plus"></i> ' + NEW_FIELD + '</a>');
437       button_field_new.click(function(e) {
438           e.preventDefault();
439           addNewField( $(this) );
440             });
441       form_field.append(button_field_new);
442
443             // If a field is linked to an authorised values list, display the list.
444             $('div.form-field-select-text select').change(function() {
445                 loadAuthorisedValuesSelect($(this));
446             }).change();
447
448             // Prevent user to select the 'All ...' option with other options.
449             $('div.form-field-select').each(function() {
450                 $(this).find('select').filter(':last').change(function() {
451                     values = $(this).val();
452                     if (values.length > 1) {
453                         var idx = $.inArray('', values);
454                         if (idx != -1) {
455                             values.splice(idx, 1);
456                             $(this).val(values);
457                         }
458                     }
459                 });
460                 $('#itemsearchform').submit(function() {
461                   var searchform = $(this);
462                   var format = searchform.find('input[name="format"]:checked').val();
463                   if (format == 'html') {
464                     submitForm(searchform);
465                     $("#item-search-block").hide();
466                     return false;
467                   }
468                 });
469             });
470         });
471     </script>
472 [% END %]
473
474 [% INCLUDE 'intranet-bottom.inc' %]