From 44ba7c27c8a5ca22fd82589ce5dd6c1c4505a151 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 29 Jun 2018 14:53:38 -0300 Subject: [PATCH] Bug 21024: (bug 20864 follow-up) Only set bibs_selected cookie when BrowseResultSelection is activated This is an attempt to fix correctly the problem bug 20864 tried to solve. The cookie bibs_selected must only be defined if BrowseResultSelection is set. Bug 20864 removed the inclusion of commons.js, but some code from results.tt We should include it and take care of the pref in each function. Test plan: Retest 19290 and 20864 --- .../intranet-tmpl/prog/en/includes/js_includes.inc | 13 ++++++-- .../prog/en/modules/catalogue/results.tt | 17 +++++----- koha-tmpl/intranet-tmpl/prog/js/commons.js | 37 ++++++++++++++-------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc index 946859a018..d16c905e18 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -12,6 +12,15 @@ [% END %] +[%# Define prefs we will need all around %] + + [% Asset.js("lib/jquery/jquery-2.2.3.min.js") %] [% Asset.js("lib/jquery/jquery-migrate-1.3.0.min.js") %] [% Asset.js("lib/jquery/jquery-ui-1.11.4.min.js") %] @@ -22,9 +31,7 @@ [% Asset.js("lib/jquery/plugins/jquery.validate.min.js") %] [% Asset.js("js/staff-global.js") %] -[% IF Koha.Preference('BrowseResultSelection') %] - [% Asset.js("js/commons.js") %] -[% END %] +[% Asset.js("js/commons.js") %] [% INCLUDE 'validator-strings.inc' %] [% IF ( IntranetUserJS ) %] 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 bb294cd92e..c93aba1f71 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -773,16 +773,17 @@ delSingleRecord(biblionumber); }); - [% UNLESS Koha.Preference('BrowseResultSelection') %] + [% IF Koha.Preference('BrowseResultSelection') %] + $(".selection").change(function(){ + if ( $(this).is(':checked') == true ) { + addBibToContext( $(this).val() ); + } else { + delBibToContext( $(this).val() ); + } + }); + [% ELSE %] 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(); diff --git a/koha-tmpl/intranet-tmpl/prog/js/commons.js b/koha-tmpl/intranet-tmpl/prog/js/commons.js index 4981c07946..8021c8327b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/commons.js +++ b/koha-tmpl/intranet-tmpl/prog/js/commons.js @@ -27,6 +27,7 @@ function paramOfUrl( url, param ) { } function addBibToContext( bibnum ) { + if ( ! global_pref_BrowseResultSelection ) return; bibnum = parseInt(bibnum, 10); var bibnums = getContextBiblioNumbers(); bibnums.push(bibnum); @@ -35,12 +36,15 @@ function addBibToContext( bibnum ) { } function delBibToContext( bibnum ) { + if ( ! global_pref_BrowseResultSelection ) return; var bibnums = getContextBiblioNumbers(); removeByValue( bibnums, bibnum ); setContextBiblioNumbers( $.uniqueArray( bibnums ) ); } function setContextBiblioNumbers( bibnums ) { + if ( ! global_pref_BrowseResultSelection ) return; + $.cookie('bibs_selected', JSON.stringify( bibnums )); } @@ -54,20 +58,27 @@ function getContextBiblioNumbers() { } function resetSearchContext() { - setContextBiblioNumbers( new Array() ); + if ( global_pref_BrowseResultSelection ) { + setContextBiblioNumbers( new Array() ); + } else { + $.cookie('bibs_selected', '', { 'path': '/', 'expires': -1 }); + } } $(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(); - }); + + if ( ! global_pref_BrowseResultSelection ) { + // 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(); + }); + } }); -- 2.11.0