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