Bug 19290: Browse selected bibliographic records - Staff interface
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 11 Oct 2017 22:06:17 +0000 (19:06 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 19 Feb 2018 19:13:30 +0000 (16:13 -0300)
This patch adds the same feature as bug 10858 for the OPAC interface:
after a search, librarians will be able to browse selected results.
The results can be selected from several pages.
By extension it is possible to add results from several pages to a list
or the cart.

When at least one result is selected, a new "Browse selected records" button
becomes usable and change the behaviour of the existing browser.

The whole feature can be turned off with the pref BrowseResultSelection.

Test plan:
- Launch a search (on the staff interface)
- Check some biblios
- Go on another page
- Check some biblios
- Come back to a page you already check results and confirm that they are
still checked
- Click on the "Browse selected records" button
- Check that you are able to browse results you had checked.

You can also:
- add them to the cart
- add them to a list

QA note: the browsers at the OPAC and the one at the staff interface are completely different
That's why the code is not mimicking what has been done on bug 10858.
The behaviour must stay the same anyway.

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

installer/data/mysql/atomicupdate/bug_19290.sql [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/js/browser.js
koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc
koha-tmpl/intranet-tmpl/prog/en/includes/page-numbers.inc
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
koha-tmpl/intranet-tmpl/prog/js/basket.js
koha-tmpl/intranet-tmpl/prog/js/cart.js
koha-tmpl/intranet-tmpl/prog/js/commons.js [new file with mode: 0644]

diff --git a/installer/data/mysql/atomicupdate/bug_19290.sql b/installer/data/mysql/atomicupdate/bug_19290.sql
new file mode 100644 (file)
index 0000000..67a64df
--- /dev/null
@@ -0,0 +1 @@
+INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES  ('BrowseResultSelection','0',NULL,'Enable/Disable browsing search results fromt the bibliographic record detail page in staff client','YesNo');
index 8e6887c..8f5e94b 100644 (file)
@@ -92,6 +92,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('BorrowersTitles','Mr|Mrs|Miss|Ms',NULL,'Define appropriate Titles for patrons','free'),
 ('BorrowerUnwantedField','',NULL,'Name the fields you don\'t need to store for a patron\'s account','free'),
 ('BranchTransferLimitsType','ccode','itemtype|ccode','When using branch transfer limits, choose whether to limit by itemtype or collection code.','Choice'),
+('BrowseResultSelection','0',NULL,'Enable/Disable browsing search results fromt the bibliographic record detail page in staff client','YesNo'),
 ('CalculateFinesOnReturn','1','','Switch to control if overdue fines are calculated on return or not','YesNo'),
 ('CalendarFirstDayOfWeek','0','0|1|2|3|4|5|6','Select the first day of week to use in the calendar.','Choice'),
 ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library place a hold on an item from another library','YesNo'),
index 1557243..7e40785 100644 (file)
@@ -102,7 +102,7 @@ KOHA.browser = function (searchid, biblionumber) {
                     } else {
                         nextbutton = '<a href="#" id="browse-next" class="browse-button">' + BROWSER_NEXT + ' »</a>';
                     }
-                    $('#menu').before('<div class="browse-controls"><div class="browse-controls-inner"><div class="browse-label"><a href="' + searchURL + '" id="browse-return-to-results" class="browse-button">' + BROWSER_RETURN_TO_SEARCH + '</a></div><div class="browse-prev-next">' + prevbutton + nextbutton + '</div></div></div>');
+                    $('#menu').before('<div class="browse-controls"><div class="browse-controls-inner"><div class="browse-label"><a href="' + searchURL + '" id="browse-return-to-results" class="browse-button searchwithcontext">' + BROWSER_RETURN_TO_SEARCH + '</a></div><div class="browse-prev-next">' + prevbutton + nextbutton + '</div></div></div>');
                     $('a#browse-previous').click(function (ev) {
                         ev.preventDefault();
                         browseRecords(-1);
index 33e99b4..4ac51f9 100644 (file)
@@ -21,6 +21,7 @@
 <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.validate.min_[% KOHA_VERSION %].js"></script>
 <!-- koha core js -->
 <script type="text/javascript" src="[% interface %]/[% theme %]/js/staff-global_[% KOHA_VERSION %].js"></script>
+<script type="text/javascript" src="[% interface %]/[% theme %]/js/commons_[% KOHA_VERSION %].js"></script>
 
 [% INCLUDE 'validator-strings.inc' %]
 [% IF ( IntranetUserJS ) %]
index 1c9bd33..af4bc09 100644 (file)
@@ -1,18 +1,18 @@
 [% IF ( PAGE_NUMBERS ) %]<nav><ul class="pagination">
     [% IF ( previous_page_offset.defined ) %]
-        <li><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">First</a></li>
+        <li><a class="nav" href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">First</a></li>
         <!-- Row of numbers corresponding to search result pages -->
-        <li><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% previous_page_offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">&lt;&lt; Previous</a></li>
+        <li><a class="nav" href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% previous_page_offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">&lt;&lt; Previous</a></li>
     [% END %]
     [% FOREACH PAGE_NUMBER IN PAGE_NUMBERS %]
         [% IF ( PAGE_NUMBER.highlight ) %]
             <li class="active"><span>[% PAGE_NUMBER.pg %]</span></li>
         [% ELSE %]
-            <li><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% PAGE_NUMBER.offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">[% PAGE_NUMBER.pg %]</a></li>
+            <li><a class="nav" href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% PAGE_NUMBER.offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">[% PAGE_NUMBER.pg %]</a></li>
         [% END %]
     [% END %]
     [% IF ( next_page_offset ) %]
-        <li><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% next_page_offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">Next &gt;&gt;</a></li>
-        <li><a href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% last_page_offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">Last</a></li>
+        <li><a class="nav" href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% next_page_offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">Next &gt;&gt;</a></li>
+        <li><a class="nav" href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;offset=[% last_page_offset %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">Last</a></li>
     [% END %]
 </ul></nav>[% END %]
index 0178468..ad28e82 100644 (file)
@@ -78,6 +78,13 @@ Searching:
                   yes: Keep
                   no: "Don't keep"
             - patron search history in the staff client.
+        -
+            - pref: BrowseResultSelection
+              default: 0
+              choices:
+                  yes: Enable
+                  no: Disable
+            - "browsing search results fromt the bibliographic record detail page in staff client."
     Search Form:
         -
             - Load the unlogged history to the next user.
index 1cf0f81..3640a9c 100644 (file)
     <script type="text/javascript" src="[% interface %]/js/browser_[% KOHA_VERSION %].js"></script>
     <script type="text/javascript" src="[% interface %]/[% theme %]/js/table_filters_[% KOHA_VERSION %].js"></script>
     <script type="text/javascript">
-        var browser = KOHA.browser('[% searchid %]', parseInt(biblionumber, 10));
+        var browser;
+        browser = KOHA.browser('[% searchid %]', parseInt(biblionumber, 10));
         browser.show();
 
         $(document).ready(function() {
index 8848abb..459bc08 100644 (file)
                     <div id="placeholdc" class="btn-group"><a class="btn btn-default btn-xs placehold" href="#"><i class="fa fa-sticky-note-o"></i> Place hold</a></div>
                 [% END %]
                 [% END %]
+                [% IF Koha.Preference('BrowseResultSelection') %]
+                    <div id="browse_selection" class="btn-group"><a class="btn btn-default btn-xs browse_selection" href="#"><i class="fa fa-sticky-note-o"></i> Browse selected records</a></div>
+                [% END %]
 
                 [% IF ( CAN_user_editcatalogue_edit_catalogue ) %] <div class="btn-group"><a class="btn btn-default btn-xs" id="z3950submit" href="#"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>[% END %]
 
     [% INCLUDE 'browser-strings.inc' %]
     <script type="text/javascript" src="[% interface %]/js/browser_[% KOHA_VERSION %].js"></script>
     <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min_[% KOHA_VERSION %].js"></script>
     <script type="text/javascript">
         var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
         var MSG_NON_RESERVES_SELECTED = _("One or more selected items cannot be placed on hold.");
 
             $("#cartsubmit").click(function(e){
                 e.preventDefault();
-                var checkboxes = $("#searchresults").find(":checkbox");
-                addMultiple(checkboxes);
+                addMultiple();
             });
 
             $(".addtolist").on("click",function(e){
                 e.preventDefault();
                 var shelfnumber = $(this).data("shelfnumber");
-                var checkboxes = $("#searchresults").find(":checkbox");
-                var vshelf = vShelfAdd(checkboxes);
+                var vshelf = vShelfAdd();
                 if( vshelf ){
                     if( $(this).hasClass("morelists") ){
                         openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?' + vshelf);
                 return false;
             });
 
+            $("#searchheader").on("click", ".browse_selection", function(){
+                browse_selection();
+                return false;
+            });
+
             $("#searchheader").on("click",".placehold", function(){
                 $("#holdFor").val("");
                 placeHold();
                 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);
+                        }
+                    }
+                }
+            });
+
         });
 
 
         [% END %]
 
         function selectAll () {
-            $(".selection").prop("checked", true);
+            $("#bookbag_form").checkCheckboxes();
+            $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
+                $(this).change();
+            } );
+            return false;
         }
         function clearAll () {
-            $(".selection").prop("checked", false);
+            $("#bookbag_form").unCheckCheckboxes();
+            $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
+                $(this).change();
+            } );
+            return false;
         }
         function placeHold () {
             var checkedItems = $(".selection:checked");
             $("#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, '[% query_cgi %]', '[% limit_cgi | uri %]','[% sort_cgi | uri %]', 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) {
index 8a255ab..e477cce 100644 (file)
@@ -157,17 +157,31 @@ function SelectAll(){
 
 function addMultiple(biblist){
     var c_value = "";
-    if(biblist.length > 0) {
+    if( biblist && biblist.length > 0 ) {
         for (var i=0; i < biblist.length; i++) {
             if (biblist[i].checked) {
                 c_value = c_value + biblist[i].value + "/";
             }
         }
-        addSelRecords(c_value);
     } else {
-        c_value = c_value + biblist.value + "/";
-        addSelRecords(c_value);
+        var bibnums = getContextBiblioNumbers();
+        if ( bibnums.length > 0 ) {
+            for ( var i = 0 ; i < bibnums.length ; i++ ) {
+                c_value = c_value + bibnums[i] + "/";
+            }
+        } else {
+            if(document.bookbag_form.biblionumber.length > 0) {
+                for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
+                    if (document.bookbag_form.biblionumber[i].checked) {
+                        c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
+                    }
+                }
+            } else {
+                c_value = c_value + document.bookbag_form.biblionumber.value + "/";
+            }
+        }
     }
+    addSelRecords(c_value);
 }
 
 function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
@@ -421,20 +435,24 @@ function addSelToShelf() {
 ///  vShelfAdd()  builds url string for multiple-biblio adds.
 
 function vShelfAdd(biblist) {
-        bibs = [];
-        if(biblist.length > 0) {
-                for (var i=0; i < biblist.length; i++) {
-                        if (biblist[i].checked) {
-                                bibs.push("biblionumber=" +  biblist[i].value);
-                        }
-                }
+    var bibs = new Array;
+    if( biblist && biblist.length > 0 ) {
+        for (var i=0; i < biblist.length; i++) {
+            if (biblist[i].checked) {
+                bibs.push("biblionumber=" +  biblist[i].value);
+            }
+        }
         if (bibs.length === 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
-            return bibs.join("&");
-        } else {
-            if (biblist.checked) {
-                return "biblionumber=" + biblist.value;
+        return bibs.join("&");
+    } else {
+        var bibnums = getContextBiblioNumbers();
+        if ( bibnums.length > 0 ) {
+            for ( var i = 0 ; i < bibnums.length ; i++ ) {
+                bibs.push("biblionumber=" + bibnums[i]);
             }
+            return bibs.join("&");
         }
+    }
 }
 
 function showCart(){
index 0494398..2d801b6 100644 (file)
@@ -71,6 +71,7 @@ $(document).ready(function(){
     $("#bookbag_form").checkCheckboxes("*", true).each(
         function() {
             selRecord(this.value,true);
+            $(this).change();
         }
     );
         return false;
@@ -80,6 +81,7 @@ $(document).ready(function(){
     $("#bookbag_form").unCheckCheckboxes("*",true).each(
         function() {
             selRecord(this.value,false);
+            $(this).change();
         }
     );
         return false;
diff --git a/koha-tmpl/intranet-tmpl/prog/js/commons.js b/koha-tmpl/intranet-tmpl/prog/js/commons.js
new file mode 100644 (file)
index 0000000..4981c07
--- /dev/null
@@ -0,0 +1,73 @@
+// Extends jQuery API
+jQuery.extend({uniqueArray:function(array){
+    return $.grep(array, function(el, index) {
+        return index === $.inArray(el, array);
+    });
+}});
+
+function removeByValue(arr, val) {
+    for(var i=0; i<arr.length; i++) {
+        if(arr[i] == val) {
+            arr.splice(i, 1);
+            break;
+        }
+    }
+}
+
+function paramOfUrl( url, param ) {
+    param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
+    var regexS = "[\\?&]"+param+"=([^&#]*)";
+    var regex = new RegExp( regexS );
+    var results = regex.exec( url );
+    if( results == null ) {
+        return "";
+    } else {
+        return results[1];
+    }
+}
+
+function addBibToContext( bibnum ) {
+    bibnum = parseInt(bibnum, 10);
+    var bibnums = getContextBiblioNumbers();
+    bibnums.push(bibnum);
+    setContextBiblioNumbers( bibnums );
+    setContextBiblioNumbers( $.uniqueArray( bibnums ) );
+}
+
+function delBibToContext( bibnum ) {
+    var bibnums = getContextBiblioNumbers();
+    removeByValue( bibnums, bibnum );
+    setContextBiblioNumbers( $.uniqueArray( bibnums ) );
+}
+
+function setContextBiblioNumbers( bibnums ) {
+    $.cookie('bibs_selected', JSON.stringify( bibnums ));
+}
+
+function getContextBiblioNumbers() {
+    var r = $.cookie('bibs_selected');
+    if ( r ) {
+        return JSON.parse(r);
+    }
+    r = new Array();
+    return r;
+}
+
+function resetSearchContext() {
+    setContextBiblioNumbers( new Array() );
+}
+
+$(document).ready(function(){
+    // forms with action leading to search
+    $("form[action*='search.pl']").submit(function(){
+        resetSearchContext();
+    });
+    // any link to launch a search except navigation links
+    $("[href*='search.pl?']").not(".nav").not('.searchwithcontext').click(function(){
+        resetSearchContext();
+    });
+    // any link to a detail page from the results page.
+    $("#bookbag_form a[href*='detail.pl?']").click(function(){
+        resetSearchContext();
+    });
+});