CRM-13973 : client side behavior improvement
[civicrm-core.git] / templates / CRM / Event / Form / ParticipantFeeSelection.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 {* This template is used to change selections of fees for a participant *}
27 {literal}
28 <script type='text/javascript'>
29 function display(totalfee) {
30 // totalfee is monetary, round it to 2 decimal points so it can
31 // go as a float - CRM-13491
32 totalfee = Math.round(totalfee*100)/100;
33 // note : some variables used used here are global variables defined inside Calculate.tpl
34 var totalEventFee = formatMoney( totalfee, 2, seperator, thousandMarker);
35 cj('#pricevalue').html("<b>"+symbol+"</b> "+totalEventFee);
36 scriptfee = totalfee;
37 scriptarray = price;
38 cj('#total_amount').val(totalfee);
39 ( totalfee < 0 ) ? cj('table#pricelabel').addClass('disabled') : cj('table#pricelabel').removeClass('disabled');
40
41 // populate the balance amount div
42 // change the status selections according to updated selections
43 populatebalanceFee(totalEventFee);
44 }
45
46 function populatebalanceFee(updatedAmt) {
47 // calculate the balance amount using total paid and updated amount
48 var balanceAmt = updatedAmt - CRM.feePaid;
49 // change the status selections according to updated selections
50 if (balanceAmt > 0) {
51 cj('#status_id').val(CRM.partiallyPaid);
52 }
53 else if(balanceAmt < 0) {
54 cj('#status_id').val(CRM.pendingRefund);
55 }
56 else if(balanceAmt == 0) {
57 cj('#status_id').val(CRM.participantStatus);
58 }
59
60 balanceAmt = formatMoney(balanceAmt, 2, seperator, thousandMarker);
61 cj('#balance-fee').text(symbol+" "+balanceAmt);
62 }
63
64 cj(function(){
65 var updatedFeeUnFormatted = cj('#pricevalue').text();
66 var updatedAmt = parseFloat(updatedFeeUnFormatted.replace(/[^0-9-.]/g, ''));
67 var balanceAmt = updatedAmt - CRM.feePaid;
68
69 // change the status selections according to updated selections
70 if (balanceAmt > 0) {
71 cj('#status_id').val(CRM.partiallyPaid);
72 }
73 else if(balanceAmt < 0) {
74 cj('#status_id').val(CRM.pendingRefund);
75 }
76 });
77
78 {/literal}
79 </script>
80 <h3>Change Registration Selections</h3>
81
82 <div class="crm-block crm-form-block crm-payment-form-block">
83 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
84 {if !$email}
85 <div class="messages status no-popup">
86 <div class="icon inform-icon"></div>&nbsp;{ts}You will not be able to send an automatic email receipt for this payment because there is no email address recorded for this contact. If you want a receipt to be sent when this payment is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the payment.{/ts}
87 </div>
88 {/if}
89 <table class="form-layout">
90 <tr>
91 <td class="font-size12pt label"><strong>{ts}Participant{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
92 </tr>
93 <tr>
94 <td class='label'>{ts}Event{/ts}</td><td>{$eventName}</td>
95 </tr>
96 <tr class="crm-participant-form-block-status_id">
97 <td class="label">{$form.status_id.label}</td>
98 <td>{$form.status_id.html}</td>
99 </tr>
100 {if $lineItem}
101 <tr class="crm-event-eventfees-form-block-line_items">
102 <td class="label">{ts}Current Selections{/ts}</td>
103 <td>{include file="CRM/Price/Page/LineItem.tpl" context="Event"}</td>
104 </tr>
105 {/if}
106 </table>
107
108 {if $priceSet.fields}
109 <fieldset id="priceset" class="crm-group priceset-group">
110 <table class='form-layout'>
111 <tr class="crm-event-eventfees-form-block-price_set_amount">
112 <td class="label" style="padding-top: 10px;">{$form.amount.label}</td>
113 <td class="view-value"><table class="form-layout">{include file="CRM/Price/Form/PriceSet.tpl" extends="Event" dontInclCal="true"}</table></td>
114 </tr>
115 {if $paymentInfo}
116 <tr><td></td><td>
117 <div class='crm-section'>
118 <div class='label'>{ts}Updated Fee(s){/ts}</div><div id="pricevalue" class='content updated-fee'></div>
119 <div class='label'>{ts}Total Paid{/ts}</div>
120 <div class='content'><a class='action-item' href='{crmURL p="civicrm/payment/view" q="action=browse&cid=`$contactId`&id=`$paymentInfo.id`&component=`$paymentInfo.component`&context=transaction"}'>{$paymentInfo.paid|crmMoney}<br/>>> view payments</a>
121 </div>
122 <div class='label'><strong>{ts}Balance Owed{/ts}</strong></div><div class='content'><strong id='balance-fee'></strong></div>
123 </div>
124 {include file='CRM/Price/Form/Calculate.tpl' currencySymbol=$currencySymbol noCalcValueDisplay='false' displayOveride='true'}
125 {/if}
126 </table>
127 </fieldset>
128 {/if}
129 {if $email}
130 <fieldset id="email-receipt"><legend>{ts}Participant Confirmation{/ts}</legend>
131 <table class="form-layout" style="width:auto;">
132 <tr class="crm-event-eventfees-form-block-send_receipt">
133 <td class="label">{ts}Send Confirmation{/ts}</td>
134 <td>{$form.send_receipt.html}<br>
135 <span class="description">{ts 1=$email'}Automatically email a confirmation to %1?{/ts}</span>
136 </td>
137 </tr>
138 <tr id="from-email" class="crm-event-eventfees-form-block-from_email_address">
139 <td class="label">{$form.from_email_address.label}</td>
140 <td>{$form.from_email_address.html} {help id ="id-from_email" file="CRM/Contact/Form/Task/Email.hlp"}</td>
141 </tr>
142 <tr id='notice' class="crm-event-eventfees-form-block-receipt_text">
143 <td class="label">{$form.receipt_text.label}</td>
144 <td><span class="description">
145 {ts}Enter a message you want included at the beginning of the confirmation email. EXAMPLE: 'We have made the changes you requested to your registration.'{/ts}
146 </span><br />
147 {$form.receipt_text.html|crmAddClass:huge}
148 </td>
149 </tr>
150 </table>
151 </fieldset>
152 {/if}
153 <fieldset>
154 <table class="form-layout">
155 <tr class="crm-participant-form-block-note">
156 <td class="label">{$form.note.label}</td><td>{$form.note.html}</td>
157 </tr>
158 </table>
159 </fieldset>
160 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
161 </div>
162 {if $email}
163 {include file="CRM/common/showHideByFieldValue.tpl"
164 trigger_field_id ="send_receipt"
165 trigger_value =""
166 target_element_id ="notice"
167 target_element_type ="table-row"
168 field_type ="radio"
169 invert = 0
170 }
171 {include file="CRM/common/showHideByFieldValue.tpl"
172 trigger_field_id ="send_receipt"
173 trigger_value =""
174 target_element_id ="from-email"
175 target_element_type ="table-row"
176 field_type ="radio"
177 invert = 0
178 }
179 {/if}
180 {literal}
181 <script type='text/javascript'>
182 cj(function($){
183 cj('.total_amount-section').remove();
184
185 cj('#ParticipantFeeSelection').submit(function(e) {
186 var statusId = cj('#status_id').val();
187 var statusLabel = cj('#status_id option:selected').text();
188 var balanceFee = cj('#balance-fee').text();
189 balanceFee = parseFloat(balanceFee.replace(/[^0-9-.]/g, ''));
190
191 if (balanceFee > 0 && statusId != CRM.partiallyPaid) {
192 var result = confirm('Balance is owing for the updated selections. Expected participant status is \'Partially paid\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries.');
193 if (result == false) {
194 e.preventDefault();
195 }
196 }
197 else if (balanceFee < 0 && statusId != CRM.pendingRefund) {
198 var result = confirm('Balance is overpaid for the updated selections. Expected participant status is \'Pending refund\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries');
199 if (result == false) {
200 e.preventDefault();
201 }
202 }
203 });
204 });
205 </script>
206 {/literal}