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