From 62bed82d93fdca70532ebe12c0dd4909f7c7c8df Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 3 Jun 2016 16:16:41 -0600 Subject: [PATCH] CRM-18744 - Remember quicksearch field selection --- templates/CRM/common/navigation.js.tpl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/templates/CRM/common/navigation.js.tpl b/templates/CRM/common/navigation.js.tpl index fdce48e01b..f04700e5c6 100644 --- a/templates/CRM/common/navigation.js.tpl +++ b/templates/CRM/common/navigation.js.tpl @@ -127,6 +127,7 @@ $('#civicrm-menu').ready(function() { $.Menu.closeAll(); }) .on('focus', function() { + setQuickSearchValue(); if ($(this).attr('style').indexOf('14em') < 0) { $(this).animate({width: '14em'}); } @@ -153,15 +154,29 @@ $('#civicrm-menu').ready(function() { } e.preventDefault(); }); - $('.crm-quickSearchField').click(function() { - var label = $(this).text(); - var value = $('input', this).val(); + function setQuickSearchValue() { + var $selection = $('.crm-quickSearchField input:checked'), + label = $selection.parent().text(), + value = $selection.val(); // These fields are not supported by advanced search if (value === 'first_name' || value === 'last_name') { value = 'sort_name'; } - $('#sort_name_navigation').attr({name: value, placeholder: label}).focus(); + $('#sort_name_navigation').attr({name: value, placeholder: label}); + } + $('.crm-quickSearchField').click(function() { + setQuickSearchValue(); + $('#sort_name_navigation').focus(); }); + // Set & retrieve default value + if (window.localStorage) { + $('.crm-quickSearchField').click(function() { + localStorage.quickSearchField = $('input', this).val(); + }); + if (localStorage.quickSearchField) { + $('.crm-quickSearchField input[value=' + localStorage.quickSearchField + ']').prop('checked', true); + } + } // redirect to view page if there is only one contact $('#id_search_block').on('submit', function() { var $menu = $('#sort_name_navigation').autocomplete('widget'); -- 2.25.1