Ian province abbreviation patch - issue 724
[civicrm-core.git] / templates / CRM / Core / BillingBlock.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
6a488035 4 +--------------------------------------------------------------------+
e7112fa7 5 | Copyright CiviCRM LLC (c) 2004-2015 |
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>
92ec1d7f
EM
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}
6a488035 49 </div>
dc3560bc
EM
50 <div class="clear"></div>
51 </div>
92ec1d7f 52 {/foreach}
dc3560bc 53 </div>
c78d6d60 54 </fieldset>
dc913073 55 {if $billingDetailsFields|@count}
c78d6d60
EM
56 {if $profileAddressFields}
57 <input type="checkbox" id="billingcheckbox" value="0">
58 <label for="billingcheckbox">{ts}My billing address is the same as above{/ts}</label>
dc3560bc 59 {/if}
c78d6d60
EM
60 <fieldset class="billing_name_address-group">
61 <legend>{ts}Billing Name and Address{/ts}</legend>
62 <div class="crm-section billing_name_address-section">
63 {foreach from=$billingDetailsFields item=billingField}
9d421118 64 {assign var='name' value=$form.$billingField.name}
c78d6d60 65 <div class="crm-section {$form.$billingField.name}-section">
9d421118 66 <div class="label">{$form.$billingField.label}
67 {if $requiredPaymentFields.$name}<span class="crm-marker" title="{ts}This field is required.{/ts}">*</span>{/if}
68 </div>
c78d6d60
EM
69 {if $form.$billingField.type == 'text'}
70 <div class="content">{$form.$billingField.html}</div>
71 {else}
72 <div class="content">{$form.$billingField.html|crmAddClass:big}</div>
73 {/if}
74 <div class="clear"></div>
75 </div>
76 {/foreach}
77 </div>
78 </fieldset>
79 {/if}
1bcfa58f 80{/if}
c78d6d60 81</div>
dc3560bc
EM
82{if $profileAddressFields}
83 <script type="text/javascript">
84 {literal}
8ae4d0d3 85
dc3560bc
EM
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;
6a488035 92
dc3560bc
EM
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';
6a488035 110
dc3560bc
EM
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 });
6a488035 122
dc3560bc
EM
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 }
6a488035 131 }
dc3560bc
EM
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) {
cce5bc84 140 $('#billingcheckbox').prop('checked', true).data('crm-initial-value', true);
ab2e3179 141 if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
dc3560bc
EM
142 $('.billing_name_address-group').hide();
143 }
6a488035 144 }
6a488035 145
dc3560bc
EM
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];
6a488035 152
dc3560bc
EM
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 });
ae8f569f 158 }
dc3560bc
EM
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];
6a488035 164
dc3560bc
EM
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);
dc3560bc
EM
169 $(orig_id).change();
170 }
171 });
6a488035 172 }
6a488035
TO
173
174
dc3560bc
EM
175 // toggle show/hide
176 $('#billingcheckbox').click(function () {
177 if (this.checked) {
ab2e3179 178 if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
dc3560bc
EM
179 $('.billing_name_address-group').hide(200);
180 }
6a488035 181
dc3560bc
EM
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);
84466477 191 $(orig_id).change();
dc3560bc
EM
192 }
193 } else {
194 $('.billing_name_address-group').show(200);
195 }
196 });
6a488035 197
dc3560bc
EM
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 });
1ba4a3aa 206
31d31a05
EM
207 $('input[name="payment_processor_id"]').change( function() {
208 function toggleConfirmButton() {
209 var suppressSubmitButton = {/literal}"{$suppressSubmitButton}"{literal};
210 var elementObj = $('input[name="payment_processor"]');
211 if ( elementObj.attr('type') == 'hidden' ) {
212 var processorTypeId = elementObj.val( );
213 }
214 else {
215 var processorTypeId = elementObj.filter(':checked').val();
216 }
1ba4a3aa 217
31d31a05
EM
218 if (suppressSubmitButton) {
219 $("#crm-submit-buttons").hide();
220 }
221 else {
222 $("#crm-submit-buttons").show();
223 }
1ba4a3aa 224 }
1ba4a3aa
EM
225 toggleConfirmButton();
226 });
227
dc3560bc 228 </script>
31d31a05 229 {/literal}
6a488035 230{/if}
6a488035 231{/crmRegion}
dbbd55dc
EM
232{crmRegion name="billing-block-post"}
233 {* Payment processors sometimes need to append something to the end of the billing block. We create a region for
234 clarity - the plan is to move to assigning this through the payment processor to this region *}
dbbd55dc 235{/crmRegion}
aaff4c69 236