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