From 0814609f7bc60a9295911c88eeffc1a24c8f4930 Mon Sep 17 00:00:00 2001 From: Brendan Lawlor Date: Tue, 16 Apr 2024 20:18:10 +0000 Subject: [PATCH] Bug 14322: Add button to copy link to an item search This work in progress patch adds a button to copy a url with all the parameters for an item search. The button currently works to copy a url with all the item search parameters url encoded, but the url returns 500. To make it work itemsearch.pl needs some updates to handle when the url parameter format=shareable, then it should handle authentication process all the prameters from the url. It would be really cool to also parameterize the state of the data table so the link could go straight to a filtered sorted result. Test plan: 1. Apply patch 2. Do an item search 3. On the results page see a new 'Copy shareable link' button 4. Click the button and confirm that you can paste a url with all parameters from the form url encoded 5. Paste the url in the browser and notice you get a 500 error :( --- catalogue/itemsearch.pl | 2 + .../prog/en/modules/catalogue/itemsearch.tt | 43 ++++++++++++++----- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index bd25081c0d..d32faa550d 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!?!? } elsif (defined $format) { die "Unsupported format $format"; } 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..88e53477a7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -368,6 +368,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 +465,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.href + '?' + $.param(params); + navigator.clipboard.writeText(url); + }); + var results_heading = $('
').addClass('results-heading') .append("

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

") .append($('

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