Bug 23847: Fix custom item search fields if subfield is '0'
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / en / modules / catalogue / itemsearch.tt
index ee130b6..ee1b43e 100644 (file)
@@ -1,5 +1,6 @@
+[% USE raw %]
+[% USE To %]
 [% USE Asset %]
-[% USE JSON.Escape %]
 
 [% BLOCK form_label %]
   [% SWITCH label %]
     [% CASE 'All statuses' %]<span>All statuses</span>
     [% CASE 'damaged' %]<span>Damaged</span>
     [% CASE 'itemlost' %]<span>Lost</span>
+    [% CASE 'withdrawn' %]<span>Withdrawn</span>
   [% END %]
 [% END %]
 
 [% BLOCK form_field_select %]
   <div class="form-field form-field-select">
-    <label class="form-field-label" for="[% name %]">[% INCLUDE form_label label=name %]</label>
-    <select id="[% name %]_op" name="[% name %]_op">
+    <label class="form-field-label" for="[% name | html %]">[% INCLUDE form_label label=name %]</label>
+    <select id="[% name | html %]_op" name="[% name | html %]_op">
       <option value="=">is</option>
       <option value="!=" >is not</option>
     </select>
-    <select id="[% name %]" name="[% name %]" multiple="multiple" size="[% options.size < 4 ? options.size + 1 : 4 %]">
+    <select id="[% name | html %]" name="[% name | html %]" multiple="multiple" size="[% options.size < 4 ? options.size + 1 : 4 | html %]">
       <option value="" selected="selected">
         [% IF (empty_option) %][% INCLUDE form_label label=empty_option %][% ELSE %]<span>All</span>[% END %]
       </option>
       [% FOREACH option IN options %]
-        <option value="[% option.value %]">[% option.label %]</option>
+        <option value="[% option.value | html %]">[% option.label | html %]</option>
       [% END %]
     </select>
   </div>
 [% END %]
 
 [% BLOCK form_field_select_option %]
-  <option value="[% value %]">[% INCLUDE form_label label=value %]</option>
+  <option value="[% value | html %]">[% INCLUDE form_label label=value %]</option>
 [% END %]
 
 [% BLOCK form_field_select_text %]
         <optgroup label="Custom search fields">
           [% FOREACH field IN items_search_fields %]
             [% marcfield = field.tagfield %]
-            [% IF field.tagsubfield %]
+            [% IF field.tagsubfield.defined AND field.tagsubfield != "" %]
               [% marcfield = marcfield _ '$' _ field.tagsubfield %]
             [% END %]
-            <option value="marc:[% marcfield %]" data-authorised-values-category="[% field.authorised_values_category %]">[% field.label %] ([% marcfield %])</option>
+            <option value="marc:[% marcfield | html %]" data-authorised-values-category="[% field.authorised_values_category | html %]">[% field.label | html %] ([% marcfield | html %])</option>
           [% END %]
         </optgroup>
       [% END %]
 [% BLOCK form_field_radio_yes_no %]
   <div class="form-field">
     <label class="form-field-label">[% INCLUDE form_label label=name %]:</label>
-    <input type="radio" name="[% name %]" id="[% name %]_indifferent" value="" checked="checked"/>
-    <label for="[% name %]_indifferent">Ignore</label>
-    <input type="radio" name="[% name %]" id="[% name %]_yes" value="yes" />
-    <label for="[% name %]_yes">Yes</label>
-    <input type="radio" name="[% name %]" id="[% name %]_no" value="no" />
-    <label for="[% name %]_no">No</label>
+    <input type="radio" name="[% name | html %]" id="[% name | html %]_indifferent" value="" checked="checked"/>
+    <label for="[% name | html %]_indifferent">Ignore</label>
+    <input type="radio" name="[% name | html %]" id="[% name | html %]_yes" value="yes" />
+    <label for="[% name | html %]_yes">Yes</label>
+    <input type="radio" name="[% name | html %]" id="[% name | html %]_no" value="no" />
+    <label for="[% name | html %]_no">No</label>
   </div>
 [% END %]
 
