CRM-13966 - Refactor autocomplete from financial acct form
authorColeman Watts <coleman@civicrm.org>
Tue, 25 Feb 2014 15:53:31 +0000 (10:53 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 25 Feb 2014 15:54:26 +0000 (10:54 -0500)
CRM/Financial/Form/FinancialAccount.php
templates/CRM/Financial/Form/FinancialAccount.tpl

index 84d60c285f71806586b2f1067a36d5fe4d0fa736..923f0e0d3e9fc11c86d62f0c6c936fa5a011b27d 100644 (file)
@@ -87,9 +87,6 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
    */
   public function buildQuickForm( ) {
     parent::buildQuickForm( );
-    $dataURL = CRM_Utils_System::url('civicrm/ajax/rest',
-      'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1', FALSE, NULL, FALSE);
-    $this->assign('dataURL', $dataURL);
 
     if ($this->_action & CRM_Core_Action::DELETE) {
       return;
@@ -104,8 +101,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     $this->add('text', 'description', ts('Description'), $attributes['description']);
     $this->add('text', 'accounting_code', ts('Accounting Code'), $attributes['accounting_code']);
     $elementAccounting = $this->add('text', 'account_type_code', ts('Account Type Code'), $attributes['account_type_code']);
-    $this->add('text', 'contact_name', ts('Owner'), $attributes['name']);
-    $this->add('hidden', 'contact_id', '', array('id' => 'contact_id'));
+    $this->addEntityRef('contact_id', ts('Owner'), array('api' => array('params' => array('contact_type' => 'Organization')), 'create' => TRUE));
     $this->add('text', 'tax_rate', ts('Tax Rate'), $attributes['tax_rate']);
     $this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'));
     $elementActive = $this->add('checkbox', 'is_active', ts('Enabled?'));
@@ -166,7 +162,6 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     $defaults = parent::setDefaultValues();
     if ($this->_action & CRM_Core_Action::ADD) {
       $defaults['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'contact_id');
-      $defaults['contact_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $defaults['contact_id'], 'sort_name');
     }
     return $defaults;
   }
@@ -196,5 +191,3 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
     }
   }
 }
-
-
index 1defdc6d69b40019ba89c0b33194c2b8d68a9024..e4d06183a9fcd5c00c46231d7c477fb1cb8f3419 100644 (file)
@@ -43,8 +43,8 @@
       <td class="html-adjust">{$form.description.html}</td>
     </tr>
     <tr class="crm-contribution-form-block-organisation_name">
-      <td class="label">{$form.contact_name.label}&nbsp;{help id="id-financial-owner" file="CRM/Contact/Form/Contact.hlp"}</td>
-      <td class="html-adjust">{$form.contact_name.html|crmReplace:class:twenty}<br />
+      <td class="label">{$form.contact_id.label}&nbsp;{help id="id-financial-owner" file="CRM/Contact/Form/Contact.hlp"}</td>
+      <td class="html-adjust">{$form.contact_id.html}<br />
         <span class="description">{ts}Use this field to indicate the organization that owns this account.{/ts}</span>
       </td>
     </tr>
 {/if}
   <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="botttom"}</div>
 </div>
-
-{literal}
-<script type="text/javascript">
-var dataUrl        = "{/literal}{$dataURL}{literal}";
-cj('#contact_name').autocomplete( dataUrl, {
-  width        : 250,
-  selectFirst  : false,
-  matchCase    : true,
-  matchContains: true,
-  max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
-}).result( function(event, data, formatted) {
-  ( parseInt( data[1] ) ) ? cj( "#contact_id" ).val( data[1] ) : cj( "#contact_id" ).val('');
-});
-
-// remove current account owner id when current owner removed.
-cj("form").submit(function() {
-  if (!cj('#contact_name').val()) cj( "#contact_id" ).val('');
-});
-
-//current employer default setting
-var employerId = "{/literal}{$organisationId}{literal}";
-if ( employerId ) {
-  var dataUrl = "{/literal}{crmURL p='civicrm/ajax/rest' h=0 q="className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&id=" }{literal}" + employerId ;
-  cj.ajax({
-    url     : dataUrl,
-    async   : false,
-    success : function(html){
-      //fixme for showing address in div
-      htmlText = html.split( '|' , 2);
-      cj('input#contact_name').val(htmlText[0]);
-      cj('input#contact_id').val(htmlText[1]);
-    }
-  });
-}
-
-cj("input#contact_name").click( function( ) {
-  cj("input#contact_id").val('');
-});
-</script>
-{/literal}