From 4162a3ca745a86018aca5c8f127a59f40ace76b7 Mon Sep 17 00:00:00 2001 From: Brendan Lawlor Date: Fri, 12 Jul 2024 16:03:57 +0000 Subject: [PATCH] Bug 14322: Add shareable link button to item search This patch adds a 'Copy shareable link' button to the item search results page. When pasted into the browser the item search form will be prefilled. The item search form submission still gets it's parameters from the form. Test plan: 1. Apply patch 2. Try some item searches (try searches using the '+ New field' button too) 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 search form is filled out exactly 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 9. Test pasting the example link below 10. With default ktd data the search will return one result for: Intermediate Perl / Schwartz, Randal L. http://localhost:8081/cgi-bin/koha/catalogue/itemsearch.pl?homebranch_op=%3D&homebranch=CPL&holdingbranch_op=%3D&holdingbranch=CPL&location_op=%3D&location=GEN&itype_op=%3D&itype=BK&ccode_op=%3D&ccode=REF¬forloan_op=!%3D¬forloan=1&itemlost_op=!%3D&itemlost=1&withdrawn_op=!%3D&withdrawn=1&damaged_op=!%3D&damaged=1&onloan=&f=publishercode&op=like&q=O'Reilly%2C&c=and&f=publicationyear&op=like&q=2006&c=and&f=title&op=not%20like&q=Javascript%20%3A&c=and&f=author&op=not%20like&q=Carlson%2C%20Lucas.&itemcallnumber_from=&itemcallnumber_to=&issues_op=%3E&issues=&datelastborrowed_op=%3E&datelastborrowed=&format=shareable Sponsored-by: CLAMS Signed-off-by: David Nind Signed-off-by: Paul Derscheid Signed-off-by: Katrin Fischer --- catalogue/itemsearch.pl | 5 +- .../prog/en/modules/catalogue/itemsearch.tt | 195 +++++++++++++----- 2 files changed, 148 insertions(+), 52 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 c0909122f4..34cdb5d2ee 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -37,30 +37,59 @@
[% END %] [% BLOCK form_field_select_option %] - + [% IF query.param('f').$i == value || query.param('f') == value %] + + [% ELSE %] + + [% END %] [% END %] [% BLOCK form_field_select_text %] + [% SET i = loop.index %]
- + [% IF loop.first || !query.param('f') %] + + [% ELSE %] + [% SET j = i - 1 %] + + [% END %] - [% IF params.exists('op') %] - - [% ELSE %] - - [% END %] - + +
[% END %] @@ -210,16 +233,34 @@ [% END %]
- + [% IF query.param('onloan') == '' %] + + [% ELSE %] + + [% END %] - + [% IF query.param('onloan') == 'IS NOT NULL' %] + + [% ELSE %] + + [% END %] - + [% IF query.param('onloan') == 'IS NULL' %] + + [% ELSE %] + + [% END %]
- [% INCLUDE form_field_select_text %] + [% IF !query.param('f') %] + [% INCLUDE form_field_select_text %] + [% ELSE %] + [% FOREACH field IN query.param('f') %] + [% INCLUDE form_field_select_text %] + [% END %] + [% END %]

You can use the following wildcard characters: % _

% matches any number of characters

_ matches only a single character

@@ -227,12 +268,12 @@
- + (inclusive)
- + (inclusive)
[% IF ( has_new_status ) %] @@ -241,21 +282,49 @@
- +
- + ISO Format (YYYY-MM-DD)
@@ -368,6 +437,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 +534,24 @@ $('#item-search-block').show(); }); + var getShareableLink = $('') + .attr('href', '#') + .html(" " + _("Copy shareable link") ) + .addClass('btn btn-secondary') + .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); + $(this).tooltip({trigger: 'manual', title: 'Copied!'}).tooltip('show'); + }); + var results_heading = $('
').addClass('results-heading') .append("

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

") .append($('

').append(advSearchLink)) @@ -458,21 +559,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.5