07dce25d87f8cae8c7da4f37c6ea63b66b55b276
[civicrm-core.git] / templates / CRM / Contribute / Form / SoftCredit.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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}&nbsp;{$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
34 </td>
35 <td>
36 {$form.soft_credit_amount.$rowNumber.label}&nbsp;{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
37 </td>
38 <td>
39 {$form.soft_credit_type.$rowNumber.label}&nbsp;{$form.soft_credit_type.$rowNumber.html}
40 &nbsp;<a class="crm-hover-button soft-credit-delete-link" href="#"><span class="icon delete-icon"></span></a>
41 </td>
42 </tr>
43 {/section}
44 <tr>
45 <td>
46 <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><i class="crm-i fa-plus-circle"></i> {ts}another soft credit{/ts}</a>
47 </td>
48 </tr>
49 </table>
50
51 {literal}
52 <script type="text/javascript">
53 CRM.$(function($) {
54 var $form = $("form.{/literal}{$form.formClass}{literal}");
55 $('#showPCP, #showSoftCredit').click(function(){
56 return showHideSoftCreditAndPCP();
57 });
58
59 function showHideSoftCreditAndPCP() {
60 $('.crm-contribution-pcp-block').toggle();
61 $('.crm-contribution-pcp-block-link').toggle();
62 $('.crm-contribution-form-block-soft_credit_to').toggle();
63 return false;
64 }
65
66 $('#addMoreSoftCredit').on('click', function () {
67 if ($('tr.crm-contribution-form-block-soft_credit_to').hasClass("hiddenElement")) {
68 $('.crm-contribution-form-block-soft_credit_to tr.hiddenElement').filter(':first').show().removeClass('hiddenElement');
69 }
70 if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
71 $('#addMoreSoftCredit').hide();
72 }
73 return false;
74 });
75
76 $('.crm-soft-credit-block tr span').each(function () {
77 if ($(this).hasClass('crm-error')) {
78 $(this).parents('tr').show();
79 }
80 });
81
82 $('.soft-credit-delete-link').click(function(){
83 $(this).closest('tr').find('input').val('');
84 $(this).closest('tr').addClass('hiddenElement').removeAttr('style');
85 $('#addMoreSoftCredit').show();
86 return false;
87 });
88
89 $('input[name^="soft_credit_contact_"]').on('change', function(){
90 var rowNum = $(this).prop('id').replace('soft_credit_contact_id_','');
91 var totalAmount = $('#total_amount').val();
92 //assign total amount as default soft credit amount
93 $('#soft_credit_amount_'+ rowNum).val(totalAmount);
94 var thousandMarker = {/literal}{$config->monetaryThousandSeparator|json_encode}{literal};
95 $('#soft_credit_type_'+ rowNum).select2('val', $('#sct_default_id').val());
96 totalAmount = Number(totalAmount.replace(thousandMarker,''));
97 if (rowNum > 1) {
98 var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val().replace(thousandMarker,''));
99 if (scAmount < totalAmount) {
100 //if user enters less than the total amount and adds another soft credit row,
101 //the soft credit amount default will be left empty
102 $('#soft_credit_amount_'+ rowNum).val('');
103 }
104 }
105 });
106
107 });
108 </script>
109 {/literal}