Contribution Pages - Change employer from autocomplete to select
authorColeman Watts <coleman@civicrm.org>
Thu, 1 May 2014 18:40:19 +0000 (11:40 -0700)
committerColeman Watts <coleman@civicrm.org>
Thu, 1 May 2014 18:40:19 +0000 (11:40 -0700)
CRM/Contact/Page/AJAX.php
CRM/Contribute/Form/Contribution/OnBehalfOf.php
CRM/Contribute/xml/Menu/Contribute.xml
templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl

index ddc6f2907c56d24c19bdf2e0bb6f4f6bc01f31e9..90fc183330e4eb72d32dc9b6a250c7c762d264b6 100644 (file)
@@ -340,25 +340,6 @@ class CRM_Contact_Page_AJAX {
     CRM_Utils_System::civiExit();
   }
 
-  /**
-   * Function to obtain list of permissioned employer for the given contact-id.
-   */
-  static function getPermissionedEmployer() {
-    $cid  = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
-    $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
-    $name = str_replace('*', '%', $name);
-
-    $elements = CRM_Contact_BAO_Relationship::getPermissionedEmployer($cid, $name);
-
-    if (!empty($elements)) {
-      foreach ($elements as $cid => $name) {
-        echo $element = $name['name'] . "|$cid\n";
-      }
-    }
-    CRM_Utils_System::civiExit();
-  }
-
-
   static function groupTree() {
     $gids = CRM_Utils_Type::escape($_GET['gids'], 'String');
     echo CRM_Contact_BAO_GroupNestingCache::json($gids);
index 9218596500e6da168034d864c8a18881569ab834..bde03401571c15a928690a7be9390de7f40f86df 100644 (file)
@@ -84,9 +84,6 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
       if ($form->_relatedOrganizationFound) {
         $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', 'cid=', FALSE, NULL, FALSE);
         $form->assign('locDataURL', $locDataURL);
-
-        $dataURL = CRM_Utils_System::url('civicrm/ajax/employer', 'cid=' . $contactID, FALSE, NULL, FALSE);
-        $form->assign('employerDataURL', $dataURL);
       }
 
       if ($form->_values['is_for_organization'] != 2) {
@@ -125,7 +122,11 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
 
     if ($contactID && count($form->_employers) >= 1) {
       $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
-      $form->add('hidden', 'onbehalfof_id', '', array('id' => 'onbehalfof_id'));
+      $employers = array();
+      foreach ($form->_employers as $id => $vals) {
+        $employers[$id] = $vals['name'];
+      }
+      $form->add('select', 'onbehalfof_id', 'onbehalfof_id', $employers);
 
       $orgOptions = array(0 => ts('Select an existing organization'),
         1 => ts('Enter a new organization'),
index 102e4fdbbf47f002c84108531bf0915280032fba..390cd1586fb845795e902b8dc2020ef78abe0e4a 100644 (file)
     <page_callback>CRM_Core_Page_AJAX_Location::getPermissionedLocation</page_callback>
     <access_arguments>make online contributions</access_arguments>
   </item>
-  <item>
-    <path>civicrm/ajax/employer</path>
-    <page_callback>CRM_Contact_Page_AJAX::getPermissionedEmployer</page_callback>
-    <access_arguments>make online contributions</access_arguments>
-  </item>
   <item>
     <path>civicrm/contribute/unsubscribe</path>
     <title>Cancel Subscription</title>
index b6ec06bf925d6f65fc01e7c3ec07ae100625afc1..a3661bcea9c93548ae819f262b06a1906ec42cb2 100644 (file)
         {else}
           <div class="label">{$form.onbehalf.$fieldName.label}</div>
           <div class="content">
-            {$form.onbehalf.$fieldName.html}
-            {if $fieldName eq 'organization_name'}
-              <div id="id-onbehalf-orgname-help" class="description">{ts}Start typing the name of an organization that you have saved previously to use it again. Otherwise click "Enter a new organization" above.{/ts}</div>
+            {if $fieldName eq 'organization_name' and !empty($form.onbehalfof_id)}
+              {$form.onbehalfof_id.html}
             {/if}
+            {$form.onbehalf.$fieldName.html}
             {if !empty($onBehalfOfFields.$fieldName.html_type)  && $onBehalfOfFields.$fieldName.html_type eq 'Autocomplete-Select'}
               {assign var=elementName value=onbehalf[$fieldName]}
             {include file="CRM/Custom/Form/AutoComplete.tpl" element_name=$elementName}
 {if empty($snippet)}
 {literal}
 <script type="text/javascript">
-  cj( "div#id-onbehalf-orgname-help").hide( );
 
   showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
 
@@ -258,30 +257,23 @@ function setLocationDetails(contactID) {
   });
 }
 
-var orgOption = '';
 cj("input:radio[name='org_option']").click( function( ) {
-  orgOption = cj("input:radio[name='org_option']:checked").val( );
+  var orgOption = cj(this).val();
   selectCreateOrg(orgOption, true);
 });
 
+cj('#onbehalfof_id').change(function() {
+  setLocationDetails(cj(this).val());
+}).change();
+
 function selectCreateOrg( orgOption, reset ) {
   if (orgOption == 0) {
-    cj("div#id-onbehalf-orgname-help").show( );
-    var dataUrl = {/literal}"{$employerDataURL}"{literal};
-    cj('#onbehalf_organization_name').autocomplete( dataUrl,
-      { width         : 180,
-        selectFirst   : false,
-        matchContains : true,
-        max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
-      }).result( function( event, data, formatted ) {
-        cj('#onbehalf_organization_name').val( data[0] );
-        cj('#onbehalfof_id').val( data[1] );
-        setLocationDetails( data[1] );
-      });
+    cj("#onbehalfof_id").show().change();
+    cj("input#onbehalf_organization_name").hide()
   }
   else if ( orgOption == 1 ) {
-    cj("input#onbehalf_organization_name").removeClass( 'ac_input' ).unautocomplete( );
-    cj("div#id-onbehalf-orgname-help").hide( );
+    cj("input#onbehalf_organization_name").show();
+    cj("#onbehalfof_id").hide();
   }
 
   if ( reset ) {