Merge pull request #17588 from artfulrobot/artfulrobot-property-bag-support-empty
[civicrm-core.git] / templates / CRM / Core / BillingBlock.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
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 |
8 +--------------------------------------------------------------------+
9 *}
10 {crmRegion name="billing-block"}
11 <div id="payment_information">
12 {if $paymentFields|@count}
13 <fieldset class="billing_mode-group {$paymentTypeName}_info-group">
14 <legend>
15 {$paymentTypeLabel}
16 </legend>
17 {crmRegion name="billing-block-pre"}
18 {/crmRegion}
19 <div class="crm-section billing_mode-section {$paymentTypeName}_info-section">
20 {foreach from=$paymentFields item=paymentField}
21 {assign var='name' value=$form.$paymentField.name}
22 <div class="crm-section {$form.$paymentField.name}-section">
23 <div class="label">{$form.$paymentField.label}</div>
24 <div class="content">
25 {$form.$paymentField.html}
26 {if $paymentFieldsMetadata.$name.description}
27 <div class="description">{$paymentFieldsMetadata.$name.description}</div>
28 {elseif $paymentField == 'cvv2'}{* @todo move to form assignment*}
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}
34 </div>
35 <div class="clear"></div>
36 </div>
37 {/foreach}
38 </div>
39 </fieldset>
40 {/if}
41 {if $billingDetailsFields|@count && $paymentProcessor.payment_processor_type neq 'PayPal_Express'}
42 {if $profileAddressFields && !$ccid}
43 <input type="checkbox" id="billingcheckbox" value="0">
44 <label for="billingcheckbox">{ts}My billing address is the same as above{/ts}</label>
45 {/if}
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}
50 {assign var='name' value=$form.$billingField.name}
51 <div class="crm-section {$form.$billingField.name}-section">
52 <div class="label">{$form.$billingField.label}</div>
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>
65 {if $profileAddressFields}
66 <script type="text/javascript">
67 {literal}
68
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;
75
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';
93
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 });
105
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 }
114 }
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) {
123 $('#billingcheckbox').prop('checked', true).data('crm-initial-value', true);
124 if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
125 $('.billing_name_address-group').hide();
126 }
127 }
128
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];
135
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 });
141 }
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];
147
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);
152 $(orig_id).change();
153 }
154 });
155 }
156
157 // toggle show/hide
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')) {
169 if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
170 $('.billing_name_address-group').hide(200);
171 }
172
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);
182 $(orig_id).change();
183 }
184 } else {
185 $('.billing_name_address-group').show(200);
186 }
187 }
188
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 });
196 });
197
198 </script>
199 {/literal}
200 {/if}
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}
210 {/crmRegion}
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 *}
214 {/crmRegion}