Merge pull request #12569 from civicrm/5.4
[civicrm-core.git] / templates / CRM / Core / BillingBlock.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
fee14197 3 | CiviCRM version 5 |
6a488035 4 +--------------------------------------------------------------------+
8c9251b3 5 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
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{crmRegion name="billing-block"}
c78d6d60 27<div id="payment_information">
3cc8d80d 28 {if $paymentFields|@count}
fbfd63ec 29 <fieldset class="billing_mode-group {$paymentTypeName}_info-group">
dc3560bc 30 <legend>
fbfd63ec 31 {$paymentTypeLabel}
dc3560bc 32 </legend>
aaff4c69 33 {crmRegion name="billing-block-pre"}
aaff4c69 34 {/crmRegion}
92ec1d7f
EM
35 <div class="crm-section billing_mode-section {$paymentTypeName}_info-section">
36 {foreach from=$paymentFields item=paymentField}
9d421118 37 {assign var='name' value=$form.$paymentField.name}
92ec1d7f 38 <div class="crm-section {$form.$paymentField.name}-section">
9d421118 39 <div class="label">{$form.$paymentField.label}
40 {if $requiredPaymentFields.$name}<span class="crm-marker" title="{ts}This field is required.{/ts}">*</span>{/if}
41 </div>
8cdd6191 42 <div class="content">
43 {$form.$paymentField.html}
92ec1d7f
EM
44 {if $paymentField == 'cvv2'}{* @todo move to form assignment*}
45 <span class="cvv2-icon" title="{ts}Usually the last 3-4 digits in the signature area on the back of the card.{/ts}"> </span>
46 {/if}
47 {if $paymentField == 'credit_card_type'}
48 <div class="crm-credit_card_type-icons"></div>
49 {/if}
6a488035 50 </div>
dc3560bc
EM
51 <div class="clear"></div>
52 </div>
92ec1d7f 53 {/foreach}
dc3560bc 54 </div>
c78d6d60 55 </fieldset>
caec10c8 56 {/if}
b5eab107 57 {if $billingDetailsFields|@count && $paymentProcessor.payment_processor_type neq 'PayPal_Express'}
37e877b2 58 {if $profileAddressFields && !$ccid}
c78d6d60
EM
59 <input type="checkbox" id="billingcheckbox" value="0">
60 <label for="billingcheckbox">{ts}My billing address is the same as above{/ts}</label>
dc3560bc 61 {/if}
c78d6d60
EM
62 <fieldset class="billing_name_address-group">
63 <legend>{ts}Billing Name and Address{/ts}</legend>
64 <div class="crm-section billing_name_address-section">
65 {foreach from=$billingDetailsFields item=billingField}
9d421118 66 {assign var='name' value=$form.$billingField.name}
c78d6d60 67 <div class="crm-section {$form.$billingField.name}-section">
9d421118 68 <div class="label">{$form.$billingField.label}
69 {if $requiredPaymentFields.$name}<span class="crm-marker" title="{ts}This field is required.{/ts}">*</span>{/if}
70 </div>
c78d6d60
EM
71 {if $form.$billingField.type == 'text'}
72 <div class="content">{$form.$billingField.html}</div>
73 {else}
74 <div class="content">{$form.$billingField.html|crmAddClass:big}</div>
75 {/if}
76 <div class="clear"></div>
77 </div>
78 {/foreach}
79 </div>
80 </fieldset>
81 {/if}
82</div>
dc3560bc
EM
83{if $profileAddressFields}
84 <script type="text/javascript">
85 {literal}
8ae4d0d3 86
dc3560bc
EM
87 CRM.$(function ($) {
88 // build list of ids to track changes on
89 var address_fields = {/literal}{$profileAddressFields|@json_encode}{literal};
90 var input_ids = {};
91 var select_ids = {};
92 var orig_id, field, field_name;
6a488035 93
dc3560bc
EM
94 // build input ids
95 $('.billing_name_address-section input').each(function (i) {
96 orig_id = $(this).attr('id');
97 field = orig_id.split('-');
98 field_name = field[0].replace('billing_', '');
99 if (field[1]) {
100 if (address_fields[field_name]) {
101 input_ids['#' + field_name + '-' + address_fields[field_name]] = '#' + orig_id;
102 }
103 }
104 });
105 if ($('#first_name').length)
106 input_ids['#first_name'] = '#billing_first_name';
107 if ($('#middle_name').length)
108 input_ids['#middle_name'] = '#billing_middle_name';
109 if ($('#last_name').length)
110 input_ids['#last_name'] = '#billing_last_name';
6a488035 111
dc3560bc
EM
112 // build select ids
113 $('.billing_name_address-section select').each(function (i) {
114 orig_id = $(this).attr('id');
115 field = orig_id.split('-');
116 field_name = field[0].replace('billing_', '').replace('_id', '');
117 if (field[1]) {
118 if (address_fields[field_name]) {
119 select_ids['#' + field_name + '-' + address_fields[field_name]] = '#' + orig_id;
120 }
121 }
122 });
6a488035 123
dc3560bc
EM
124 // detect if billing checkbox should default to checked
125 var checked = true;
126 for (var id in input_ids) {
127 orig_id = input_ids[id];
128 if ($(id).val() != $(orig_id).val()) {
129 checked = false;
130 break;
131 }
6a488035 132 }
dc3560bc
EM
133 for (var id in select_ids) {
134 orig_id = select_ids[id];
135 if ($(id).val() != $(orig_id).val()) {
136 checked = false;
137 break;
138 }
139 }
140 if (checked) {
cce5bc84 141 $('#billingcheckbox').prop('checked', true).data('crm-initial-value', true);
ab2e3179 142 if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
dc3560bc
EM
143 $('.billing_name_address-group').hide();
144 }
6a488035 145 }
6a488035 146
dc3560bc
EM
147 // onchange handlers for non-billing fields
148 for (var id in input_ids) {
149 orig_id = input_ids[id];
150 $(id).change(function () {
151 var id = '#' + $(this).attr('id');
152 var orig_id = input_ids[id];
6a488035 153
dc3560bc
EM
154 // if billing checkbox is active, copy other field into billing field
155 if ($('#billingcheckbox').prop('checked')) {
156 $(orig_id).val($(id).val());
157 }
158 });
ae8f569f 159 }
dc3560bc
EM
160 for (var id in select_ids) {
161 orig_id = select_ids[id];
162 $(id).change(function () {
163 var id = '#' + $(this).attr('id');
164 var orig_id = select_ids[id];
6a488035 165
dc3560bc
EM
166 // if billing checkbox is active, copy other field into billing field
167 if ($('#billingcheckbox').prop('checked')) {
168 $(orig_id + ' option').prop('selected', false);
169 $(orig_id + ' option[value="' + $(id).val() + '"]').prop('selected', true);
dc3560bc
EM
170 $(orig_id).change();
171 }
172 });
6a488035 173 }
6a488035
TO
174
175
dc3560bc
EM
176 // toggle show/hide
177 $('#billingcheckbox').click(function () {
178 if (this.checked) {
ab2e3179 179 if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
dc3560bc
EM
180 $('.billing_name_address-group').hide(200);
181 }
6a488035 182
dc3560bc
EM
183 // copy all values
184 for (var id in input_ids) {
185 orig_id = input_ids[id];
186 $(orig_id).val($(id).val());
187 }
188 for (var id in select_ids) {
189 orig_id = select_ids[id];
190 $(orig_id + ' option').prop('selected', false);
191 $(orig_id + ' option[value="' + $(id).val() + '"]').prop('selected', true);
84466477 192 $(orig_id).change();
dc3560bc
EM
193 }
194 } else {
195 $('.billing_name_address-group').show(200);
196 }
197 });
6a488035 198
dc3560bc
EM
199 // remove spaces, dashes from credit card number
200 $('#credit_card_number').change(function () {
201 var cc = $('#credit_card_number').val()
202 .replace(/ /g, '')
203 .replace(/-/g, '');
204 $('#credit_card_number').val(cc);
205 });
1ba4a3aa
EM
206 });
207
dc3560bc 208 </script>
31d31a05 209 {/literal}
6a488035 210{/if}
079e7379
CW
211{if $suppressSubmitButton}
212{literal}
213 <script type="text/javascript">
214 CRM.$(function($) {
215 $('.crm-submit-buttons', $('#billing-payment-block').closest('form')).hide();
216 });
217 </script>
218{/literal}
219{/if}
6a488035 220{/crmRegion}
dbbd55dc
EM
221{crmRegion name="billing-block-post"}
222 {* Payment processors sometimes need to append something to the end of the billing block. We create a region for
223 clarity - the plan is to move to assigning this through the payment processor to this region *}
dbbd55dc 224{/crmRegion}