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 cc4d7711287230c6c3ec78bb85cb4f306293f59a..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.                                    |
  |                                                                    |
               {if $form.onbehalf.$phone_ext_field.html}
                  {$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>
   showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
 
   cj( "#mode" ).hide( );
-  cj( "#mode" ).attr( 'checked', 'checked' );
-  if ( cj( "#mode" ).attr( 'checked' ) && !{/literal}"{$reset}"{literal} ) {
+  cj( "#mode" ).prop('checked', true );
+  if ( cj( "#mode" ).prop('checked' ) && !{/literal}"{$reset}"{literal} ) {
     $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
     cj( "#createNewOrg" ).text( $text );
-    cj( "#mode" ).removeAttr( 'checked' );
+    cj( "#mode" ).prop('checked', false );
   }
 
 function showOnBehalf(onBehalfRequired) {
-  if ( cj( "#is_for_organization" ).attr( 'checked' ) || onBehalfRequired ) {
+  if ( cj( "#is_for_organization" ).prop( 'checked' ) || onBehalfRequired ) {
     var urlPath = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&onbehalf=1&id=$contributionPageID&qfKey=$qfKey"}";
     {if $mode eq 'test'}
       urlPath += '&action=preview';
@@ -170,15 +174,16 @@ function resetValues() {
 }
 
 function createNew( ) {
-  if (cj("#mode").attr('checked')) {
+  if (cj("#mode").prop('checked')) {
     var textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
     cj("#onbehalf_organization_name").removeAttr('readonly');
+    cj("#mode").prop('checked', false);
     cj("#mode").removeAttr('checked');
     resetValues();
   }
   else {
     var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
-    cj("#mode").attr('checked', 'checked');
+    cj("#mode").prop('checked', true);
     setOrgName( );
   }
   cj("#createNewOrg").text(textMessage);
@@ -193,7 +198,17 @@ function setOrgName( ) {
 }
 
 
-function setLocationDetails(contactID) {
+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({
@@ -204,17 +219,17 @@ function setLocationDetails(contactID) {
       for (var ele in data) {
         if (data[ele].type == 'Radio') {
           if (data[ele].value) {
-            cj("input[name='"+ ele +"']").filter("[value=" + data[ele].value + "]").attr('checked', 'checked');
+            cj("input[name='"+ ele +"']").filter("[value=" + data[ele].value + "]").prop('checked', true);
           }
         }
         else if (data[ele].type == 'CheckBox') {
           if (data[ele].value) {
-            cj("input[name='"+ ele +"']").attr('checked','checked');
+            cj("input[name='"+ ele +"']").prop('checked','checked');
           }
         }
         else if (data[ele].type == 'Multi-Select') {
           for (var selectedOption in data[ele].value) {
-            cj('#' + ele + " option[value='" + selectedOption + "']").attr('selected', 'selected');
+            cj('#' + ele + " option[value='" + selectedOption + "']").prop('selected', true);
           }
         }
         else if (data[ele].type == 'Autocomplete-Select') {
@@ -256,7 +271,7 @@ cj('#onbehalfof_id').change(function() {
 function selectCreateOrg( orgOption, reset ) {
   if (orgOption == 0) {
     cj("#onbehalfof_id").show().change();
-    cj("input#onbehalf_organization_name").hide()
+    cj("input#onbehalf_organization_name").hide();
   }
   else if ( orgOption == 1 ) {
     cj("input#onbehalf_organization_name").show();
@@ -280,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}