Merge pull request #583 from yashodha/CRM-12463
authorKurund Jalmi <kurund@civicrm.org>
Tue, 30 Apr 2013 18:26:24 +0000 (11:26 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Tue, 30 Apr 2013 18:26:24 +0000 (11:26 -0700)
CRM-12463

CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/SoftCredit.php [new file with mode: 0644]
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/SoftCredit.tpl [new file with mode: 0644]

index b19ff6219bc803f6c22ee0db9e5715c09e889482..65957540455bbe5b8a0ece953ea17ee81691de7b 100644 (file)
@@ -842,6 +842,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       $this->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
     }
 
+    CRM_Contribute_Form_SoftCredit::buildQuickForm($this);
+    
+    /*
     // If we have a contact for this contribution, pass cid= to the dataUrl to exclude current contact from autocomplete results
     if ($this->_contactID) {
       $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest',
@@ -855,13 +858,14 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       );
     }
     $this->assign('dataUrl', $dataUrl);
+
     $this->addElement('text', 'soft_credit_to', ts('Soft Credit To'));
     // 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', $this->_values)) {
       $this->assign('pcpLinked', 1);
     }
     $this->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id'));
-
+    */
     $js = NULL;
     if (!$this->_mode) {
       $js = array('onclick' => "return verify( );");
diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php
new file mode 100644 (file)
index 0000000..dc4ffa7
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class build form elements for select exitsing or create new soft block
+ */
+class CRM_Contribute_Form_SoftCredit {
+
+  /**
+   * Function used to build form element for soft credit block
+   *
+   * @param object   $form form object
+   * @access public
+   *
+   * @return void
+   */
+  static function buildQuickForm(&$form) {
+    for ($rowNumber = 1; $rowNumber <= $form->_softCredit['item_count']; $rowNumber++) {
+      CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, TRUE, 'soft_credit_');
+    }
+
+    // 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'));
+    // 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);
+    }
+    $form->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id'));
+  }
+}
+
index 065f150c06361a55fbe7efa26f169e760996c3f1..d3130de130f107e2e4a942c320ee5b7ddd5ae7b9 100644 (file)
         </td>
       </tr>
     {/if}
-  <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}
-    </td>
-  </tr>
-    {if $siteHasPCPs}{* Credit contribution to PCP. *}
-    <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}
+
   </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>
     {if !$contributionMode}
     <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="paymentDetails_Information">
       <div class="crm-accordion-header">
 
   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}
     {if $context eq 'standalone' and $outBound_option != 2 }
       {literal}
@@ -524,42 +492,6 @@ cj(function() {
 // 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}
-
 {literal}
 function buildAmount( priceSetId ) {
   if (!priceSetId) priceSetId = cj("#price_set_id").val( );
diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl
new file mode 100644 (file)
index 0000000..27ba380
--- /dev/null
@@ -0,0 +1,119 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{* template for adding form elements for soft credit form*}
+  <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}
+    </td>
+  </tr>
+    {if $siteHasPCPs}{* Credit contribution to PCP. *}
+    <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>
+
+
+
+
+
+