alternative approach to remove snippet dependency
[civicrm-core.git] / templates / CRM / Contribute / Form / SoftCredit.tpl
CommitLineData
0baed70b 1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
0baed70b 4 +--------------------------------------------------------------------+
e7112fa7 5 | Copyright CiviCRM LLC (c) 2004-2015 |
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>
ccec9d6b 33 {$form.soft_credit_contact_id.$rowNumber.label}&nbsp;{$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
3389d6e2
KJ
34 </td>
35 <td>
36 {$form.soft_credit_amount.$rowNumber.label}&nbsp;{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
51fa20cb 37 </td>
38 <td>
ccec9d6b
CW
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>
3389d6e2
KJ
41 </td>
42 </tr>
43 {/section}
44 <tr>
81bc499e 45 <td>
52604b19 46 <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><span class="icon ui-icon-circle-plus"></span> {ts}another soft credit{/ts}</a>
0baed70b 47 </td>
48 </tr>
232624b1 49</table>
cb804cd9 50
6a490aa4
CW
51{literal}
52<script type="text/javascript">
3cc60a06 53 CRM.$(function($) {
b50fdacc 54 var $form = $("form.{/literal}{$form.formClass}{literal}");
6a490aa4
CW
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 () {
e9556dbf 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 }
6a490aa4
CW
70 if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
71 $('#addMoreSoftCredit').hide();
72 }
73 return false;
74 });
75
6a490aa4
CW
76 $('.crm-soft-credit-block tr span').each(function () {
77 if ($(this).hasClass('crm-error')) {
78 $(this).parents('tr').show();
79 }
80 });
81
ccec9d6b 82 $('.soft-credit-delete-link').click(function(){
b6545333 83 $(this).closest('tr').find('input').val('');
e9556dbf 84 $(this).closest('tr').addClass('hiddenElement').removeAttr('style');
85 $('#addMoreSoftCredit').show();
6a490aa4
CW
86 return false;
87 });
88
6d7cb3ad 89 $('input[name^="soft_credit_contact_"]').on('change', function(){
90 var rowNum = $(this).prop('id').replace('soft_credit_contact_id_','');
6a490aa4
CW
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};
6d7cb3ad 95 $('#soft_credit_type_'+ rowNum).select2('val', $('#sct_default_id').val());
6a490aa4
CW
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}