{*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
+--------------------------------------------------------------------+
*}
{* template for adding form elements for soft credit form*}
-
+{if $honor_block_is_active}
+ {crmRegion name="contribution-soft-credit-block"}
+ <legend>{$honor_block_title}</legend>
+ <div class="crm-section honor_block_text-section">
+ {$honor_block_text}
+ </div>
+ {if $form.soft_credit_type_id.html}
+ <div class="crm-section {$form.soft_credit_type_id.name}-section">
+ <div class="content" >
+ {$form.soft_credit_type_id.html}
+ <div class="description">{ts}Select an option to reveal honoree information fields.{/ts}</div>
+ </div>
+ </div>
+ {/if}
+ {/crmRegion}
+{else}
<table class="form-layout-compressed crm-soft-credit-block">
-{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 {if $rowNumber gt 1}hiddenElement{/if}">
- <td class="label">{ts}Soft Credit To{/ts}</td>
+ {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 {if $rowNumber gte $showSoftCreditRow}hiddenElement{/if}">
+ <td>
+ {$form.soft_credit_contact_id.$rowNumber.label} {$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
+ </td>
+ <td>
+ {$form.soft_credit_amount.$rowNumber.label} {$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
+ </td>
+ <td>
+ {$form.soft_credit_type.$rowNumber.label} {$form.soft_credit_type.$rowNumber.html}
+ <a class="crm-hover-button soft-credit-delete-link" href="#"><span class="icon delete-icon"></span></a>
+ </td>
+ </tr>
+ {/section}
+ <tr>
<td>
- {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true blockNo=$rowNumber
- prefix="soft_credit_"}
+ <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><span class="icon add-icon"></span> {ts}another soft credit{/ts}</a>
</td>
- <td>
- {$form.soft_credit_currency.$blockNo.html|crmAddClass:eight} {$form.soft_credit_amount.$blockNo.html|crmAddClass:eight}
- </td>
</tr>
-{/section}
- <tr>
- <td></td>
- <td>
- <a href="#" id="addMoreSoftCredit">{ts}add another soft credit{/ts}</a>
- </td>
- </tr>
-</table>
\ No newline at end of file
+</table>
+{/if}
+{literal}
+<script type="text/javascript">
+ cj(function($) {
+ $('#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;
+ }
+
+ $('#addMoreSoftCredit').on('click', function () {
+ $('.crm-contribution-form-block-soft_credit_to tr.hiddenElement').filter(':first').show().removeClass('hiddenElement');
+ if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
+ $('#addMoreSoftCredit').hide();
+ }
+ return false;
+ });
+
+ var pcpURL = CRM.url('civicrm/ajax/rest',
+ 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
+ $('#pcp_made_through').autocomplete(pcpURL,
+ { width : 360, selectFirst : false, matchContains: true
+ }).result( function(event, data, formatted) {
+ $("#pcp_made_through_id" ).val( data[1]);
+ });
+
+ $('.crm-soft-credit-block tr span').each(function () {
+ if ($(this).hasClass('crm-error')) {
+ $(this).parents('tr').show();
+ }
+ });
+
+ $('.soft-credit-delete-link').click(function(){
+ $(this).closest('tr').hide().find('input').val('').change();
+ return false;
+ });
+
+ $('input[name^="soft_credit_contact["]').change(function(){
+ var rowNum = $(this).prop('id').replace('soft_credit_contact_','');
+ var totalAmount = $('#total_amount').val();
+ //assign total amount as default soft credit amount
+ $('#soft_credit_amount_'+ rowNum).val(totalAmount);
+ var thousandMarker = {/literal}{$config->monetaryThousandSeparator|json_encode}{literal};
+ $('#soft_credit_type_'+ rowNum).val($('#sct_default_id').val());
+ totalAmount = Number(totalAmount.replace(thousandMarker,''));
+ if (rowNum > 1) {
+ var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val().replace(thousandMarker,''));
+ if (scAmount < totalAmount) {
+ //if user enters less than the total amount and adds another soft credit row,
+ //the soft credit amount default will be left empty
+ $('#soft_credit_amount_'+ rowNum).val('');
+ }
+ }
+ });
+
+ });
+</script>
+{/literal}