From 428cb1254c997668b0a0dae2bb4e650c5aefac88 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Tue, 22 Oct 2019 11:47:04 +0000
Subject: [PATCH] Bug 23885: Move staff client search results JavaScript into
 separate file

This patch moves most of the JavaScript embedded in results.tt into a
separate file. The JavaScript that remains on the page is everything
which requires processing by Template Toolkit. This is limited to
variable definition.

To test, apply the patch and perform a catalog search in the staff
client. On the results page, test that JavaScript functionality has not
been affected:

 - The search results toolbar should "float" as you scroll
 - Select all and Clear all
 - Default search term highlighting; Unhighlight and highlight controls
 - Adding and removing one or more items from the cart
 - Adding one or more items to a list
 - Placing one or more holds my making selections and clicking "Place
   hold"
 - Browse selected records
 - Z39.50 search (search form should be populated with your search
   terms)
 - "Show more" and "Show less" links in the facets sidebar
 - Book cover image services: Amazon, Coce, local covers, etc.
 - Open a patron record and click "Search to hold"
  - Perform a search and select one or more results
    - Test "Place hold" from the hold menu in the toolbar
    - Test "Place hold for..." from the hold menu in the toolbar
    - Test "Forget..." from the hold menu in the toolbar
 - In Tools -> Patron clubs, locate a club with enrolled members
   - From the "Actions" menu, select "Search to hold"
     - Perform a search and select one or more results
       - Test "Place hold" from the hold menu in the toolbar
       - Test "Place hold for..." from the hold menu in the toolbar
       - Test "Forget..." from the hold menu in the toolbar
---
 .../intranet-tmpl/prog/en/includes/strings.inc     |   1 +
 .../prog/en/modules/catalogue/results.tt           | 350 +++------------------
 koha-tmpl/intranet-tmpl/prog/js/pages/results.js   | 308 ++++++++++++++++++
 3 files changed, 344 insertions(+), 315 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/js/pages/results.js

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc
index ff5291dcf91..75f54c026ee 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc
@@ -13,6 +13,7 @@
     var PREVIOUS_CHECKOUTS = _("Previous checkouts");
     var BY = _("by _AUTHOR_");
     var ON_HOLD = _("On hold");
+    var PLACE_HOLD = _("Place hold");
     var NOT_RENEWABLE = _("Not renewable");
     var NOT_RENEWABLE_TOO_SOON = _("No renewal before %s");
     var NOT_RENEWABLE_AUTO_TOO_SOON = _("Scheduled for automatic renewal");
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
index 326b60fa3ef..eff9ea4a01d 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
@@ -672,324 +672,44 @@
     <script>
         var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
         var MSG_NON_RESERVES_SELECTED = _("One or more selected items cannot be placed on hold.");
+        var PREF_AmazonCoverImages = parseInt( [% Koha.Preference('AmazonCoverImages') | html %], 10);
         var q_array = new Array();  // will hold search terms, if present
