Set version to 5.20.beta1
[civicrm-core.git] / templates / CRM / Contribute / Form / SoftCredit.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2019 |
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*}
27 <table class="form-layout-compressed crm-soft-credit-block">
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}">
32 <td>
33 {$form.soft_credit_contact_id.$rowNumber.label}<br>{$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
34 </td>
35 <td>
36 {$form.soft_credit_amount.$rowNumber.label}<br>{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
37 </td>
38 <td>
39 {$form.soft_credit_type.$rowNumber.label}<br>
40 {$form.soft_credit_type.$rowNumber.html}
41 &nbsp;<a class="crm-hover-button soft-credit-delete-link" href="#"><span class="icon delete-icon"></span></a>
42 </td>
43 </tr>
44 {/section}
45 <tr>
46 <td>
47 <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><i class="crm-i fa-plus-circle"></i> {ts}another soft credit{/ts}</a>
48 </td>
49 </tr>
50 </table>
51
52 {literal}
53 <script type="text/javascript">
54 CRM.$(function($) {
55 var $form = $("form.{/literal}{$form.formClass}{literal}");
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 () {
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 }
71 if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
72 $('#addMoreSoftCredit').hide();
73 }
74 return false;
75 });
76
77 $('.crm-soft-credit-block tr span').each(function () {
78 if ($(this).hasClass('crm-error')) {
79 $(this).parents('tr').show();
80 }
81 });
82
83 $('.soft-credit-delete-link').click(function(){
84 $(this).closest('tr').find('input').val('');
85 $(this).closest('tr').addClass('hiddenElement').removeAttr('style');
86 $('#addMoreSoftCredit').show();
87 return false;
88 });
89
90 $('input[name^="soft_credit_contact_"]').on('change', function(){
91 var rowNum = $(this).prop('id').replace('soft_credit_contact_id_','');
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};
96 $('#soft_credit_type_'+ rowNum).select2('val', $('#sct_default_id').val());
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}