From e0f7ceee5cb64c5e02caf9fcdcd6c59d9f6500a2 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 21 Mar 2013 16:50:03 -0700 Subject: [PATCH] Fix quicksearch redirect --- templates/CRM/common/Navigation.tpl | 54 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/templates/CRM/common/Navigation.tpl b/templates/CRM/common/Navigation.tpl index 6276100513..5d1f678828 100644 --- a/templates/CRM/common/Navigation.tpl +++ b/templates/CRM/common/Navigation.tpl @@ -25,9 +25,9 @@ *} @@ -97,31 +96,30 @@ cj(function( ) { } cj('#sort_name_navigation').attr({name: value, placeholder: label}).flushCache().focus(); }); -}); -function getSearchURLValue( ) -{ - var input = cj('#sort_name_navigation').val(); - var contactId = cj( '#sort_contact_id' ).val(); - if ( ! contactId || isNaN( contactId ) ) { - var sortValue = cj( '#sort_name_navigation' ).val(); - if ( sortValue ) { - //using xmlhttprequest check if there is only one contact and redirect to view page - var dataUrl = {/literal}"{crmURL p='civicrm/ajax/contact' h=0 q='name='}"{literal} + sortValue; - - var response = cj.ajax({ - url: dataUrl, - async: false - }).responseText; - - contactId = response; - } + // check if there is only one contact and redirect to view page + cj('#id_search_block').on('submit', function() { + var contactId, sortValue = cj('#sort_name_navigation').val(); + if (sortValue && cj('#sort_name_navigation').attr('name') == 'sort_name') { + {/literal}{* + // FIXME: async:false == bad, + // we should just check the autocomplete results instead of firing a new request + // when we fix this, the civicrm/ajax/contact server-side callback can be removed as well + // also that would fix the fact that this only works with sort_name search + // (and we can remove the above conditional) + *}{literal} + var dataUrl = {/literal}"{crmURL p='civicrm/ajax/contact' h=0 q='name='}"{literal} + sortValue; + contactId = cj.ajax({ + url: dataUrl, + async: false + }).responseText; } - - if ( contactId && !isNaN(parseInt(contactId)) ) { - var url = {/literal}"{crmURL p='civicrm/contact/view' h=0 q='reset=1&cid='}"{literal} + contactId; - document.getElementById('id_search_block').action = url; + if (contactId && !isNaN(parseInt(contactId))) { + var url = {/literal}"{crmURL p='civicrm/contact/view' h=0 q='reset=1&cid='}"{literal} + contactId; + this.action = url; } -} + }); +}); + {/literal}{if $config->userFramework neq 'Joomla'}{literal} cj('body').prepend( cj("#menu-container").html() ); -- 2.25.1