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