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