+[%# We need to escape html characters for 'value' and 'label' %]
+[%- BLOCK escape_html_value_label -%]
+    [%- SET escaped = [] -%]
+    [%- FOR e IN elts -%]
+        [%- value = BLOCK %][% e.value | html %][% END -%]
+        [%- label = BLOCK %][% e.label | html %][% END -%]
+        [%- escaped.push({ 'value' => value, 'label' => label }) -%]
+    [%- END -%]
+    [%- To.json(escaped) | $raw -%]
+[%- END -%]
+
 [%# Page starts here %]
 
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
   <title>Koha &rsaquo; Catalog &rsaquo; Item search</title>
   [% INCLUDE 'doc-head-close.inc' %]
-  [% Asset.css("css/itemsearchform.css") %]
-  [% Asset.css("css/datatables.css") %]
+  [% Asset.css("css/itemsearchform.css") | $raw %]
 </head>
 
 <body id="catalog_itemsearch" class="catalog">
           <div id="toolbar" class="btn-toolbar">
               <fieldset class="action">
                   <div class="btn-group">
-                      <button class="btn btn-default btn-sm"><i class="fa fa-search"></i> Search</button>
+                      <button class="btn btn-default"><i class="fa fa-search"></i> Search</button>
                   </div>
               </fieldset>
           </div>
             [% IF notforloans.size %]
                 [% INCLUDE form_field_select name="notforloan" options = notforloans empty_option = "All statuses" %]
             [% END %]
+            [% IF itemlosts.size %]
+                [% INCLUDE form_field_select name="itemlost" options = itemlosts empty_option = "All statuses" %]
+            [% END %]
+            [% IF withdrawns.size %]
+                [% INCLUDE form_field_select name="withdrawn" options = withdrawns empty_option = "All statuses" %]
+            [% END %]
           </fieldset>
           <fieldset>
             [% INCLUDE form_field_select_text %]
               <span class="hint">(inclusive)</span>
             </div>
             [% INCLUDE form_field_radio_yes_no name="damaged" %]
-            [% INCLUDE form_field_radio_yes_no name="itemlost" %]
             <div class="form-field">
               <label class="form-field-label" for="issues_op">Checkout count:</label>
               <select id="issues_op" name="issues_op">
 
 [% MACRO jsinclude BLOCK %]
     [% INCLUDE 'datatables.inc' %]
-    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") %]
-    [% Asset.js("lib/jquery/plugins/jquery.fixFloat.js") %]
-    <script type="text/javascript">
-        var authorised_values = [% authorised_values_json %];
+    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
+    [% Asset.js("lib/hc-sticky.js") | $raw %]
+    <script>
+        var authorised_values = [% authorised_values_json | $raw %];
 
         function loadAuthorisedValuesSelect(select) {
             var selected = select.find('option:selected');
                 + '      <th id="items_homebranch">' + _("Home library") + '</th>'
                 + '      <th id="items_holdingbranch">' + _("Current location") + '</th>'
                 + '      <th id="items_location">' + _("Shelving location") + '</th>'
+                + '      <th id="items_itype">' + _("Itemtype") + '</th>'
                 + '      <th id="item_inventoryno">' + _("Inventory number") + '</th>'
-                + '      <th id="items_status">' + _("Status") + '</th>'
+                + '      <th id="items_status">' + _("Not for loan status") + '</th>'
+                + '      <th id="items_itemlost">' + _("Lost status") + '</th>'
+                + '      <th id="items_widthdrawn">' + _("Withdrawn status") + '</th>'
                 + '      <th id="items_checkouts">' + _("Checkouts") + '</th>'
                 + '      <th id=""></th>'
                 + '    </tr>'
                 .append(table);
 
             var params = [];
-            $form.find('select').not(':disabled').find('option:selected').each(function () {
-                var name = $(this).parents('select').first().attr('name');
-                var value = $(this).val();
-                params.push({ 'name': name, 'value': value });
-            });
-            $form.find('input[type="text"],input[type="hidden"]').not(':disabled').each(function () {
-                params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
-            });
-            $form.find('input[type="radio"]:checked').each(function() {
-                params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
+            $form.find('select:not(:disabled) option:selected,input[type="text"]:not(:disabled),input[type="hidden"]:not(:disabled),input[type="radio"]:checked').each(function() {
+                if ( $(this).prop('tagName').toLowerCase() == 'option' ) {
+                    var name = $(this).parents('select').first().attr('name');
+                    var value = $(this).val();
+                    params.push({ 'name': name, 'value': value });
+                } else {
+                    params.push({ 'name': $(this).attr('name'), 'value': $(this).val() });
+                }
             });
 
             $('#results').dataTable($.extend(true, {}, dataTablesDefaults, {
                     { 'sName': 'title' },
                     { 'sName': 'publicationyear' },
                     { 'sName': 'publishercode' },
-          { 'sName': 'ccode' },
+                    { 'sName': 'ccode' },
                     { 'sName': 'barcode' },
                     { 'sName': 'itemcallnumber' },
                     { 'sName': 'homebranch' },
                     { 'sName': 'holdingbranch' },
                     { 'sName': 'location' },
+                    { 'sName': 'itype'},
                     { 'sName': 'stocknumber' },
                     { 'sName': 'notforloan' },
+                    { 'sName': 'itemlost' },
+                    { 'sName': 'withdrawn' },
                     { 'sName': 'issues' },
                     { 'sName': 'checkbox', 'bSortable': false }
                 ],
                     { 'type': 'text' },
                     { 'type': 'text' },
                     [% IF ccodes.size %]
-                        { 'type': 'select', 'values': [% ccodes.json %] },
+                        { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => ccodes %] },
                     [% ELSE %]
                         null,
                     [% END %]
                     { 'type': 'text' },
                     { 'type': 'text' },
-                    { 'type': 'select', 'values': [% branches.json %] },
-                    { 'type': 'select', 'values': [% branches.json %] },
+                    { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
+                    { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
                     [% IF locations.size %]
-                        { 'type': 'select', 'values': [% locations.json %] },
+                        { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => locations %] },
+                    [% ELSE %]
+                        null,
+                    [% END %]
+                    [% IF itemtypes.size %]
+                        { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemtypes %] },
                     [% ELSE %]
                         null,
                     [% END %]
                     { 'type': 'text' },
                     [% IF notforloans.size %]
-                        { 'type': 'select', 'values': [% notforloans.json %] },
+                        { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => notforloans %] },
+                    [% ELSE %]
+                        null,
+                    [% END %]
+                    [% IF itemlosts.size %]
+                        { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemlosts %] },
+                    [% ELSE %]
+                        null,
+                    [% END %]
+                    [% IF withdrawns.size %]
+                        { 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => withdrawns %] },
                     [% ELSE %]
                         null,
                     [% END %]
                 ]
             });
         }
-
+        var Sticky;
         $(document).ready(function () {
-            $('#toolbar').fixFloat();
+            Sticky = $("#toolbar");
+            Sticky.hcSticky({
+                stickTo: "#item-search-block",
+                stickyClass: "floating"
+            });
             // Add the "New field" link.
             var form_field = $('div.form-field-select-text').last()
             var NEW_FIELD = _("New field");
       form_field.append(button_field_new);
 
             // If a field is linked to an authorised values list, display the list.
-            $('div.form-field-select-text select').change(function() {
+            $('div.form-field-select-text select[name="f"]').change(function() {
                 loadAuthorisedValuesSelect($(this));
             }).change();
 
                         }
                     }
                 });
-                $('#itemsearchform').submit(function() {
-                  var searchform = $(this);
-                  var format = searchform.find('input[name="format"]:checked').val();
-                  if (format == 'html') {
+            });
+
+            $('#itemsearchform').submit(function() {
+                var searchform = $(this);
+                var format = searchform.find('input[name="format"]:checked').val();
+                if (format == 'html') {
                     submitForm(searchform);
                     $("#item-search-block").hide();
                     return false;
-                  }
-                });
+                }
             });
         });
     </script>