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