Bug 16485: collection column in Item search is always empty
[koha.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 [% INCLUDE 'doc-head-open.inc' %]
102   <title>Koha &rsaquo; Catalog &rsaquo; Item search</title>
103   [% INCLUDE 'doc-head-close.inc' %]
104   <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
105   [% INCLUDE 'datatables.inc' %]
106   <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.columnFilter.js"></script>
107   <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat.js"></script>
108   <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/itemsearchform.css" />
109   <script type="text/javascript">
110     //<![CDATA[
111     var authorised_values = [% authorised_values_json %];
112
113     function loadAuthorisedValuesSelect(select) {
114       var selected = select.find('option:selected');
115       var category = selected.data('authorised-values-category');
116       var form_field_value = select.siblings('.form-field-value');
117       if (category && category in authorised_values) {
118         var values = authorised_values[category];
119         var html = '<select name="q" class="form-field-value">\n';
120         for (i in values) {
121           var value = values[i];
122           html += '<option value="' + value.authorised_value + '">' + value.lib + '</option>\n';
123         }
124         html += '</select>\n';
125         var new_form_field_value = $(html);
126         new_form_field_value.val(form_field_value.val());
127         form_field_value.replaceWith(new_form_field_value);
128       } else {
129         if (form_field_value.prop('tagName').toLowerCase() == 'select') {
130           html = '<input name="q" type="text" class="form-field-value" />';
131           var new_form_field_value = $(html);
132           form_field_value.replaceWith(new_form_field_value);
133         }
134       }
135     }
136
137     function addNewField() {
138       var form_field = $('div.form-field-select-text').last();
139       var copy = form_field.clone(true);
140       copy.find('input,select').not('[type="hidden"]').each(function() {
141         $(this).val('');
142       });
143       copy.find('.form-field-conjunction').prop('disabled', false);
144       form_field.after(copy);
145       copy.find('select.form-field-column').change();
146     }
147
148     function submitForm($form) {
149       var tr = ''
150         + '    <tr>'
151         + '      <th>' + _("Title") + '</th>'
152         + '      <th>' + _("Publication date") + '</th>'
153         + '      <th>' + _("Publisher") + '</th>'
154         + '      <th>' + _("Collection") + '</th>'
155         + '      <th>' + _("Barcode") + '</th>'
156         + '      <th>' + _("Call number") + '</th>'
157         + '      <th>' + _("Home library") + '</th>'
158         + '      <th>' + _("Current location") + '</th>'
159         + '      <th>' + _("Shelving location") + '</th>'
160         + '      <th>' + _("Inventory number") + '</th>'
161         + '      <th>' + _("Status") + '</th>'
162         + '      <th>' + _("Checkouts") + '</th>'
163         + '      <th></th>'
164         + '    </tr>'
165       var table = ''
166         + '<table id="results">'
167         + '  <thead>' + tr + tr + '</thead>'
168         + '  <tbody></tbody>'
169         + '</table>';
170
171       var advSearchLink = $('<a>')
172         .attr('href', '/cgi-bin/koha/catalogue/search.pl')
173         .html(_("Go to advanced search"));
174       var editSearchLink = $('<a>')
175         .attr('href', '#')
176         .html(_("Edit search"))
177         .addClass('btn btn-default btn-xs')
178         .on('click', function(e) {
179           e.preventDefault();
180           $('#item-search-block').show();
181         });
182
183       var csvExportLink = $('<a>')
184         .attr('href', '#')
185         .html(_("Export results to CSV"))
186         .addClass('btn btn-default btn-xs')
187         .on('click', function(e) {
188           e.preventDefault();
189           $('#format-csv').prop('checked', true);
190           $('#itemsearchform').submit();
191           $('#format-html').prop('checked', true);
192         });
193       var barcodesExportLink = $('<a>')
194         .attr('href', '#')
195         .html(_("Export results to barcodes file"))
196         .addClass('btn btn-default btn-xs')
197         .on('click', function(e) {
198           e.preventDefault();
199           $('#format-barcodes').prop('checked', true);
200           $('#itemsearchform').submit();
201           $('#format-html').prop('checked', true);
202         });
203
204       var editSearchAndExportLinks = $('<p>')
205         .append(editSearchLink)
206         .append(' | ')
207         .append(csvExportLink)
208         .append(' ')
209         .append(barcodesExportLink);
210
211       var results_heading = $('<div>').addClass('results-heading')
212         .append("<h1>" + _("Item search results") + "</h1>")
213         .append($('<p>').append(advSearchLink))
214         .append(editSearchAndExportLinks);
215       $('#results-wrapper').empty()
216         .append(results_heading)
217         .append(table);
218
219       var params = [];
220       $form.find('select').not(':disabled').find('option:selected').each(function () {
221         var name = $(this).parents('select').first().attr('name');
222         var value = $(this).val();
223         params.push({ 'name': name, 'value': value });
224       });
225       $form.find('input[type="text"],input[type="hidden"]').not(':disabled').each(function () {
226         params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
227       });
228       $form.find('input[type="radio"]:checked').each(function() {
229         params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
230       });
231
232       $('#results').dataTable($.extend(true, {}, dataTablesDefaults, {
233         'bDestroy': true,
234         'bServerSide': true,
235         'bProcessing': true,
236         'sAjaxSource': '/cgi-bin/koha/catalogue/itemsearch.pl',
237         'fnServerData': function(sSource, aoData, fnCallback) {
238           aoData.push( { 'name': 'format', 'value': 'json' } );
239           for (i in params) {
240             aoData.push(params[i]);
241           }
242           $.ajax({
243               'dataType': 'json',
244               'type': 'POST',
245               'url': sSource,
246               'data': aoData,
247               'success': function(json){
248                   fnCallback(json);
249               }
250           });
251         },
252         'sDom': '<"top pager"ilp>t<"bottom pager"ip>r',
253         'aoColumns': [
254           { 'sName': 'title' },
255           { 'sName': 'publicationyear' },
256           { 'sName': 'publishercode' },
257           { 'sName': 'ccode' },
258           { 'sName': 'barcode' },
259           { 'sName': 'itemcallnumber' },
260           { 'sName': 'homebranch' },
261           { 'sName': 'holdingbranch' },
262           { 'sName': 'location' },
263           { 'sName': 'stocknumber' },
264           { 'sName': 'notforloan' },
265           { 'sName': 'issues' },
266           { 'sName': 'checkbox', 'bSortable': false }
267         ],
268         "sPaginationType": "full_numbers"
269       })).columnFilter({
270         'sPlaceHolder': 'head:after',
271         'aoColumns': [
272           { 'type': 'text' },
273           { 'type': 'text' },
274           { 'type': 'text' },
275           { 'type': 'select', 'values': [% ccodes.json %] },
276           { 'type': 'text' },
277           { 'type': 'text' },
278           { 'type': 'select', 'values': [% branches.json %] },
279           { 'type': 'select', 'values': [% branches.json %] },
280           [% IF locations.size %]
281               { 'type': 'select', 'values': [% locations.json %] },
282           [% ELSE %]
283               null,
284           [% END %]
285           { 'type': 'text' },
286           [% IF notforloans.size %]
287               { 'type': 'select', 'values': [% notforloans.json %] },
288           [% ELSE %]
289               null,
290           [% END %]
291           { 'type': 'text' },
292           null
293         ]
294       });
295     }
296
297     $(document).ready(function () {
298       $('#toolbar').fixFloat();
299       // Add the "New field" link.
300       var form_field = $('div.form-field-select-text').last()
301       var NEW_FIELD = _("New field");
302       var button_field_new = $('<a href="#" class="button-field-new" title="Add a new field">' + NEW_FIELD + '</a>');
303       button_field_new.click(function() {
304         addNewField();
305         return false;
306       });
307       form_field.after(button_field_new);
308
309       // If a field is linked to an authorised values list, display the list.
310       $('div.form-field-select-text select').change(function() {
311         loadAuthorisedValuesSelect($(this));
312       }).change();
313
314       // Prevent user to select the 'All ...' option with other options.
315       $('div.form-field-select').each(function() {
316         $(this).find('select').filter(':last').change(function() {
317           values = $(this).val();
318           if (values.length > 1) {
319             var idx = $.inArray('', values);
320             if (idx != -1) {
321               values.splice(idx, 1);
322               $(this).val(values);
323             }
324           }
325         });
326       });
327
328       $('#itemsearchform').submit(function() {
329         var searchform = $(this);
330         var format = searchform.find('input[name="format"]:checked').val();
331         if (format == 'html') {
332           submitForm(searchform);
333           $("#item-search-block").hide();
334           return false;
335         }
336       });
337     });
338     //]]>
339   </script>
340 </head>
341 <body id="catalog_itemsearch" class="catalog">
342   [% INCLUDE 'header.inc' %]
343   [% INCLUDE 'home-search.inc' %]
344   <div id="breadcrumbs">
345     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> &rsaquo; Item search
346   </div>
347
348   <div id="doc" class="yui-t7">
349     <div id="item-search-block">
350       <h1>Item search</h1>
351       <p><a href="/cgi-bin/koha/catalogue/search.pl">Go to advanced search</a></p>
352       <form action="/cgi-bin/koha/catalogue/itemsearch.pl" method="get" id="itemsearchform">
353           <div id="toolbar" class="btn-toolbar">
354               <fieldset class="action">
355                   <div class="btn-group">
356                       <button class="btn btn-default btn-sm"><i class="fa fa-search"></i> Search</button>
357                   </div>
358               </fieldset>
359           </div>
360           <fieldset>
361             [% INCLUDE form_field_select name="homebranch" options = branches empty_option = "All libraries" %]
362             [% INCLUDE form_field_select name="holdingbranch" options = branches empty_option = "All libraries" %]
363             [% IF locations.size %]
364                 [% INCLUDE form_field_select name="location" options = locations empty_option = "All locations" %]
365             [% END %]
366           </fieldset>
367           <fieldset>
368             [% INCLUDE form_field_select name="itype" options = itemtypes empty_option = "All item types" %]
369             [% INCLUDE form_field_select name="ccode" options = ccodes empty_option = "All collection codes" %]
370             [% IF notforloans.size %]
371                 [% INCLUDE form_field_select name="notforloan" options = notforloans empty_option = "All statuses" %]
372             [% END %]
373           </fieldset>
374           <fieldset>
375             [% INCLUDE form_field_select_text %]
376             <p class="hint">You can use the following wildcard characters: % _</p>
377             <p class="hint">% matches any number of characters</p>
378             <p class="hint">_ matches only a single character</p>
379           </fieldset>
380           <fieldset>
381             <div class="form-field">
382               <label class="form-field-label" for="itemcallnumber_from">From call number:</label>
383               <input type="text" id="itemcallnumber_from" name="itemcallnumber_from" value="" />
384               <span class="hint">(inclusive)</span>
385             </div>
386             <div class="form-field">
387               <label class="form-field-label" for="itemcallnumber_to">To call number:</label>
388               <input type="text" id="itemcallnumber_to" name="itemcallnumber_to" value="" />
389               <span class="hint">(inclusive)</span>
390             </div>
391             [% INCLUDE form_field_radio_yes_no name="damaged" %]
392             [% INCLUDE form_field_radio_yes_no name="itemlost" %]
393             <div class="form-field">
394               <label class="form-field-label" for="issues_op">Checkout count:</label>
395               <select id="issues_op" name="issues_op">
396                 <option value=">">&gt;</option>
397                 <option value="<">&lt;</option>
398                 <option value="=">=</option>
399                 <option value="!=">!=</option>
400               </select>
401               <input type="text" name="issues" />
402             </div>
403             <div class="form-field">
404               <label class="form-field-label" for="datelastborrowed_op">Last checkout date:</label>
405               <select id="datelastborrowed_op" name="datelastborrowed_op">
406                 <option value=">">After</option>
407                 <option value="<">Before</option>
408                 <option value="=">On</option>
409               </select>
410               <input type="text" name="datelastborrowed" />
411               <span class="hint">ISO Format (YYYY-MM-DD)</span>
412             </div>
413           </fieldset>
414           <fieldset>
415             <div class="form-field-radio">
416               <label>Output:</label>
417               <input type="radio" id="format-html" name="format" value="html" checked="checked" /> <label for="format-html">Screen</label>
418               <input type="radio" id="format-csv" name="format" value="csv" /> <label for="format-csv">CSV</label>
419               <input type="radio" id="format-barcodes" name="format" value="barcodes"/> <label for="format-barcodes">Barcodes file</label>
420             </div>
421           </fieldset>
422       </form>
423     </div>
424   </div>
425   <div id="doc3" class="yui-t7">
426       <div id="results-wrapper"></div>
427
428     [% INCLUDE 'intranet-bottom.inc' %]