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