worked on CRM-12463 restructured code and fixes
authorKurund Jalmi <kurund@civicrm.org>
Tue, 30 Apr 2013 23:24:39 +0000 (16:24 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Tue, 30 Apr 2013 23:24:39 +0000 (16:24 -0700)
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/SoftCredit.php
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/SoftCredit.js [new file with mode: 0644]
templates/CRM/Contribute/Form/SoftCredit.tpl

index 65957540455bbe5b8a0ece953ea17ee81691de7b..73e539c4775fec1ac7113ca2aa43b85ea4383a04 100644 (file)
@@ -150,6 +150,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
    * @access public
    */
   public function preProcess() {
+
+    $resources = CRM_Core_Resources::singleton();
+    $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js');
+
     //check permission for action.
     if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
       CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
index 01b3c6b8111fa212cd2807d4415de762d5cea91e..64e24cc891615afee721baa7cfc3e7136c64ac31 100644 (file)
@@ -48,28 +48,15 @@ class CRM_Contribute_Form_SoftCredit {
    */
   static function buildQuickForm(&$form) {
     $prefix = 'soft_credit_';
-    $form->_softCredit['item_count'] = 10;
+    $form->_softCredit['item_count'] = 5;
     for ($rowNumber = 1; $rowNumber <= $form->_softCredit['item_count']; $rowNumber++) {
       CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix);
-      $form->add('text', "{$prefix}contact[{$rowNumber}][amount]");
+      $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, TRUE,
+        "{$prefix}currency[{$rowNumber}]", NULL, TRUE);
     }
-    
-    // If we have a contact for this contribution, pass cid= to the dataUrl to exclude current contact from autocomplete results
-    if ($form->_contactID) {
-      $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest',
-        "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1&context=softcredit&cid={$form->_contactID}",
-        FALSE, NULL, FALSE
-      );
-    } 
-    else {
-      $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest',
-        'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1&context=softcredit',
-        FALSE, NULL, FALSE
-      );
-    }
-    $form->assign('dataUrl', $dataUrl);
 
