From 325d4f21f3450f75207c4c87e702a3dd88e19132 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 2 Nov 2020 17:15:31 -0300 Subject: [PATCH] Bug 20212: (QA follow-up) Remember current filter This patch restores the original behaviour: if you jump into receiving an order, and then go back to receiving, you want the page to remember your filters. This feature was overlooked. On fixing it, I wrapped some JS code in a function for reusing it and simplified it a bit as well. To test: 1. Enter a search term in either of the search fields 2. Add a note, receive or do another action => SUCCESS: The search term is kept 3. Apply this patch set 4. Repeat 2 => SUCCESS: The search term is kept Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- acqui/parcel.pl | 22 +++- .../prog/en/modules/acqui/parcel.tt | 117 +++++++++++------- 2 files changed, 91 insertions(+), 48 deletions(-) diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 3705dfc833..9e4974ba90 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -74,8 +74,7 @@ use Koha::Biblios; use JSON; -my $input=CGI->new; -my $sticky_filters = $input->param('sticky_filters') || 0; +my $input = CGI->new; my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "acqui/parcel.tt", @@ -110,6 +109,25 @@ unless( $invoiceid and $invoice->{invoiceid} ) { exit; } +my $sticky_filters = $input->param('sticky_filters') || 0; + +if ($sticky_filters) { + my $search = $input->cookie("filter_parcel_summary"); + my $ean = $input->cookie("filter_parcel_ean"); + my $basketname = $input->cookie("filter_parcel_basketname"); + my $orderno = $input->cookie("filter_parcel_orderno"); + my $basketgroupname = $input->cookie("filter_parcel_basketgroupname"); + + $template->param( + summaryfilter => $search, + eanfilter => $ean, + basketfilter => $basketname, + orderfilter => $orderno, + basketgroupnamefilter => $basketgroupname, + ); +} + + my $booksellerid = $invoice->{booksellerid}; my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt index 0899a4fdbf..a10c806bef 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -372,6 +372,39 @@ dt_overwrite_html_sorting_localeCompare(); var sticky_filters = [% sticky_filters | html %]; + function query_from_filters( base_query, params ) { + + var query_and = []; + + if ( params.basket_name != "" ) { + query_and.push( { "basket.name": { "like": '%'+params.basket_name+'%' } } ); + } + if (params.basket_group != "") { + query_and.push( { "basket.basket_group.name": { "like": '%'+params.basket_group+'%' } } ); + } + if (params.summary != "") { + query_and.push( { "-or": [{"biblio.title": { "like": '%'+params.summary+'%' } }, + {"biblio.author": { "like": '%'+params.summary+'%' } }, + {"biblio.isbn": { "like": '%'+params.summary+'%' } } ] } ); + } + if (params.ean != "") { + query_and.push( { "biblio.ean": params.ean } ); + } + + var query_params = []; + + if ( query_and.length > 0 ) { + query_and.push(base_query); + query_params.push('q=' + encodeURIComponent(JSON.stringify({ "-and": query_and }))); + } + + if ( params.order_id != "" ) { + query_params.push("order_id="+params.order_id); + } + + return query_params; + } + $(document).ready(function(){ if ( $("#receivedt").length ) { @@ -403,10 +436,30 @@ } var base_query = { "basket.vendor_id": [% booksellerid | html %] }; + + var summary = $("#summaryfilter").val(); + var basket_name = $("#basketfilter").val(); + var basket_group = $("#basketgroupnamefilter").val(); + var order_id = $("#orderfilter").val(); + var ean = $("#eanfilter").val(); + + var query_params = query_from_filters( + base_query, + { + "summary": summary, + "basket_name": basket_name, + "basket_group": basket_group, + "order_id": order_id, + "ean": (ean === undefined) ? '' : ean // ean == undefined if the DOM doens't have it + } + ); + + var THE_query = query_params.join("&"); + var pending_orders_url = '/api/v1/acquisitions/orders?only_active=1'; var pending_orders_table = $("#pending_orders").api({ "ajax": { - "url": pending_orders_url + '&q=' + encodeURI(JSON.stringify(base_query)) + "url": pending_orders_url + '&' + THE_query }, "header_filter": true, "embed": [ @@ -688,45 +741,32 @@ $("#filterform").on("submit", function(e) { e.preventDefault(); - // Update the datatable URL + var summary = $("#summaryfilter").val(); var basket_name = $("#basketfilter").val(); var basket_group = $("#basketgroupnamefilter").val(); var order_id = $("#orderfilter").val(); var ean = $("#eanfilter").val(); - var query_and = []; - - if (basket_name != "") { - query_and.push( { "basket.name": { "like": '%'+basket_name+'%' } } ); - } - if (basket_group != "") { - query_and.push( { "basket.basket_group.name": { "like": '%'+basket_group+'%' } } ); - } - if (summary != "") { - query_and.push( { "-or": [{"biblio.title": { "like": '%'+summary+'%' } }, - {"biblio.author": { "like": '%'+summary+'%' } }, - {"biblio.isbn": { "like": '%'+summary+'%' } } ] } ); - } - [% IF (UNIMARC) %] - if (ean != "") { - query_and.push( { "biblio.ean": ean } ); - } - [% END %] - - if ( !jQuery.isEmptyObject(query_and) || order_id != "" ) { - - var query_params = []; - - if ( order_id != "" ) { - query_params.push("order_id="+order_id); - } + // Save the filters in the cookie + $.cookie("filter_parcel_summary", summary); + $.cookie("filter_parcel_basketname", basket_name); + $.cookie("filter_parcel_orderno", basket_group); + $.cookie("filter_parcel_basketgroupname", order_id); + $.cookie("filter_parcel_ean", ean); - if ( !jQuery.isEmptyObject(query_and) ) { - query_and.push(base_query); - query_params.push('q=' + encodeURI(JSON.stringify({ "-and": query_and }))); + var query_params = query_from_filters( + base_query, + { + "summary": summary, + "basket_name": basket_name, + "basket_group": basket_group, + "order_id": order_id, + "ean": (ean === undefined) ? '' : ean // ean == undefined if the HTML doens't have it } + ); + if ( query_params.length > 0 ) { pending_orders_table.api().ajax.url( pending_orders_url + '&' + query_params.join("&") ); } else { @@ -740,21 +780,6 @@ pending_orders_table.api().ajax.url(pending_orders_url + '&q=' + encodeURI(JSON.stringify(base_query))).draw(); }); - // Keep filters from finishreceive.pl to parcel.pl - $.cookie("filter_parcel_summary", $("#summaryfilter").val()); - $.cookie("filter_parcel_basketname", $("#basketfilter").val()); - $.cookie("filter_parcel_orderno", $("#orderfilter").val()); - $.cookie("filter_parcel_basketgroupname", $("#basketgroupnamefilter").val()); - $.cookie("filter_parcel_ean", $("#eanfilter").val()); - - $("#filterform").on('submit', function(){ - $.cookie("filter_parcel_summary", $("#summaryfilter").val()); - $.cookie("filter_parcel_basketname", $("#basketfilter").val()); - $.cookie("filter_parcel_orderno", $("#orderfilter").val()); - $.cookie("filter_parcel_basketgroupname", $("#basketgroupnamefilter").val()); - $.cookie("filter_parcel_ean", $("#eanfilter").val()); - }); - $(".previewData").on("click", function(e){ e.preventDefault(); var ltitle = $(this).text(); -- 2.20.1