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