From 2a060e07385a772cdb5d82a0aa8cc4b741b9fb0c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Dec 2019 10:45:11 +0100 Subject: [PATCH] Bug 24219: Preserve sort order when returning to result list There is a mismatch between sort_cgi, sort and sort_by variables. * sort_cgi I did not find relevant occurrences of sort_cgi in the git log of both search.pl and results.tt. So it seems that it never worked correctly. * sort It is the JS variable use in browser.js * sort_by is the search.pl parameter to set the sort_by option Test plan: 1. Perform a search in the staff client 2. Change the sort order to something different (try Author A-Z) 3. Click on a result to view the record 4. Click on "Results" button on left side to return to result list => Without this patch the result list is sorted by relevancy => With this patch applied the Author A-Z is kept Signed-off-by: Michal Denar Signed-off-by: Nick Clemens --- koha-tmpl/intranet-tmpl/js/browser.js | 6 +++--- koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/pages/results.js | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/js/browser.js b/koha-tmpl/intranet-tmpl/js/browser.js index 3b9ca87cbb..09f1d02d38 100644 --- a/koha-tmpl/intranet-tmpl/js/browser.js +++ b/koha-tmpl/intranet-tmpl/js/browser.js @@ -32,9 +32,9 @@ KOHA.browser = function (searchid, biblionumber) { var browseRecords = function (movement) { var newSearchPos = me.curPos + movement; if (newSearchPos > current_search.results.length - 1) { - window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort=' + current_search.sort + '&gotoPage=detail.pl&gotoNumber=first&searchid=' + me.searchid + '&offset=' + newSearchPos; + window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort_by=' + current_search.sort + '&gotoPage=detail.pl&gotoNumber=first&searchid=' + me.searchid + '&offset=' + newSearchPos; } else if (newSearchPos < 0) { - window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort=' + current_search.sort + '&gotoPage=detail.pl&gotoNumber=last&searchid=' + me.searchid + '&offset=' + (me.offset - current_search.pagelen); + window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort_by=' + current_search.sort + '&gotoPage=detail.pl&gotoNumber=last&searchid=' + me.searchid + '&offset=' + (me.offset - current_search.pagelen); } else { window.location = window.location.href.replace('biblionumber=' + biblionumber, 'biblionumber=' + current_search.results[newSearchPos]); } @@ -91,7 +91,7 @@ KOHA.browser = function (searchid, biblionumber) { $(document).ready(function () { if (me.curPos > -1) { - var searchURL = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort=' + current_search.sort + '&searchid=' + me.searchid + '&offset=' + me.offset; + var searchURL = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort_by=' + current_search.sort + '&searchid=' + me.searchid + '&offset=' + me.offset; var prevbutton; var nextbutton; if (me.curPos === 0 && current_search.offset === 1) { 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 211b4164e3..4b66e8e516 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -708,6 +708,7 @@ query_cgi: "[% query_cgi | html %]", limit_cgi: "[% limit_cgi | html %]", sort_cgi: "[% sort_cgi | html %]", + sort_by: "[% sort_by | html %]", gotoPage: "[% gotoPage | html %]", gotoNumber: "[% gotoNumber | html %]", searchid: "[% searchid | html %]", diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js index d99c4c2ec7..0887f4ae8c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js @@ -104,7 +104,7 @@ $(document).ready(function() { 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 ); + browser.create( search_result.first_result_number, search_result.query_cgi, search_result.limit_cgi, search_result.sort_by, new_results_browser, search_result.total ); } if( search_result.gotoPage && search_result.gotoNumber){ @@ -245,7 +245,7 @@ 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); + browser.create(1, search_result.query_cgi, search_result.limit_cgi, search_result.sort_by, bibnums, bibnums.length); window.location = '/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + bibnums[0] + '&searchid='+browser.searchid; } else { alert(MSG_NO_ITEM_SELECTED); @@ -305,4 +305,4 @@ function verify_images() { } } }); -} \ No newline at end of file +} -- 2.11.0