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