CRM-10760 - Autocomplte - Simplify single contact check
authorColeman Watts <coleman@civicrm.org>
Thu, 30 Jan 2014 01:02:41 +0000 (17:02 -0800)
committerColeman Watts <coleman@civicrm.org>
Thu, 30 Jan 2014 19:03:23 +0000 (11:03 -0800)
CRM/Contact/Page/AJAX.php
CRM/Core/xml/Menu/Contact.xml
templates/CRM/common/Navigation.tpl

index 04730ae2ba48517d03a6714c1eb5269ba8d756b7..f41d364174131f2b8b1a0f415c4da7727b125686 100644 (file)
@@ -537,28 +537,6 @@ ORDER BY sort_name ";
     CRM_Utils_System::civiExit();
   }
 
-  /**
-   *
-   * Function to check how many contact exits in db for given criteria,
-   * if one then return contact id else null
-   */
-  static function contact() {
-    $name = CRM_Utils_Type::escape($_GET['name'], 'String');
-
-    $query = "
-SELECT id
-FROM civicrm_contact
-WHERE sort_name LIKE '%$name%'";
-
-    $dao = CRM_Core_DAO::executeQuery($query);
-    $dao->fetch();
-
-    if ($dao->N == 1) {
-      echo $dao->id;
-    }
-    CRM_Utils_System::civiExit();
-  }
-
   /**
    * Function to delete custom value
    *
index 6e965b272f8ec4dfbffd7078013e1c1f2448386d..b1eeafd832ebefe141f7a8e655bb731a0133da1a 100644 (file)
      <page_callback>CRM_Contact_Page_AJAX::groupTree</page_callback>
      <access_arguments>access CiviCRM</access_arguments>
 </item>
-<item>
-     <path>civicrm/ajax/contact</path>
-     <page_callback>CRM_Contact_Page_AJAX::contact</page_callback>
-     <access_arguments>access CiviCRM</access_arguments>
-</item>
 <item>
      <path>civicrm/ajax/custom</path>
      <page_callback>CRM_Contact_Page_AJAX::customField</page_callback>
index 4a1477148e8a815c4bc7f43d498a8a819a3ad535..4ed222dcfb71cccf18f88374257ba994aca6da5b 100644 (file)
@@ -142,26 +142,13 @@ $('#civicrm-menu').ready(function() {
     }
     $('#sort_name_navigation').attr({name: value, placeholder: label}).focus();
   });
-  // check if there is only one contact and redirect to view page
+  // redirect to view page if there is only one contact
   $('#id_search_block').on('submit', function() {
-    var contactId, sortValue = $('#sort_name_navigation').val();
-    if (sortValue && $('#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 = $.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;
-      this.action = url;
+    var $menu = $('#sort_name_navigation').crmAutocomplete('widget');
+    if ($('li.ui-menu-item', $menu).length === 1) {
+      var cid = $('li.ui-menu-item', $menu).data('ui-autocomplete-item').value;
+      document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid});
+      return false;
     }
   });
 });