From 261dc1e247b215079973a400e0587c922a74bddc Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 17 Jan 2020 10:17:42 +0100 Subject: [PATCH] Bug 18433: Remember item search results selected rows in session storage Session storage is not shared between browser tabs, and is cleared when a tab is closed, so it seems like a good fit for storing selected rows Test plan: 1. Go to item search (intranet) and submit the form 2. Select some rows on the first page by clicking on checkboxes 3. Go to another page of results 4. Select more rows 5. Go back to the first page 6. Selected rows should still be checked 7. Play with sorting and filtering, and see that selected rows are always checked 8. Export as CSV and as a barcodes file, verify that the export contains all selected rows 9. Click on 'Clear selection', it should deselect all rows from all pages 10. Select some rows again 11. Click on 'Edit search' and submit the same search 12. No row should be selected 13. Select some rows again 14. Refresh the page and submit again the same search 15. No row should be selected Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- .../prog/en/modules/catalogue/itemsearch.tt | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) 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 a9ad87d0c5..578639af2e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -315,14 +315,22 @@ $('#item-search-block').show(); }); + function getCheckedItemnumbers () { + var itemnumbers; + try { + itemnumbers = JSON.parse(sessionStorage.getItem('itemsearch_itemnumbers') || '[]'); + } catch (e) { + itemnumbers = []; + } + + return new Set(itemnumbers); + } + function exportItems(format) { - var itemnumbers = []; - $('#results').find('input[name="itemnumber"]:checked').each(function() { - itemnumbers.push($(this).val()); - }); - if (itemnumbers.length) { + var itemnumbers = getCheckedItemnumbers(); + if (itemnumbers.size > 0) { var href = '/cgi-bin/koha/catalogue/item-export.pl?format=' + format; - href += '&itemnumber=' + itemnumbers.join('&itemnumber='); + href += '&itemnumber=' + Array.from(itemnumbers).join('&itemnumber='); location = href; } else { $('#format-' + format).prop('checked', true); @@ -374,6 +382,7 @@ .append(_("Clear selection")) .on('click', function(e) { e.preventDefault(); + sessionStorage.setItem('itemsearch_itemnumbers', '[]'); $('#results input[type="checkbox"]').prop('checked', false).change(); }); var exportLinks = $('

') @@ -491,11 +500,30 @@ null ] }); + $('#results').on('draw.dt', function (e, settings) { + var itemnumbers = getCheckedItemnumbers(); + $(this).find('input[type="checkbox"][name="itemnumber"]').each(function () { + var itemnumber = this.value; + if (itemnumbers.has(itemnumber)) { + this.checked = true; + } + }); + }); + + sessionStorage.setItem('itemsearch_itemnumbers', '[]'); $('#results').on('change', 'input[type="checkbox"]', function() { - var countSelected = $(this).parents('table').find('input:checked').length; + var itemnumber = this.value; + var itemnumbers = getCheckedItemnumbers(); + if (this.checked) { + itemnumbers.add(itemnumber); + } else { + itemnumbers.delete(itemnumber); + } + sessionStorage.setItem('itemsearch_itemnumbers', JSON.stringify(Array.from(itemnumbers))); + var caret = ' '; - if (countSelected > 0) { + if (itemnumbers.size > 0) { $('#export-button').html(_("Export selected results to") + caret); } else { $('#export-button').html(_("Export all results to") + caret); -- 2.39.5