From 1185267abb2680a2baf9a5ad80cd50383690a1ed Mon Sep 17 00:00:00 2001 From: Katlyn Beck Date: Wed, 30 Jan 2019 18:11:47 +0000 Subject: [PATCH] CAT-200 Remember last search template used - When selected, the template name is saved to localStorage. - When the page is loaded or refreshed, the template is retrieved and populated from localStorage based on stored name. Signed-off-by: Katlyn Beck Changes to be committed: modified: Open-ILS/web/js/ui/kcls/conify/global/config/search_templates.js --- .../kcls/conify/global/config/search_templates.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Open-ILS/web/js/ui/kcls/conify/global/config/search_templates.js b/Open-ILS/web/js/ui/kcls/conify/global/config/search_templates.js index 99e1a231a6..6a2ca43200 100644 --- a/Open-ILS/web/js/ui/kcls/conify/global/config/search_templates.js +++ b/Open-ILS/web/js/ui/kcls/conify/global/config/search_templates.js @@ -46,6 +46,7 @@ function getXULSearchStash() { function templateActionSave() { var nameInput = document.getElementById('nameInput').value; create_template(nameInput); + templateSelected(); } // Removes template from templateList and localStorage if it exists and if user wants it deleted @@ -300,6 +301,46 @@ function clearSearchFilters() { } } +// Adds "selected" attribute to chosen template from list +function templateSelected() { + var templateSelector = document.getElementById('templateList'); + var templateOptions = templateSelector.getElementsByTagName('option'); + for (var i = 0; i < templateOptions.length; i++) { + if (!templateOptions[i].selected) { + templateOptions[i].removeAttribute('selected'); + } + if (templateOptions[i].value == templateSelector.value) { + templateOptions[i].setAttribute('selected', ''); + var selectedTemplate = templateOptions[i].value; + window.localStorage.setItem('eg.catalog.staff.search_templates.last_used', selectedTemplate); + } + } +} + +// Retrieves and populates selected template from localStorage +function retrieveSelectedTemplate() { + var selectedTemplate = window.localStorage.getItem('eg.catalog.staff.search_templates.last_used'); + var templateList = JSON.parse(window.localStorage.getItem('eg.catalog.staff.search_templates')); + var templateSelector = document.getElementById('templateList'); + var templateOptions = templateSelector.getElementsByTagName('option'); + + for (var i = 0; i < templateList.length; i++) { + if (templateList[i].name == selectedTemplate) { + populateSearchOptions(templateList[i]); + } + } + // ensures template stays selected on reload + for (var j = 0; j < templateOptions.length; j++) { + if (templateOptions[j].value == selectedTemplate) { + templateOptions[j].setAttribute('selected', ''); + } + } +} + +window.onload = function () { + retrieveSelectedTemplate(); +} + //Given a template name, saves template as the current search template if name found in TemplateList //Populates options, or not, accordingly function selectSearchTemplateOrClear(tName) { @@ -320,6 +361,7 @@ function selectSearchTemplateOrClear(tName) { function selectSearchTemplateOrClearAll(tName) { selectSearchTemplateOrClear(tName); populateTemplateNameValue(tName); + templateSelected(); clearGlobalRowInputs(); clearPubDateInputs(); } -- 2.11.0