-        [% IF ( AmazonCoverImages ) %]
-            // http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
-            function verify_images() {
-                $("img").each(function(i){
-                    if ((this.src.indexOf('images-amazon.com') >= 0) || (this.src.indexOf('images.amazon.com') >=0)) {
-                        w = this.width;
-                        h = this.height;
-                        if ((w == 1) || (h == 1)) {
-                            $(this).parent().html('<span class="no-image">No cover image available</span>');
-                        } else if ((this.complete != null) && (!this.complete)) {
-                            $(this).parent().html('<span class="no-image">No cover image available</span>');
-                        }
-                    }
-                });
-            }
-
-            $(window).load(function() {
-                verify_images();
-            });
-        [% END %]
-        var Sticky;
-        $(document).ready(function() {
-
-            $(".moretoggle").click(function(e) {
-                e.preventDefault();
-                $(this).siblings(".collapsible-facet").toggle();
-                $(this).siblings(".moretoggle").toggle();
-                $(this).toggle();
-            });
-
-            Sticky = $("#searchheader");
-            Sticky.hcSticky({
-                stickTo: "main",
-                stickyClass: "floating"
-            });
-
-            $("#cartsubmit").click(function(e){
-                e.preventDefault();
-                addMultiple();
-            });
-
-            $(".addtolist").on("click",function(e){
-                e.preventDefault();
-                var shelfnumber = $(this).data("shelfnumber");
-                var vshelf = vShelfAdd();
-                if( vshelf ){
-                    if( $(this).hasClass("morelists") ){
-                        openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?' + vshelf);
-                    } else if( $(this).hasClass("newlist") ){
-                        openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&' + vshelf);
-                    } else {
-                        openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&' + vshelf);
-                    }
-                }
-            });
-
-            $("#z3950submit").click(function(){
-                PopupZ3950();
-                return false;
-            });
-
-            $("#searchheader").on("click", ".browse_selection", function(){
-                browse_selection();
-                return false;
-            });
-
-            $("#searchheader").on("click",".placehold", function(){
-                $("#holdFor").val("");
-                $("#holdForClub").val("");
-                placeHold();
-                $(".btn-group").removeClass("open");
-                return false;
-            });
-
-            $(".placeholdfor").click(function(){
-                holdForPatron();
-                $(".btn-group").removeClass("open");
-                return false;
-            });
-
-            $(".placeholdforclub").click(function(){
-                holdForClub();
-                $(".btn-group").removeClass("open");
-                return false;
-            });
-
-            $("#forgetholdfor, #forgetholdforclub").click(function(){
-                forgetPatronAndClub();
-                $(".btn-group").removeClass("open");
-                return false;
-            });
-
-            $("#tagsel_span").html("<input id=\"tagsel_tag\" class=\"submit\" type=\"submit\" value=\"Tag\"/>");
-
-            $(".selection").show();
-
-            [% IF ( query_desc ) %]
-                toHighlight = $("p,span.results_summary,a.title");
-                var query_desc = "[% query_desc |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
-                q_array = query_desc.split(" ");
-                // ensure that we don't have "" at the end of the array, which can
-                // break the highlighter
-                while (q_array.length > 0 && q_array[q_array.length-1] == "") {
-                    q_array = q_array.splice(0,-1);
-                }
-                highlightOn();
-                $("#highlight_toggle_on" ).hide().click(function(e) {
-                    e.preventDefault();
-                     highlightOn();
-                });
-                $("#highlight_toggle_off").show().click(function(e) {
-                    e.preventDefault();
-                    highlightOff();
-                });
-            [% END %]
-
-            [% IF (SEARCH_RESULTS) %]
-                var newresults = [
-                    [%- FOREACH result IN SEARCH_RESULTS -%]
-                        [%- result.biblionumber | html %],
-                    [%- END -%]
-                ];
-                var browser = KOHA.browser('[% searchid | html %]', parseInt('[% biblionumber | html %]', 10));
-                browser.create([% SEARCH_RESULTS.first.result_number | html %], '[% query_cgi | html %]', '[% limit_cgi | html %]','[% sort_cgi | html %]',
-                       newresults, '[% total | html %]');
-            [% END %]
-
-            [% IF (gotoPage && gotoNumber) %]
-                [% IF (gotoNumber == 'first') %]
-                    window.location = '/cgi-bin/koha/catalogue/[% gotoPage | html %]?biblionumber=' + [% SEARCH_RESULTS.first.biblionumber | html %] + '&searchid=[% searchid | html %]';
-                [% ELSIF (gotoNumber == 'last') %]
-                    window.location = '/cgi-bin/koha/catalogue/[% gotoPage | html %]?biblionumber=' + [% SEARCH_RESULTS.last.biblionumber | html %] + '&searchid=[% searchid | html %]';
-                [% END %]
-            [% END %]
-
-            [% IF LocalCoverImages %]
-                KOHA.LocalCover.LoadResultsCovers();
-            [% END %]
-
-            [% IF ( IntranetCoce && CoceProviders ) %]
-                KOHA.coce.getURL('[% CoceHost | html %]', '[% CoceProviders | html %]');
-            [% END %]
-
-            $("#select_all").on("click",function(e){
-                e.preventDefault();
-                selectAll();
-            });
-
-            $("#clear_all").on("click",function(e){
-                e.preventDefault();
-                clearAll();
-            });
-
-            $("#searchresults").on("click",".addtocart",function(e){
-                e.preventDefault();
-                var selection_id = this.id;
-                var biblionumber = selection_id.replace("cart","");
-                addRecord(biblionumber);
-            });
-
-            $("#searchresults").on("click",".cartRemove",function(e){
-                e.preventDefault();
-                var selection_id = this.id;
-                var biblionumber = selection_id.replace("cartR","");
-                delSingleRecord(biblionumber);
-            });
-
-            [% UNLESS Koha.Preference('BrowseResultSelection') %]
-                resetSearchContext();
-            [% END %]
-            $(".selection").change(function(){
-                if ( $(this).is(':checked') == true ) {
-                  addBibToContext( $(this).val() );
-                } else {
-                  delBibToContext( $(this).val() );
-                }
-            });
-            $("#bookbag_form").ready(function(){
-                $("#bookbag_form").unCheckCheckboxes();
-                var bibnums = getContextBiblioNumbers();
-                if (bibnums) {
-                    for (var i=0; i < bibnums.length; i++) {
-                        var id = ('#bib' + bibnums[i]);
-                        if ($(id)) {
-                            $(id).attr('checked', true);
-                        }
-                    }
-                }
-            });
-
-        });
-
-
-        [% IF ( query_desc ) %]
-            function highlightOff() {
-                toHighlight.removeHighlight();
-                $(".highlight_toggle").toggle();
-            }
-            function highlightOn() {
-                var x;
-                for (x in q_array) {
-                    q_array[x] = q_array[x].toLowerCase();
-                    var myStopwords = "[% Koha.Preference('NotHighlightedWords') | html %]".toLowerCase().split('|');
-                    if ( (q_array[x].length > 0) && ($.inArray(q_array[x], myStopwords) == -1) ) {
-                        toHighlight.highlight(q_array[x]);
-                    }
-                }
-                $(".highlight_toggle").toggle();
-            }
-        [% END %]
-
-        function selectAll () {
-            $("#bookbag_form").checkCheckboxes();
-            $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
-                $(this).change();
-            } );
-            return false;
-        }
-        function clearAll () {
-            $("#bookbag_form").unCheckCheckboxes();
-            $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
-                $(this).change();
-            } );
-            return false;
-        }
-        function placeHold () {
-            var checkedItems = $(".selection:checked");
-            if ($(checkedItems).size() == 0) {
-                alert(MSG_NO_ITEM_SELECTED);
-                return false;
-            }
-            var bibs = "";
-            var badBibs = false;
-            $(checkedItems).each(function() {
-                var bib = $(this).val();
-                if ($("#reserve_" + bib).size() == 0) {
-                    alert(MSG_NON_RESERVES_SELECTED);
-                    badBibs = true;
-                    return false;
-                }
-                bibs += bib + "/";
-            });
-            if (badBibs) {
-                return false;
-            }
-            $("#hold_form_biblios").val(bibs);
-            $("#hold_form").submit();
-            return false;
-        }
-
-        function forgetPatronAndClub(){
-            $.removeCookie("holdfor", { path: '/' });
-            $.removeCookie("holdforclub", { path: '/' });
-            $(".holdforlink").remove();
-            $("#placeholdc").html("<a class=\"btn btn-default btn-xs placehold\" href=\"#\"><i class=\"fa fa-sticky-note-o\"></i> "+_("Place hold")+"</a>");
-        }
-
-        function browse_selection () {
-            var bibnums = getContextBiblioNumbers();
-            if ( bibnums && bibnums.length > 0 ) {
-                var browser = KOHA.browser('', parseInt('[% biblionumber | html %]', 10));
-                browser.create(1, '[% query_cgi | html %]', '[% limit_cgi | html %]','[% sort_cgi | html %]', bibnums, bibnums.length);
-                window.location = '/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + bibnums[0] + '&searchid='+browser.searchid;
-            } else {
-                alert(MSG_NO_ITEM_SELECTED);
-            }
-            return false;
-        }
-
-        function addToList () {
-            var checkedItems = $(".selection:checked");
-            if ($(checkedItems).size() == 0) {
-                alert(MSG_NO_ITEM_SELECTED);
-                return false;
-            }
-            var bibs = "";
-            $(checkedItems).each(function() {
-                bibs += $(this).val() + "/";
-            });
-
-            var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
-            window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
-            return false;
-        }
-
-        /* this function open a popup to search on z3950 server.  */
-        function PopupZ3950() {
-            var strQuery = GetZ3950Terms();
-            if(strQuery){
-                window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=[% biblionumber | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
-            }
-        }
-        /* provide Z3950 search points */
-        function GetZ3950Terms(){
-            var strQuery="&frameworkcode=";
-            [% FOREACH z3950_search_param IN z3950_search_params %]
-                strQuery += "&" + "[% z3950_search_param.name |uri %]" + "=" + "[% z3950_search_param.value |uri %]";
-            [% END %]
-            return strQuery;
-        }
-
-        function holdfor(){
-            $("#holdFor").val("");
-            $("#holdForClub").val("");
-            placeHold();
-        }
-
-        function holdForPatron() {
-            $("#holdFor").val("[% holdfor_cardnumber | html %]");
-            placeHold();
-        }
-
-        function holdForClub() {
-            $("#holdForClub").val("[% holdforclub | html %]");
-            placeHold();
+        var PREF_LocalCoverImages = parseInt( [% Koha.Preference('LocalCoverImages') | html %], 10);
+        var PREF_IntranetCoce = parseInt( [% Koha.Preference('IntranetCoce') | html %], 10);
+        var PREF_CoceProviders = "[% Koha.Preference('CoceProviders') | html %]";
+        var CoceHost = "[% CoceHost | html %]";
+        var CoceProviders = "[% CoceProviders | html %]";
+        var PREF_BrowseResultSelection = parseInt( [% Koha.Preference('BrowseResultSelection') | html %], 10);
+        var PREF_NotHighlightedWords = "[% Koha.Preference('NotHighlightedWords') | html %]";
+        var biblionumber = "[% biblionumber | html %]";
+        var holdfor_cardnumber = "[% holdfor_cardnumber | html %]";
+        var holdforclub = "[% holdforclub | html %]";
+        var SEARCH_RESULTS = [% IF (SEARCH_RESULTS) %]1[% ELSE %]0[% END %];
+        var new_results_browser = [
+            [%- FOREACH result IN SEARCH_RESULTS -%]
+                [%- result.biblionumber | html -%],
+            [%- END -%]
+        ];
+        var strQuery="&frameworkcode=";
+        [%- FOREACH z3950_search_param IN z3950_search_params -%]
+            strQuery += "&" + "[% z3950_search_param.name |uri %]" + "=" + "[% z3950_search_param.value |uri %]";
+        [%- END -%]
+
+        var search_result = {
+            query_desc: "[% query_desc |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]",
+            query_cgi: "[% query_cgi | html %]",
+            limit_cgi: "[% limit_cgi | html %]",
+            sort_cgi: "[% sort_cgi | html %]",
+            gotoPage: "[% gotoPage | html %]",
+            gotoNumber: "[% gotoNumber | html %]",
+            searchid: "[% searchid | html %]",
+            total: "[% total | html %]",
+            first_result_number: "[% SEARCH_RESULTS.first.result_number | html %]",
+            first_biblionumber: "[% SEARCH_RESULTS.first.biblionumber | html %]",
+            last_biblionumber: "[% SEARCH_RESULTS.last.biblionumber | html %]",
         }
     </script>
+    [% Asset.js("js/pages/results.js") | $raw %]
 [% END %]
 
 [% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js
new file mode 100644
index 00000000000..d99c4c2ec73
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js
@@ -0,0 +1,308 @@
+/* global KOHA biblionumber new_results_browser addMultiple vShelfAdd openWindow search_result SEARCH_RESULTS PREF_AmazonCoverImages PREF_LocalCoverImages PREF_IntranetCoce PREF_CoceProviders CoceHost CoceProviders addRecord delSingleRecord PREF_BrowseResultSelection resetSearchContext addBibToContext delBibToContext getContextBiblioNumbers MSG_NO_ITEM_SELECTED MSG_NO_ITEM_SELECTED holdfor_cardnumber holdforclub strQuery MSG_NON_RESERVES_SELECTED PREF_NotHighlightedWords PLACE_HOLD */
+
+if( PREF_AmazonCoverImages ){
+    $(window).load(function() {
+        verify_images();
+    });
+}
+
+var Sticky;
+var toHighlight = {};
+var q_array;
+
+$(document).ready(function() {
+
+    $(".moretoggle").click(function(e) {
+        e.preventDefault();
+        $(this).siblings(".collapsible-facet").toggle();
+        $(this).siblings(".moretoggle").toggle();
+        $(this).toggle();
+    });
+
+    Sticky = $("#searchheader");
+    Sticky.hcSticky({
+        stickTo: "main",
+        stickyClass: "floating"
+    });
+
+    $("#cartsubmit").click(function(e){
+        e.preventDefault();
+        addMultiple();
+    });
+
+    $(".addtolist").on("click",function(e){
+        e.preventDefault();
+        var shelfnumber = $(this).data("shelfnumber");
+        var vshelf = vShelfAdd();
+        if( vshelf ){
+            if( $(this).hasClass("morelists") ){
+                openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?' + vshelf);
+            } else if( $(this).hasClass("newlist") ){
+                openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&' + vshelf);
+            } else {
+                openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&' + vshelf);
+            }
+        }
+    });
+
+    $("#z3950submit").click(function(){
+        PopupZ3950();
+        return false;
+    });
+
+    $("#searchheader").on("click", ".browse_selection", function(){
+        browse_selection();
+        return false;
+    });
+
+    $("#searchheader").on("click",".placehold", function(){
+        $("#holdFor").val("");
+        $("#holdForClub").val("");
+        placeHold();
+        $(".btn-group").removeClass("open");
+        return false;
+    });
+
+    $(".placeholdfor").click(function(){
+        holdForPatron();
+        $(".btn-group").removeClass("open");
+        return false;
+    });
+
+    $(".placeholdforclub").click(function(){
+        holdForClub();
+        $(".btn-group").removeClass("open");
+        return false;
+    });
+
+    $("#forgetholdfor, #forgetholdforclub").click(function(){
+        forgetPatronAndClub();
+        $(".btn-group").removeClass("open");
+        return false;
+    });
+
+    $(".selection").show();
+
+    if( search_result.query_desc ){
+        toHighlight = $("p,span.results_summary,a.title");
+        q_array = search_result.query_desc.split(" ");
+        // ensure that we don't have "" at the end of the array, which can
+        // break the highlighter
+        while ( q_array.length > 0 && q_array[q_array.length-1] == "") {
+            q_array = q_array.splice(0,-1);
+        }
+        highlightOn();
+        $("#highlight_toggle_on" ).hide().click(function(e) {
+            e.preventDefault();
+            highlightOn();
+        });
+        $("#highlight_toggle_off").show().click(function(e) {
+            e.preventDefault();
+            highlightOff();
+        });
+    }
+
+    if( SEARCH_RESULTS ){
+        var browser = KOHA.browser( search_result.searchid, parseInt( biblionumber, 10));
+        browser.create( search_result.first_result_number, search_result.query_cgi, search_result.limit_cgi, search_result.sort_cgi, new_results_browser, search_result.total );
+    }
+
+    if( search_result.gotoPage && search_result.gotoNumber){
+        if( search_result.gotoNumber == 'first' ){
+            window.location = "/cgi-bin/koha/catalogue/" + search_result.gotoPage + "?biblionumber=" + search_result.first_biblionumber + "&searchid=" + search_result.searchid;
+        } else if( search_result.gotoNumber == "last" ){
+            window.location = "/cgi-bin/koha/catalogue/" + search_result.gotoPage + "?biblionumber=" + search_result.last_biblionumber + "&searchid=" + search_result.searchid;
+        }
+    }
+
+    if( PREF_LocalCoverImages ){
+        KOHA.LocalCover.LoadResultsCovers();
+    }
+
+    if( PREF_IntranetCoce && PREF_CoceProviders ){
+        KOHA.coce.getURL( CoceHost, CoceProviders );
+    }
+
+    $("#select_all").on("click",function(e){
+        e.preventDefault();
+        selectAll();
+    });
+
+    $("#clear_all").on("click",function(e){
+        e.preventDefault();
+        clearAll();
+    });
+
+    $("#searchresults").on("click",".addtocart",function(e){
+        e.preventDefault();
+        var selection_id = this.id;
+        var biblionumber = selection_id.replace("cart","");
+        addRecord(biblionumber);
+    });
+
+    $("#searchresults").on("click",".cartRemove",function(e){
+        e.preventDefault();
+        var selection_id = this.id;
+        var biblionumber = selection_id.replace("cartR","");
+        delSingleRecord(biblionumber);
+    });
+
+    if( !PREF_BrowseResultSelection ){
+        resetSearchContext();
+    }
+
+    $(".selection").change(function(){
+        if ( $(this).is(':checked') == true ) {
+            addBibToContext( $(this).val() );
+        } else {
+            delBibToContext( $(this).val() );
+        }
+    });
+    $("#bookbag_form").ready(function(){
+        $("#bookbag_form").unCheckCheckboxes();
+        var bibnums = getContextBiblioNumbers();
+        if (bibnums) {
+            for (var i=0; i < bibnums.length; i++) {
+                var id = ('#bib' + bibnums[i]);
+                if ($(id)) {
+                    $(id).attr('checked', true);
+                }
+            }
+        }
+    });
+});
+
+
+function highlightOff() {
+    if( toHighlight.length > 0 ){
+        toHighlight.removeHighlight();
+        $(".highlight_toggle").toggle();
+    }
+}
+
+function highlightOn() {
+    if( toHighlight.length > 0 ){
+        var x;
+        for (x in q_array) {
+            q_array[x] = q_array[x].toLowerCase();
+            var myStopwords = PREF_NotHighlightedWords.toLowerCase().split('|');
+            if ( (q_array[x].length > 0) && ($.inArray(q_array[x], myStopwords) == -1) ) {
+                toHighlight.highlight(q_array[x]);
+            }
+        }
+        $(".highlight_toggle").toggle();
+    }
+}
+
+
+function selectAll () {
+    $("#bookbag_form").checkCheckboxes();
+    $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
+        $(this).change();
+    } );
+    return false;
+}
+function clearAll () {
+    $("#bookbag_form").unCheckCheckboxes();
+    $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
+        $(this).change();
+    } );
+    return false;
+}
+function placeHold () {
+    var checkedItems = $(".selection:checked");
+    if ($(checkedItems).size() == 0) {
+        alert(MSG_NO_ITEM_SELECTED);
+        return false;
+    }
+    var bibs = "";
+    var badBibs = false;
+    $(checkedItems).each(function() {
+        var bib = $(this).val();
+        if ($("#reserve_" + bib).size() == 0) {
+            alert(MSG_NON_RESERVES_SELECTED);
+            badBibs = true;
+            return false;
+        }
+        bibs += bib + "/";
+    });
+    if (badBibs) {
+        return false;
+    }
+    $("#hold_form_biblios").val(bibs);
+    $("#hold_form").submit();
+    return false;
+}
+
+function forgetPatronAndClub(){
+    $.removeCookie("holdfor", { path: '/' });
+    $.removeCookie("holdforclub", { path: '/' });
+    $(".holdforlink").remove();
+    $("#placeholdc").html("<a class=\"btn btn-default btn-xs placehold\" href=\"#\"><i class=\"fa fa-sticky-note-o\"></i> " + PLACE_HOLD + "</a>");
+}
+
+function browse_selection () {
+    var bibnums = getContextBiblioNumbers();
+    if ( bibnums && bibnums.length > 0 ) {
+        var browser = KOHA.browser('', parseInt( biblionumber, 10));
+        browser.create(1, search_result.query_cgi, search_result.limit_cgi, search_result.sort_cgi, bibnums, bibnums.length);
+        window.location = '/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + bibnums[0] + '&searchid='+browser.searchid;
+    } else {
+        alert(MSG_NO_ITEM_SELECTED);
+    }
+    return false;
+}
+
+function addToList () {
+    var checkedItems = $(".selection:checked");
+    if ($(checkedItems).size() == 0) {
+        alert(MSG_NO_ITEM_SELECTED);
+        return false;
+    }
+    var bibs = "";
+    $(checkedItems).each(function() {
+        bibs += $(this).val() + "/";
+    });
+
+    var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
+    window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
+    return false;
+}
+
+/* this function open a popup to search on z3950 server.  */
+function PopupZ3950() {
+    if( strQuery ){
+        window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=" + biblionumber + strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
+    }
+}
+
+function holdfor(){
+    $("#holdFor").val("");
+    $("#holdForClub").val("");
+    placeHold();
+}
+
+function holdForPatron() {
+    $("#holdFor").val( holdfor_cardnumber );
+    placeHold();
+}
+
+function holdForClub() {
+    $("#holdForClub").val( holdforclub );
+    placeHold();
+}
+
+// http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
+function verify_images() {
+    $("img").each(function(){
+        if ((this.src.indexOf('images-amazon.com') >= 0) || (this.src.indexOf('images.amazon.com') >=0)) {
+            var w = this.width;
+            var h = this.height;
+            if ((w == 1) || (h == 1)) {
+                $(this).parent().html('<span class="no-image">No cover image available</span>');
+            } else if ((this.complete != null) && (!this.complete)) {
+                $(this).parent().html('<span class="no-image">No cover image available</span>');
+            }
+        }
+    });
+}
\ No newline at end of file
-- 
2.11.0