-    $form->addElement('text', 'soft_credit_to', ts('Soft Credit To'));
+    $form->assign('rowCount', $form->_softCredit['item_count']);
+
     // Tell tpl to hide Soft Credit field if contribution is linked directly to a PCP Page
     if (CRM_Utils_Array::value('pcp_made_through_id', $form->_values)) {
       $form->assign('pcpLinked', 1);
index d3130de130f107e2e4a942c320ee5b7ddd5ae7b9..ca2cef2eafe74fbcffcd7c9425267cb243964d1d 100644 (file)
     {/if}
 
   </table>
-  <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="softCredit">
-    <div class="crm-accordion-header">
-      {ts}Soft Credit{/ts}
-    </div>
-    <div class="crm-accordion-body">
-      {include file="CRM/Contribute/Form/SoftCredit.tpl"}
-    </div>
-  </div>
+         <!-- start of soft credit -->
+         <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="softCredit">
+                 <div class="crm-accordion-header">
+                         {ts}Soft Credit{/ts}&nbsp;{help id="id-soft_credit"}
+                 </div>
+                 <div class="crm-accordion-body">
+                         <table class="form-layout-compressed">
+                                 {if $siteHasPCPs}
+                                         <tr class="crm-contribution-pcp-block-link">
+                                                 <td colspan="2">
+                                                         <div id="showPCP"><a
+                                                                         href='#'>{ts}credit this contribution to a personal campaign page{/ts}</a>{help id="id-link_pcp"}
+                                                         </div>
+                                                 </td>
+                                         </tr>
+                                         <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
+                                                 <td class="label">{$form.pcp_made_through.label}</td>
+                                                 <td>
+                                                         {$form.pcp_made_through.html} &nbsp;
+                                                               <span class="showSoftCreditLink">
+                                                                       <a href="#" id="showSoftCredit">{ts}unlink from personal campaign page{/ts}</a>
+                                                               </span><br/>
+                                                               <span class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or
+                                                                email address.{/ts}</span>
+
+                                                         <div class="spacer"></div>
+                                                         <div class="crm-contribution-form-block-pcp_details">
+                                                                 <table class="crm-contribution-form-table-credit_to_pcp">
+                                                                         <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll">
+                                                                                 <td class="label">{$form.pcp_display_in_roll.label}</td>
+                                                                                 <td>{$form.pcp_display_in_roll.html}</td>
+                                                                         </tr>
+                                                                         <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
+                                                                                 <td class="label">{$form.pcp_roll_nickname.label}</td>
+                                                                                 <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br/>
+                                                                                               <span class="description">{ts}Name or nickname contributor wants to be displayed in the Honor
+                                                                                       Roll. Enter "Anonymous" for anonymous contributions.{/ts}</span>
+                                                                                 </td>
+                                                                         </tr>
+                                                                         <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
+                                                                                 <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
+                                                                                 <td>
+                                                                                         {$form.pcp_personal_note.html}
+                                                                                         <span
+                                                                                                 class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</span>
+                                                                                 </td>
+                                                                         </tr>
+                                                                 </table>
+                                                         </div>
+                                                 </td>
+                                         </tr>
+                                 {/if}
+                                 <tr class="crm-contribution-form-block-soft_credit_to">
+                                         <td colspan="2">
+                                                 {include file="CRM/Contribute/Form/SoftCredit.tpl"}
+                                         </td>
+                                 </tr>
+                         </table>
+                 </div>
+         </div>
+         <!-- end of soft credit -->
     {if !$contributionMode}
     <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="paymentDetails_Information">
       <div class="crm-accordion-header">
diff --git a/templates/CRM/Contribute/Form/SoftCredit.js b/templates/CRM/Contribute/Form/SoftCredit.js
new file mode 100644 (file)
index 0000000..4527179
--- /dev/null
@@ -0,0 +1,65 @@
+// http://civicrm.org/licensing
+cj(function($) {
+  $('.crm-contribution-pcp-block').hide();
+  $('#showPCP, #showSoftCredit').click(function(){
+    return showHideSoftCreditAndPCP();
+  });
+
+  function showHideSoftCreditAndPCP() {
+    $('.crm-contribution-pcp-block').toggle();
+    $('.crm-contribution-pcp-block-link').toggle();
+    $('.crm-contribution-form-block-soft_credit_to').toggle();
+    return false;
+  }
+
+});
+/*
+ var url = "{/literal}{$dataUrl}{literal}";
+
+  cj('#soft_credit_to').autocomplete( url, { width : 180, selectFirst : false, matchContains: true
+  }).result( function(event, data, formatted) {
+      cj( "#soft_contact_id" ).val( data[1] );
+  });
+ {/literal}
+
+// load form during form rule.
+{if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
+
+{if $siteHasPCPs}
+  {literal}
+  var pcpUrl = "{/literal}{$pcpDataUrl}{literal}";
+
+  cj('#pcp_made_through').autocomplete( pcpUrl, { width : 360, selectFirst : false, matchContains: true
+  }).result( function(event, data, formatted) {
+      cj( "#pcp_made_through_id" ).val( data[1] );
+  });
+{/literal}
+
+  {if $pcpLinked}
+    {literal}hideSoftCredit( );{/literal}{* hide soft credit on load if we have PCP linkage *}
+  {else}
+    {literal}cj('#pcpID').hide();{/literal}{* hide PCP section *}
+  {/if}
+
+  {literal}
+  function hideSoftCredit ( ){
+    cj("#softCreditID").hide();
+  }
+  function showPCP( ) {
+    cj('#pcpID').show();
+    cj("#softCreditID").hide();
+  }
+  function showSoftCredit( ) {
+    cj('#pcp_made_through_id').val('');
+    cj('#pcp_made_through').val('');
+    cj('#pcp_roll_nickname').val('');
+    cj('#pcp_personal_note').val('');
+    cj('#pcp_display_in_roll').attr('checked', false);
+    cj("#pcpID").hide();
+    cj('#softCreditID').show();
+  }
+  {/literal}
+{/if}
+</script>
+
+*/
index 42213b893e0162f0b3ddffb6328ed4892b3512b2..df5d78b78400b3809baeae5d6fd0d45211559b64 100644 (file)
 *}
 {* template for adding form elements for soft credit form*}
 
