Bug 17790: Fix js error on undefined autocomplete(...).data(...)
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Mon, 19 Dec 2016 11:55:59 +0000 (12:55 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 20 Dec 2016 13:25:19 +0000 (13:25 +0000)
Bug 17418 moved some code to js_includes.inc.
But if #findborrower does not exist, you cannot define _renderItem.
Trivial fix.

Test plan:
[1] Find a page where this include is used and #findborrowers is absent.
    Like about.pl
[2] Without this patch, you will have a js error in the js console.
[3] With this patch, you should no longer have it.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc

index 326f22a..414425a 100644 (file)
@@ -89,7 +89,7 @@
     [% IF ( CircAutocompl ) %]
         <script type="text/javascript">
             $(document).ready(function(){
-                $( "#findborrower" ).autocomplete({
+                var obj = $( "#findborrower" ).autocomplete({
                     source: "/cgi-bin/koha/circ/ysearch.pl",
                     minLength: 3,
                     select: function( event, ui ) {
                         $("#patronsearch").submit();
                         return false;
                     }
-                })
-                .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
-                    return $( "<li></li>" )
-                    .data( "ui-autocomplete-item", item )
-                    .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.dateofbirth + " " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
-                    .appendTo( ul );
-                };
+                }).data( "ui-autocomplete" );
+                if( obj ) {
+                    obj._renderItem = function( ul, item ) {
+                        return $( "<li></li>" )
+                        .data( "ui-autocomplete-item", item )
+                        .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.dateofbirth + " " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
+                        .appendTo( ul );
+                    };
+                }
             });
         </script>
     [% END %]