From 81bc499ee1813a7a6fa9b444ce568cf2470b4ec6 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Tue, 30 Apr 2013 16:24:39 -0700 Subject: [PATCH] worked on CRM-12463 restructured code and fixes --- CRM/Contribute/Form/Contribution.php | 4 + CRM/Contribute/Form/SoftCredit.php | 23 +--- .../CRM/Contribute/Form/Contribution.tpl | 69 ++++++++++-- templates/CRM/Contribute/Form/SoftCredit.js | 65 +++++++++++ templates/CRM/Contribute/Form/SoftCredit.tpl | 105 +++--------------- 5 files changed, 148 insertions(+), 118 deletions(-) create mode 100644 templates/CRM/Contribute/Form/SoftCredit.js diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 6595754045..73e539c477 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -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')); diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index 01b3c6b811..64e24cc891 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -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); diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index d3130de130..ca2cef2eaf 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -221,14 +221,67 @@ {/if} -
-
- {ts}Soft Credit{/ts} -
-
- {include file="CRM/Contribute/Form/SoftCredit.tpl"} -
-
+ +
+
+ {ts}Soft Credit{/ts} {help id="id-soft_credit"} +
+
+ + {if $siteHasPCPs} + + + + + + + + {/if} + + + +
{$form.pcp_made_through.label} + {$form.pcp_made_through.html}   + + {ts}unlink from personal campaign page{/ts} +
+ {ts}Search for the Personal Campaign Page by the fund-raiser's last name or + email address.{/ts} + +
+
+ + + + + + + + + + + + + +
{$form.pcp_display_in_roll.label}{$form.pcp_display_in_roll.html}
{$form.pcp_roll_nickname.label}{$form.pcp_roll_nickname.html|crmAddClass:big}
+ {ts}Name or nickname contributor wants to be displayed in the Honor + Roll. Enter "Anonymous" for anonymous contributions.{/ts} +
{$form.pcp_personal_note.label} + {$form.pcp_personal_note.html} + {ts}Personal message submitted by contributor for display in the Honor Roll.{/ts} +
+
+
+ {include file="CRM/Contribute/Form/SoftCredit.tpl"} +
+
+
+ {if !$contributionMode}
diff --git a/templates/CRM/Contribute/Form/SoftCredit.js b/templates/CRM/Contribute/Form/SoftCredit.js new file mode 100644 index 0000000000..4527179e0f --- /dev/null +++ b/templates/CRM/Contribute/Form/SoftCredit.js @@ -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} + + +*/ diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl index 42213b893e..df5d78b784 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.tpl +++ b/templates/CRM/Contribute/Form/SoftCredit.tpl @@ -25,97 +25,18 @@ *} {* template for adding form elements for soft credit form*} - {include file="CRM/Contact/Form/NewContact.tpl"} -{* {$form.soft_credit_to.label} - - {$form.soft_credit_to.html} {help id="id-soft_credit"} - {if $siteHasPCPs} - - {/if} + +{section name='i' start=1 loop=$rowCount} +{assign var='rowNumber' value=$smarty.section.i.index} + + + + - {if $siteHasPCPs} - - - - - {/if} -*} - {literal} - - - - - - - +{/section} +
{ts}Soft Credit To{/ts} + {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true blockNo=$rowNumber + prefix="soft_credit_"} + {$form.soft_credit_currency.$blockNo.html|crmAddClass:eight} {$form.soft_credit_amount.$blockNo.html|crmAddClass:eight} +
{$form.pcp_made_through.label} - {$form.pcp_made_through.html}   - {ts}unlink from personal campaign page{/ts}
- {ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts} -
-
- - - - - - - - - - - - -
{$form.pcp_display_in_roll.label}{$form.pcp_display_in_roll.html}
{$form.pcp_roll_nickname.label}{$form.pcp_roll_nickname.html|crmAddClass:big}
- {ts}Name or nickname contributor wants to be displayed in the Honor Roll. Enter "Anonymous" for anonymous contributions.{/ts}
{$form.pcp_personal_note.label}{$form.pcp_personal_note.html} - {ts}Personal message submitted by contributor for display in the Honor Roll.{/ts} -
-
-
\ No newline at end of file -- 2.25.1