-  {include file="CRM/Contact/Form/NewContact.tpl"}
-{*  <tr id="softCreditID" class="crm-contribution-form-block-soft_credit_to"><td class="label">{$form.soft_credit_to.label}</td>
-    <td {$valueStyle}>
-      {$form.soft_credit_to.html} {help id="id-soft_credit"}
-      {if $siteHasPCPs}
-        <div id="showPCPLink"><a href='#' onclick='showPCP(); return false;'>{ts}credit this contribution to a personal campaign page{/ts}</a>{help id="id-link_pcp"}</div>
-      {/if}
+<table class="form-layout-compressed">
+{section name='i' start=1 loop=$rowCount}
+{assign var='rowNumber' value=$smarty.section.i.index}
+  <tr id="soft-credit-row-{$rowNumber}" class="crm-contribution-form-block-soft_credit_to">
+    <td class="label">{ts}Soft Credit To{/ts}</td>
+    <td>
+      {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true blockNo=$rowNumber
+      prefix="soft_credit_"}
     </td>
+         <td>
+                 {$form.soft_credit_currency.$blockNo.html|crmAddClass:eight}&nbsp;{$form.soft_credit_amount.$blockNo.html|crmAddClass:eight}
+         </td>
   </tr>
-    {if $siteHasPCPs}
-    <tr id="pcpID" class="crm-contribution-form-block-pcp_made_through_id">
-      <td class="label">{$form.pcp_made_through.label}</td>
-      <td>
-        {$form.pcp_made_through.html} &nbsp;
-        <span class="showSoftCreditLink">{ts}<a href="#" onclick='showSoftCredit(); return false;'>unlink from personal campaign page</a>{/ts}</span><br />
-        <span class="description">{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}</span>
-        <div class="spacer"></div>
-        <div class="crm-contribution-form-block-pcp_details">
-          <table class="crm-contribution-form-table-credit_to_pcp">
-            <tr id="pcpDisplayRollID" class="crm-contribution-form-block-pcp_display_in_roll"><td class="label">{$form.pcp_display_in_roll.label}</td>
-              <td>{$form.pcp_display_in_roll.html}</td>
-            </tr>
-            <tr id="nickID" class="crm-contribution-form-block-pcp_roll_nickname">
-              <td class="label">{$form.pcp_roll_nickname.label}</td>
-              <td>{$form.pcp_roll_nickname.html|crmAddClass:big}<br />
-                <span class="description">{ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}</span></td>
-            </tr>
-            <tr id="personalNoteID" class="crm-contribution-form-block-pcp_personal_note">
-              <td class="label" style="vertical-align: top">{$form.pcp_personal_note.label}</td>
-              <td>{$form.pcp_personal_note.html}
-                <span class="description">{ts}Personal message submitted by contributor for display in the Honor Roll.{/ts}</span>
-              </td>
-            </tr>
-          </table>
-        </div>
-      </td>
-    </tr>
-    {/if}
-*}
- {literal}
- <script type="text/javascript">
- var url = "{/literal}{$dataUrl}{literal}";
-
-  cj('#soft_credit_to').autocomplete( url, { width : 180, selectFirst : false, matchContains: true
-  }).result( function(event, data, formatted) {
-      cj( "#soft_contact_id" ).val( data[1] );
-  });
- {/literal}
-
-// load form during form rule.
-{if $buildPriceSet}{literal}buildAmount( );{/literal}{/if}
-
-{if $siteHasPCPs}
-  {literal}
-  var pcpUrl = "{/literal}{$pcpDataUrl}{literal}";
-
-  cj('#pcp_made_through').autocomplete( pcpUrl, { width : 360, selectFirst : false, matchContains: true
-  }).result( function(event, data, formatted) {
-      cj( "#pcp_made_through_id" ).val( data[1] );
-  });
-{/literal}
-
-  {if $pcpLinked}
-    {literal}hideSoftCredit( );{/literal}{* hide soft credit on load if we have PCP linkage *}
-  {else}
-    {literal}cj('#pcpID').hide();{/literal}{* hide PCP section *}
-  {/if}
-
-  {literal}
-  function hideSoftCredit ( ){
-    cj("#softCreditID").hide();
-  }
-  function showPCP( ) {
-    cj('#pcpID').show();
-    cj("#softCreditID").hide();
-  }
-  function showSoftCredit( ) {
-    cj('#pcp_made_through_id').val('');
-    cj('#pcp_made_through').val('');
-    cj('#pcp_roll_nickname').val('');
-    cj('#pcp_personal_note').val('');
-    cj('#pcp_display_in_roll').attr('checked', false);
-    cj("#pcpID").hide();
-    cj('#softCreditID').show();
-  }
-  {/literal}
-{/if}
-</script>
-
-
-
-
-
-
+{/section}
+</table>
\ No newline at end of file