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