Update copyright date for 2020
[civicrm-core.git] / templates / CRM / Contribute / Form / SoftCredit.tpl
CommitLineData
0baed70b 1{*
2 +--------------------------------------------------------------------+
fee14197 3 | CiviCRM version 5 |
0baed70b 4 +--------------------------------------------------------------------+
f299f7db 5 | Copyright CiviCRM LLC (c) 2004-2020 |
0baed70b 6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
26{* template for adding form elements for soft credit form*}
65377546 27<table class="form-layout-compressed crm-soft-credit-block">
3389d6e2
KJ
28 {section name='i' start=1 loop=$rowCount}
29 {assign var='rowNumber' value=$smarty.section.i.index}
30 <tr id="soft-credit-row-{$rowNumber}"
31 class="crm-contribution-form-block-soft_credit_to {if $rowNumber gte $showSoftCreditRow}hiddenElement{/if}">
3389d6e2 32 <td>
c67e7149 33 {$form.soft_credit_contact_id.$rowNumber.label}<br>{$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
3389d6e2
KJ
34 </td>
35 <td>
c67e7149 36 {$form.soft_credit_amount.$rowNumber.label}<br>{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
51fa20cb 37 </td>
38 <td>
c67e7149
MR
39 {$form.soft_credit_type.$rowNumber.label}<br>
40 {$form.soft_credit_type.$rowNumber.html}
ccec9d6b 41 &nbsp;<a class="crm-hover-button soft-credit-delete-link" href="#"><span class="icon delete-icon"></span></a>
3389d6e2
KJ
42 </td>
43 </tr>
44 {/section}
45 <tr>
81bc499e 46 <td>
a2c70872 47 <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><i class="crm-i fa-plus-circle"></i> {ts}another soft credit{/ts}</a>
0baed70b 48 </td>
49 </tr>
232624b1 50</table>
cb804cd9 51
6a490aa4
CW
52{literal}
53<script type="text/javascript">
3cc60a06 54 CRM.$(function($) {
b50fdacc 55 var $form = $("form.{/literal}{$form.formClass}{literal}");
6a490aa4
CW
56 $('#showPCP, #showSoftCredit').click(function(){
57 return showHideSoftCreditAndPCP();
58 });
59
60 function showHideSoftCreditAndPCP() {
61 $('.crm-contribution-pcp-block').toggle();
62 $('.crm-contribution-pcp-block-link').toggle();
63 $('.crm-contribution-form-block-soft_credit_to').toggle();
64 return false;
65 }
66
67 $('#addMoreSoftCredit').on('click', function () {
e9556dbf 68 if ($('tr.crm-contribution-form-block-soft_credit_to').hasClass("hiddenElement")) {
69 $('.crm-contribution-form-block-soft_credit_to tr.hiddenElement').filter(':first').show().removeClass('hiddenElement');
70 }
6a490aa4
CW
71 if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
72 $('#addMoreSoftCredit').hide();
73 }
74 return false;
75 });
76
6a490aa4
CW
77 $('.crm-soft-credit-block tr span').each(function () {
78 if ($(this).hasClass('crm-error')) {
79 $(this).parents('tr').show();
80 }
81 });
82
ccec9d6b 83 $('.soft-credit-delete-link').click(function(){
b6545333 84 $(this).closest('tr').find('input').val('');
e9556dbf 85 $(this).closest('tr').addClass('hiddenElement').removeAttr('style');
86 $('#addMoreSoftCredit').show();
6a490aa4
CW
87 return false;
88 });
89
6d7cb3ad 90 $('input[name^="soft_credit_contact_"]').on('change', function(){
91 var rowNum = $(this).prop('id').replace('soft_credit_contact_id_','');
6a490aa4
CW
92 var totalAmount = $('#total_amount').val();
93 //assign total amount as default soft credit amount
94 $('#soft_credit_amount_'+ rowNum).val(totalAmount);
95 var thousandMarker = {/literal}{$config->monetaryThousandSeparator|json_encode}{literal};
6d7cb3ad 96 $('#soft_credit_type_'+ rowNum).select2('val', $('#sct_default_id').val());
6a490aa4
CW
97 totalAmount = Number(totalAmount.replace(thousandMarker,''));
98 if (rowNum > 1) {
99 var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val().replace(thousandMarker,''));
100 if (scAmount < totalAmount) {
101 //if user enters less than the total amount and adds another soft credit row,
102 //the soft credit amount default will be left empty
103 $('#soft_credit_amount_'+ rowNum).val('');
104 }
105 }
106 });
107
108 });
109</script>
110{/literal}