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