From f2cdcd590149681a9fe3bfcc94beafb0b02694b4 Mon Sep 17 00:00:00 2001 From: Brendan Lawlor Date: Tue, 16 Apr 2024 20:18:10 +0000 Subject: [PATCH] Bug 14322: Add shareable link button to item search This work in progress patch add a 'Copy shareable link' button to the item search results page. If you paste the link in the browser the item search form will be prefilled. Currently this works for all fields on the item search page except for fields added by the user with the '+ New field button' Test plan: 1. Apply patch 2. Try some item searches (except for ones using the '+ New field' button) 3. On the results page click the 'Copy shareable link' button 4. Paste the link into the browser and hit enter 5. Notice the item searhc form is filled out as you did earlier 6. Click 'Search' and confirm the results are as you would expect 7. Click 'Edit search', modify the search and search again 8. Test the 'Copy shareable link' button again TODO: add support for fields added with the '+ New field' button --- catalogue/itemsearch.pl | 5 +- .../prog/en/modules/catalogue/itemsearch.tt | 124 +++++++++++------- 2 files changed, 82 insertions(+), 47 deletions(-) diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index bd25081c0d..a8134712f4 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -90,6 +90,8 @@ if (defined $format and $format eq 'json') { } elsif (defined $format and $format eq 'barcodes') { # Retrieve all results $cgi->param('rows', 0); +} elsif (defined $format and $format eq 'shareable') { + # get the item search parameters from the url and fill form } elsif (defined $format) { die "Unsupported format $format"; } @@ -119,7 +121,7 @@ if ( Koha::MarcSubfieldStructures->search( { frameworkcode => '', kohafield => ' $template->param( has_new_status => 1 ); } -if ( defined $format ) { +if ( defined $format and $format ne 'shareable') { # Parameters given, it's a search my $filter = { @@ -351,6 +353,7 @@ $template->param( damageds => \@damageds, items_search_fields => \@items_search_fields, authorised_values_json => to_json($authorised_values), + query => $cgi, ); output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt index 59b4c9225a..28cb854563 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -37,22 +37,37 @@
[% END %] [% BLOCK form_field_select_option %] - + [% IF query.param('f').grep(value).0 == value %] + + [% ELSE %] + + [% END %] [% END %] [% BLOCK form_field_select_text %] @@ -84,22 +99,16 @@ [% END %] - [% IF params.exists('op') %] - - [% ELSE %] - - [% END %] - + + [% END %] @@ -210,11 +219,11 @@ [% END %]
- + - + - +
@@ -227,12 +236,12 @@
- + (inclusive)
- + (inclusive)
[% IF ( has_new_status ) %] @@ -241,21 +250,21 @@
- +
- + ISO Format (YYYY-MM-DD)
@@ -368,6 +377,20 @@ } } + function getParams($form) { + var params = []; + $form.find('select:not(:disabled) option:selected,input[type="text"]:not(:disabled),input[type="hidden"]:not(:disabled),input[type="radio"]:checked').each(function() { + if ( $(this).prop('tagName').toLowerCase() == 'option' ) { + var name = $(this).parents('select').first().attr('name'); + var value = $(this).val(); + params.push({ 'name': name, 'value': value }); + } else { + params.push({ 'name': $(this).attr('name'), 'value': $(this).val() }); + } + }); + return params; + } + function submitForm($form) { var tr = '' + ' ' @@ -451,6 +474,23 @@ $('#item-search-block').show(); }); + var getShareableLink = $('') + .attr('href', '#') + .html(" " + _("Copy shareable link") ) + .addClass('btn btn-default') + .on('click', function(e) { + e.preventDefault(); + var params = getParams( $('#itemsearchform') ); + params = params.map(p => { + if(p.name === 'format') { + return { ...p, value: 'shareable' }; + } + return p; + }) + var url = window.location.origin + window.location.pathname + '?' + $.param(params); + navigator.clipboard.writeText(url); + }); + var results_heading = $('
').addClass('results-heading') .append("

" + _("Item search results") + "

") .append($('

').append(advSearchLink)) @@ -458,21 +498,13 @@ .addClass("btn-toolbar") .attr("id","toolbar") .append(editSearchLink) + .append(getShareableLink) ); $('#results-wrapper').empty() .append(results_heading) .append(table); - var params = []; - $form.find('select:not(:disabled) option:selected,input[type="text"]:not(:disabled),input[type="hidden"]:not(:disabled),input[type="radio"]:checked').each(function() { - if ( $(this).prop('tagName').toLowerCase() == 'option' ) { - var name = $(this).parents('select').first().attr('name'); - var value = $(this).val(); - params.push({ 'name': name, 'value': value }); - } else { - params.push({ 'name': $(this).attr('name'), 'value': $(this).val() }); - } - }); + var params = getParams($form); $('#results').dataTable($.extend(true, {}, dataTablesDefaults, { "destroy": true, -- 2.39.2