Merge in 5.20
[civicrm-core.git] / templates / CRM / Contribute / Form / SoftCredit.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
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 +--------------------------------------------------------------------+
9 *}
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}">
16 <td>
17 {$form.soft_credit_contact_id.$rowNumber.label}<br>{$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
18 </td>
19 <td>
20 {$form.soft_credit_amount.$rowNumber.label}<br>{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
21 </td>
22 <td>
23 {$form.soft_credit_type.$rowNumber.label}<br>
24 {$form.soft_credit_type.$rowNumber.html}
25 &nbsp;<a class="crm-hover-button soft-credit-delete-link" href="#"><span class="icon delete-icon"></span></a>
26 </td>
27 </tr>
28 {/section}
29 <tr>
30 <td>
31 <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><i class="crm-i fa-plus-circle"></i> {ts}another soft credit{/ts}</a>
32 </td>
33 </tr>
34 </table>
35
36 {literal}
37 <script type="text/javascript">
38 CRM.$(function($) {
39 var $form = $("form.{/literal}{$form.formClass}{literal}");
40 $('#showPCP, #showSoftCredit').click(function(){
41 return showHideSoftCreditAndPCP();
42 });
43
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();
48 return false;
49 }
50
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');
54 }
55 if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
56 $('#addMoreSoftCredit').hide();
57 }
58 return false;
59 });
60
61 $('.crm-soft-credit-block tr span').each(function () {
62 if ($(this).hasClass('crm-error')) {
63 $(this).parents('tr').show();
64 }
65 });
66
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();
71 return false;
72 });
73
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,''));
82 if (rowNum > 1) {
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('');
88 }
89 }
90 });
91
92 });
93 </script>
94 {/literal}