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