2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
8 +--------------------------------------------------------------------+
10 {* template for adding form elements for soft credit form*}
11 <table class="form-layout-compressed crm-soft-credit-block">
12 {section name='i' start=1 loop=$rowCount}
13 {assign var='rowNumber' value=$smarty.section.i.index}
14 <tr id="soft-credit-row-{$rowNumber}"
15 class="crm-contribution-form-block-soft_credit_to {if $rowNumber gte $showSoftCreditRow}hiddenElement{/if}">
17 {$form.soft_credit_contact_id.$rowNumber.label}<br>{$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
20 {$form.soft_credit_amount.$rowNumber.label}<br>{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
23 {$form.soft_credit_type.$rowNumber.label}<br>
24 {$form.soft_credit_type.$rowNumber.html}
25 <a class="crm-hover-button soft-credit-delete-link" href="#"><span class="icon delete-icon"></span></a>
31 <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><i class="crm-i fa-plus-circle"></i> {ts}another soft credit{/ts}</a>
37 <script type="text/javascript">
39 var $form = $("form.{/literal}{$form.formClass}{literal}");
40 $('#showPCP, #showSoftCredit').click(function(){
41 return showHideSoftCreditAndPCP();
44 function showHideSoftCreditAndPCP() {
45 $('.crm-contribution-pcp-block').toggle();
46 $('.crm-contribution-pcp-block-link').toggle();
47 $('.crm-contribution-form-block-soft_credit_to').toggle();
51 $('#addMoreSoftCredit').on('click', function () {
52 if ($('tr.crm-contribution-form-block-soft_credit_to').hasClass("hiddenElement")) {
53 $('.crm-contribution-form-block-soft_credit_to tr.hiddenElement').filter(':first').show().removeClass('hiddenElement');
55 if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
56 $('#addMoreSoftCredit').hide();
61 $('.crm-soft-credit-block tr span').each(function () {
62 if ($(this).hasClass('crm-error')) {
63 $(this).parents('tr').show();
67 $('.soft-credit-delete-link').click(function(){
68 $(this).closest('tr').find('input').val('');
69 $(this).closest('tr').addClass('hiddenElement').removeAttr('style');
70 $('#addMoreSoftCredit').show();
74 $('input[name^="soft_credit_contact_"]').on('change', function(){
75 var rowNum = $(this).prop('id').replace('soft_credit_contact_id_','');
76 var totalAmount = $('#total_amount').val();
77 //assign total amount as default soft credit amount
78 $('#soft_credit_amount_'+ rowNum).val(totalAmount);
79 var thousandMarker = {/literal}{$config->monetaryThousandSeparator|json_encode}{literal};
80 $('#soft_credit_type_'+ rowNum).select2('val', $('#sct_default_id').val());
81 totalAmount = Number(totalAmount.replace(thousandMarker,''));
83 var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val().replace(thousandMarker,''));
84 if (scAmount < totalAmount) {
85 //if user enters less than the total amount and adds another soft credit row,
86 //the soft credit amount default will be left empty
87 $('#soft_credit_amount_'+ rowNum).val('');