Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-09-08-20-42-29
[civicrm-core.git] / templates / CRM / Contribute / Form / Contribution / OnBehalfOf.tpl
index 76427ec8084cf495d741c02259355a062eccff12..b9181ecc6d37559725c9431269fd469cd81ba837 100644 (file)
@@ -1,8 +1,8 @@
 {*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
         {else}
           <div class="label">{$form.onbehalf.$fieldName.label}</div>
           <div class="content">
+            {if $fieldName eq 'organization_name' and !empty($form.onbehalfof_id)}
+              {$form.onbehalfof_id.html}
+            {/if}
             {$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 !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}
             {if $onBehalfOfFields.$fieldName.name|substr:0:5 eq 'phone'}
               {assign var="phone_ext_field" value=$onBehalfOfFields.$fieldName.name|replace:'phone':'phone_ext'}
               {if $form.onbehalf.$phone_ext_field.html}
                 &nbsp;{$form.onbehalf.$phone_ext_field.html}
               {/if}
+            {/if} 
+           {if $onBehalfOfFields.$fieldName.data_type eq 'Date'}
+            {assign var=elementName value=onbehalf[$fieldName]}
+              {include file="CRM/common/jcalendar.tpl" elementName=$elementName elementId=onbehalf_$fieldName}
             {/if}
             {if $onBehalfOfFields.$fieldName.help_post}
               <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
 {if empty($snippet)}
 {literal}
 <script type="text/javascript">
-  cj( "div#id-onbehalf-orgname-help").hide( );
 
   showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
 
@@ -161,22 +168,9 @@ function showOnBehalf(onBehalfRequired) {
   }
 }
 
-function resetValues( filter ) {
-  if (filter) {
-    cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) {
-      if ( cj(this).attr('name') != 'onbehalf[organization_name]' ) {
-        cj(this).val('');
-      }
-    });
-  }
-  else {
-    cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) {
-      cj(this).val( '' );
-    });
-  }
-  cj("#select_org tr td").find( 'input[type=radio], input[type=checkbox]' ).each(function( ) {
-    cj(this).prop('checked', false);
-  });
+function resetValues() {
+  cj('input[type=text], select, textarea', "#select_org div").not('#onbehalfof_id').val('');
+  cj('input[type=radio], input[type=checkbox]', "#select_org tr td").prop('checked', false);
 }
 
 function createNew( ) {
@@ -184,7 +178,8 @@ function createNew( ) {
     var textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
     cj("#onbehalf_organization_name").removeAttr('readonly');
     cj("#mode").prop('checked', false);
-    resetValues( false );
+    cj("#mode").removeAttr('checked');
+    resetValues();
   }
   else {
     var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
@@ -203,8 +198,18 @@ function setOrgName( ) {
 }
 
 
-function setLocationDetails(contactID) {
-  resetValues(true);
+function setLocationDetails(contactID , reset) {
+  var submittedCID = {/literal}"{$submittedOnBehalf}"{literal};
+  var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
+  submittedOnBehalfInfo = cj.parseJSON(submittedOnBehalfInfo);
+  if (submittedCID == contactID) {
+    cj.each(submittedOnBehalfInfo, function(key, value) {
+      cj('#onbehalf_' + key ).val(value);
+    });
+    return;
+  }
+
+  resetValues();
   var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
   cj.ajax({
     url         : locationUrl,
@@ -254,34 +259,27 @@ 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 ) {
-    resetValues( false );
+    resetValues();
   }
 }
 
@@ -297,10 +295,10 @@ function selectCreateOrg( orgOption, reset ) {
 {* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
 {if $membershipContactID}
 {literal}
-  cj( function( ) {
-    cj('#organization_id').val("{/literal}{$membershipContactName}{literal}");
-    cj('#organization_name').val("{/literal}{$membershipContactName}{literal}");
-    cj('#onbehalfof_id').val("{/literal}{$membershipContactID}{literal}");
+  CRM.$(function($) {
+    $('#organization_id').val("{/literal}{$membershipContactName}{literal}");
+    $('#organization_name').val("{/literal}{$membershipContactName}{literal}");
+    $('#onbehalfof_id').val("{/literal}{$membershipContactID}{literal}");
     setLocationDetails( "{/literal}{$membershipContactID}{literal}" );
   });
 {/literal}