CRM-16260 - Fix use of ts() within templates
[civicrm-core.git] / templates / CRM / Member / Form / Membership.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 {* this template is used for adding/editing/deleting memberships for a contact *}
27 {if $cancelAutoRenew}
28 <div class="messages status no-popup">
29 <div class="icon inform-icon"></div>
30 <p>{ts 1=$cancelAutoRenew}This membership is set to renew automatically {if $endDate}on {$endDate|crmDate}{/if}. You will need to cancel the auto-renew option if you want to modify the Membership Type, End Date or Membership Status. <a href="%1">Click here</a> if you want to cancel the automatic renewal option.{/ts}</p>
31 </div>
32 {/if}
33 <div class="spacer"></div>
34 {if $cdType }
35 {include file="CRM/Custom/Form/CustomData.tpl"}
36 {elseif $priceSetId}
37 {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Membership"}
38 {literal}
39 <script type="text/javascript">
40 CRM.$(function($) {
41 var membershipValues = [];
42 {/literal}{foreach from=$optionsMembershipTypes item=memType key=opId}{literal}
43 membershipValues[{/literal}{$opId}{literal}] = {/literal}{$memType}{literal};
44 {/literal}{/foreach}{literal}
45 processMembershipPriceset(membershipValues, {/literal}{$autoRenewOption}{literal}, 1);
46 {/literal}{if !$membershipMode}{literal}
47 enableAmountSection({/literal}{$contributionType}{literal});
48 {/literal}{/if}{literal}
49 });
50 </script>
51 {/literal}
52 {else}
53 {if $membershipMode == 'test' }
54 {assign var=registerMode value="TEST"}
55 {elseif $membershipMode == 'live'}
56 {assign var=registerMode value="LIVE"}
57 {/if}
58 {if !$emailExists and $action neq 8 and $context neq 'standalone'}
59 <div class="messages status no-popup">
60 <div class="icon inform-icon"></div>
61 <p>{ts}You will not be able to send an automatic email receipt for this Membership because there is no email address recorded for this contact. If you want a receipt to be sent when this Membership is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the Membership.{/ts}</p>
62 </div>
63 {/if}
64 {if $membershipMode}
65 <div id="help">
66 {ts 1=$displayName 2=$registerMode}Use this form to submit Membership Record on behalf of %1. <strong>A %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
67 </div>
68 {/if}
69 <div class="crm-block crm-form-block crm-membership-form-block">
70 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
71 {if $action eq 8}
72 <div class="messages status no-popup">
73 <div class="icon inform-icon"></div>&nbsp;
74 <span class="font-red bold">{ts}WARNING: Deleting this membership will also delete any related payment (contribution) records.{/ts} {ts}This action cannot be undone.{/ts}</span>
75 <p>{ts}Consider modifying the membership status instead if you want to maintain an audit trail and avoid losing payment data. You can set the status to Cancelled by editing the membership and clicking the Status Override checkbox.{/ts}</p>
76 <p>{ts}Click 'Delete' if you want to continue.{/ts}</p>
77 </div>
78 {else}
79 <table class="form-layout-compressed">
80 {if $context neq 'standalone'}
81 <tr>
82 <td class="font-size12pt label"><strong>{ts}Member{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
83 </tr>
84 {else}
85 <td class="label">{$form.contact_id.label}</td>
86 <td>{$form.contact_id.html}</td>
87 {/if}
88 {if $membershipMode}
89 <tr><td class="label">{$form.payment_processor_id.label}</td><td>{$form.payment_processor_id.html}</td></tr>
90 {/if}
91 <tr class="crm-membership-form-block-membership_type_id">
92 <td class="label">{$form.membership_type_id.label}</td>
93 <td><span id='mem_type_id'>{$form.membership_type_id.html}</span>
94 {if $hasPriceSets}
95 <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
96 <span id='selectPriceSet'>{$form.price_set_id.html}</span>
97 {if $buildPriceSet && $priceSet}
98 <div id="priceset"><br/>{include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"}</div>
99 {else}
100 <div id="priceset" class="hiddenElement"></div>
101 {/if}
102 {/if}
103 {if $member_is_test} {ts}(test){/ts}{/if}<br />
104 <span class="description">{ts}Select Membership Organization and then Membership Type.{/ts}{if $hasPriceSets} {ts}Alternatively, you can use a price set.{/ts}{/if}</span>
105 </td>
106 </tr>
107 <tr id="maxRelated" class="crm-membership-form-block-max_related">
108 <td class="label">{$form.max_related.label}</td>
109 <td>{$form.max_related.html}<br />
110 <span class="description">{ts}Maximum number of related memberships (leave blank for unlimited).{/ts}</span>
111 </td>
112 </tr>
113 {if $action eq 1}
114 <tr id="num_terms_row" class="crm-membership-form-block-num_terms">
115 <td class="label">{$form.num_terms.label}</td>
116 <td>&nbsp;{$form.num_terms.html}<br />
117 <span class="description">{ts}Set the membership end date this many membership periods from now. Make sure the appropriate corresponding fee is entered below.{/ts}</span>
118 </td>
119 </tr>
120 {/if}
121 <tr class="crm-membership-form-block-source">
122 <td class="label">{$form.source.label}</td>
123 <td>&nbsp;{$form.source.html}<br />
124 <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td>
125 </tr>
126
127 {* CRM-7362 --add campaign to membership *}
128 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
129 campaignTrClass="crm-membership-form-block-campaign_id"}
130
131 <tr class="crm-membership-form-block-join_date"><td class="label">{$form.join_date.label}</td><td>{include file="CRM/common/jcalendar.tpl" elementName=join_date}
132 <br />
133 <span class="description">{ts}When did this contact first become a member?{/ts}</span></td></tr>
134 <tr class="crm-membership-form-block-start_date"><td class="label">{$form.start_date.label}</td><td>{include file="CRM/common/jcalendar.tpl" elementName=start_date}
135 <br />
136 <span class="description">{ts}First day of current continuous membership period. Start Date will be automatically set based on Membership Type if you don't select a date.{/ts}</span></td></tr>
137 <tr class="crm-membership-form-block-end_date"><td class="label">{$form.end_date.label}</td>
138 <td id="end-date-readonly">
139 {$endDate|crmDate}
140 <a href="#" class="crm-hover-button action-item override-date" id="show-end-date">
141 {ts}Over-ride end date{/ts}
142 </a>
143 {help id="override_end_date"}
144 </td>
145 <td id="end-date-editable">
146 {include file="CRM/common/jcalendar.tpl" elementName=end_date}
147 <br />
148 <span class="description">{ts}Latest membership period expiration date. End Date will be automatically set based on Membership Type if you don't select a date.{/ts}</span>
149 </td>
150 </tr>
151 {if !empty($form.auto_renew)}
152 <tr id="autoRenew" class="crm-membership-form-block-auto_renew">
153 <td class="label"> {$form.auto_renew.label} {help id="id-auto_renew" file="CRM/Member/Form/Membership.hlp" action=$action} </td>
154 <td> {$form.auto_renew.html} </td>
155 </tr>
156 {/if}
157 {if !$membershipMode}
158 <tr><td class="label">{$form.is_override.label} {help id="id-status-override"}</td><td>{$form.is_override.html}</td></tr>
159 {/if}
160
161 {if ! $membershipMode}
162 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
163 <tr id="memberStatus_show">
164 {if $action eq 2}
165 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
166 {/if}
167 </tr>
168
169 {* Show editable status field when is_override is TRUE *}
170 <tr id="memberStatus"><td class="label">{$form.status_id.label}</td><td>{$form.status_id.html}<br />
171 <span class="description">{ts}If <strong>Status Override</strong> is checked, the selected status will remain in force (it will NOT be modified by the automated status update script).{/ts}</span></td></tr>
172
173 {elseif $membershipMode}
174 <tr class="crm-membership-form-block-financial_type_id-mode">
175 <td class="label">{$form.financial_type_id.label}</td>
176 <td>{$form.financial_type_id.html}<br />
177 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
178 </tr>
179 <tr class="crm-membership-form-block-total_amount">
180 <td class="label">{$form.total_amount.label}</td>
181 <td>{$form.total_amount.html}<br />
182 <span class="description">{ts}Membership payment amount.{/ts}</span><div class="totaltaxAmount"></div></td>
183 </tr>
184 <tr class="crm-membership-form-block-contribution-contact">
185 <td class="label">{$form.is_different_contribution_contact.label}</td>
186 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
187 </tr>
188 <tr id="record-different-contact">
189 <td>&nbsp;</td>
190 <td>
191 <table class="compressed">
192 <tr class="crm-membership-form-block-soft-credit-type">
193 {*CRM-15366*}
194 <td class="label">{$form.soft_credit_type_id.label}</td>
195 <td>{$form.soft_credit_type_id.html}</td>
196 </tr>
197 <tr class="crm-membership-form-block-soft-credit-contact-id">
198 <td class="label">{$form.soft_credit_contact_id.label}</td>
199 <td>{$form.soft_credit_contact_id.html}</td>
200 </tr>
201 </table>
202 </td>
203 </tr>
204 <tr class="crm-membership-form-block-billing">
205 <td colspan="2">
206 {include file='CRM/Core/BillingBlock.tpl'}
207 </td>
208 </tr>
209 {/if}
210 {if $accessContribution and ! $membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
211 <tr id="contri">
212 <td class="label">{if $onlinePendingContributionId}{ts}Update Payment Status{/ts}{else}{$form.record_contribution.label}{/if}</td>
213 <td>{$form.record_contribution.html}<br />
214 <span class="description">{ts}Check this box to enter or update payment information. You will also be able to generate a customized receipt.{/ts}</span></td>
215 </tr>
216 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
217 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
218 <table>
219 <tr class="crm-membership-form-block-contribution-contact">
220 <td class="label">{$form.is_different_contribution_contact.label}</td>
221 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
222 </tr>
223 <tr id="record-different-contact">
224 <td>&nbsp;</td>
225 <td>
226 <table class="compressed">
227 <tr class="crm-membership-form-block-soft-credit-type">
228 <td class="label">{$form.soft_credit_type_id.label}</td>
229 <td>{$form.soft_credit_type_id.html}</td>
230 </tr>
231 <tr class="crm-membership-form-block-soft-credit-contact-id">
232 <td class="label">{$form.soft_credit_contact_id.label}</td>
233 <td>{$form.soft_credit_contact_id.html}</td>
234 </tr>
235 </table>
236 </td>
237 </tr>
238 <tr class="crm-membership-form-block-financial_type_id">
239 <td class="label">{$form.financial_type_id.label}</td>
240 <td>{$form.financial_type_id.html}<br />
241 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
242 </tr>
243 <tr class="crm-membership-form-block-total_amount">
244 <td class="label">{$form.total_amount.label}</td>
245 <td>{$form.total_amount.html}<br />
246 <span class="description">{ts}Membership payment amount. A contribution record will be created for this amount.{/ts}</span><div class="totaltaxAmount"></div></td>
247 </tr>
248 <tr class="crm-membership-form-block-receive_date">
249 <td class="label">{$form.receive_date.label}</td>
250 <td>{include file="CRM/common/jcalendar.tpl" elementName=receive_date}</td>
251 </tr>
252 <tr class="crm-membership-form-block-payment_instrument_id">
253 <td class="label">{$form.payment_instrument_id.label}<span class="marker"> *</span></td>
254 <td>{$form.payment_instrument_id.html} {help id="payment_instrument_id" file="CRM/Contribute/Page/Tab.hlp"}</td>
255 </tr>
256 <tr id="checkNumber" class="crm-membership-form-block-check_number">
257 <td class="label">{$form.check_number.label}</td>
258 <td>{$form.check_number.html|crmAddClass:six}</td>
259 </tr>
260 {if $action neq 2 }
261 <tr class="crm-membership-form-block-trxn_id">
262 <td class="label">{$form.trxn_id.label}</td>
263 <td>{$form.trxn_id.html}</td>
264 </tr>
265 {/if}
266 <tr class="crm-membership-form-block-contribution_status_id">
267 <td class="label">{$form.contribution_status_id.label}</td>
268 <td>{$form.contribution_status_id.html}</td>
269 </tr>
270 </table>
271 </fieldset>
272 </td></tr>
273 {else}
274 <div class="spacer"></div>
275 {/if}
276
277 {if $emailExists and $outBound_option != 2 }
278 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
279 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
280 <span class="description">{ts 1=$emailExists}Automatically email a membership confirmation and receipt to %1?{/ts}</span></td>
281 </tr>
282 {elseif $context eq 'standalone' and $outBound_option != 2 }
283 <tr id="email-receipt" style="display:none;">
284 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
285 <span class="description">{ts}Automatically email a membership confirmation and receipt to {/ts}<span id="email-address"></span>?</span></td>
286 </tr>
287 {/if}
288 <tr id="fromEmail" style="display:none;">
289 <td class="label">{$form.from_email_address.label}</td>
290 <td>{$form.from_email_address.html}</td>
291 </tr>
292 <tr id='notice' style="display:none;">
293 <td class="label">{$form.receipt_text_signup.label}</td>
294 <td class="html-adjust"><span class="description">{ts}If you need to include a special message for this member, enter it here. Otherwise, the confirmation email will include the standard receipt message configured under System Message Templates.{/ts}</span>
295 {$form.receipt_text_signup.html|crmAddClass:huge}</td>
296 </tr>
297 </table>
298 <div id="customData"></div>
299 {*include custom data js file*}
300 {include file="CRM/common/customData.tpl"}
301 {literal}
302 <script type="text/javascript">
303 CRM.$(function($) {
304 {/literal}
305 CRM.buildCustomData( '{$customDataType}' );
306 {if $customDataSubType}
307 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
308 {/if}
309 {literal}
310 });
311 </script>
312 {/literal}
313 {if $accessContribution and $action eq 2 and $rows.0.contribution_id}
314 <div class="crm-accordion-wrapper">
315 <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div>
316 <div class="crm-accordion-body">{include file="CRM/Contribute/Form/Selector.tpl" context="Search"}</div>
317 </div>
318 {/if}
319 {if $softCredit}
320 <div class="crm-accordion-wrapper">
321 <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div>
322 <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div>
323 </div>
324 {/if}
325 {/if}
326
327 <div class="spacer"></div>
328 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
329 </div> <!-- end form-block -->
330
331 {if $action neq 8} {* Jscript additions not need for Delete action *}
332 {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)}
333
334 {include file="CRM/common/showHideByFieldValue.tpl"
335 trigger_field_id ="record_contribution"
336 trigger_value =""
337 target_element_id ="recordContribution"
338 target_element_type ="table-row"
339 field_type ="radio"
340 invert = 0
341 }
342 {include file="CRM/common/showHideByFieldValue.tpl"
343 trigger_field_id ="payment_instrument_id"
344 trigger_value = '4'
345 target_element_id ="checkNumber"
346 target_element_type ="table-row"
347 field_type ="select"
348 invert = 0
349 }
350 {/if}
351
352 {literal}
353 <script type="text/javascript">
354 function setPaymentBlock(mode, checkboxEvent) {
355 var memType = parseInt(cj('#membership_type_id_1').val( ));
356 var isPriceSet = 0;
357
358 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
359 isPriceSet = 1;
360 }
361
362 if ( !memType || isPriceSet ) {
363 return;
364 }
365
366 var allMemberships = {/literal}{$allMembershipInfo}{literal};
367 if ( !mode ) {
368 //check the record_contribution checkbox if membership is a paid one
369 {/literal}{if $action eq 1}{literal}
370 if (!checkboxEvent) {
371 if (allMemberships[memType]['total_amount_numeric'] > 0) {
372 cj('#record_contribution').prop('checked','checked');
373 cj('#recordContribution').show();
374 }
375 else {
376 cj('#record_contribution').prop('checked', false);
377 cj('#recordContribution').hide();
378 }
379 }
380 {/literal}{/if}{literal}
381 }
382
383 // skip this for test and live modes because financial type is set automatically
384 cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']);
385 var term = cj('#num_terms').val();
386 var taxRates = '{/literal}{$taxRates}{literal}';
387 var taxTerm = '{/literal}{$taxTerm}{literal}';
388 var taxRates = JSON.parse(taxRates);
389 var taxRate = taxRates[allMemberships[memType]['financial_type_id']];
390 var currency = '{/literal}{$currency}{literal}';
391 var taxAmount = (taxRate/100)*allMemberships[memType]['total_amount_numeric'];
392 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
393 if ( term ) {
394 if (!taxRate) {
395 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
396 }
397 else {
398 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number(allMemberships[memType]['total_amount_numeric'] * term );
399 }
400 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
401 }
402 else {
403 if (taxRate) {
404 var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
405 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
406 }
407 else {
408 var feeTotal = allMemberships[memType]['total_amount'];
409 cj("#total_amount").val( allMemberships[memType]['total_amount'] );
410 }
411 }
412 var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
413 cj('.totaltaxAmount').html(taxMessage);
414 }
415
416
417 CRM.$(function($) {
418 var mode = {/literal}'{$membershipMode}'{literal};
419 if ( !mode ) {
420 // Offline form (mode = false) has the record_contribution checkbox
421 cj('#record_contribution').click( function( ) {
422 if ( cj(this).prop('checked') ) {
423 cj('#recordContribution').show( );
424 setPaymentBlock( false, true);
425 }
426 else {
427 cj('#recordContribution').hide( );
428 }
429 });
430 }
431
432 cj('#membership_type_id_1').change( function( ) {
433 setPaymentBlock(mode);
434 });
435 cj('#num_terms').change( function( ) {
436 setPaymentBlock(mode);
437 });
438 setPaymentBlock(mode);
439
440 // show/hide different contact section
441 setDifferentContactBlock();
442 cj('#is_different_contribution_contact').change( function() {
443 setDifferentContactBlock();
444 });
445
446 // give option to override end-date for auto-renew memberships
447 {/literal}
448 {if $isRecur && $endDate}
449 cj('#end-date-readonly').show();
450 cj('#end-date-editable').hide();
451 {else}
452 cj('#end-date-readonly').hide();
453 cj('#end-date-editable').show();
454 {/if}
455 {literal}
456
457 cj('#show-end-date').click( function( e ) {
458 e.preventDefault();
459 cj('#end-date-readonly').hide();
460 cj('#end-date-editable').show();
461 });
462
463 });
464
465 function setDifferentContactBlock( ) {
466 // show/hide different contact section
467 if ( cj('#is_different_contribution_contact').prop('checked') ) {
468 cj('#record-different-contact').show();
469 }
470 else {
471 cj('#record-different-contact').hide();
472 }
473 }
474
475 </script>
476 {/literal}
477
478 {if ($emailExists and $outBound_option != 2) OR $context eq 'standalone' }
479 {include file="CRM/common/showHideByFieldValue.tpl"
480 trigger_field_id ="send_receipt"
481 trigger_value =""
482 target_element_id ="notice"
483 target_element_type ="table-row"
484 field_type ="radio"
485 invert = 0
486 }
487 {include file="CRM/common/showHideByFieldValue.tpl"
488 trigger_field_id ="send_receipt"
489 trigger_value =""
490 target_element_id ="fromEmail"
491 target_element_type ="table-row"
492 field_type ="radio"
493 invert = 0
494 }
495 {/if}
496 {literal}
497
498 <script type="text/javascript">
499
500 {/literal}{if !$membershipMode}{literal}
501 showHideMemberStatus();
502 function showHideMemberStatus() {
503 if ( cj( "#is_override" ).prop('checked' ) ) {
504 cj('#memberStatus').show( );
505 cj('#memberStatus_show').hide( );
506 }
507 else {
508 cj('#memberStatus').hide( );
509 cj('#memberStatus_show').show( );
510 }
511 }
512 {/literal}{/if}
513
514 {if $context eq 'standalone' and $outBound_option != 2 }
515 {literal}
516 CRM.$(function($) {
517 var $form = $("form.{/literal}{$form.formClass}{literal}");
518 $("#contact_id", $form).change(checkEmail);
519 checkEmail( );
520
521 function checkEmail( ) {
522 var data = $("#contact_id", $form).select2('data');
523 if (data && data.extra && data.extra.email && data.extra.email.length) {
524 $("#email-receipt", $form).show();
525 if ($("#send_receipt", $form).is(':checked')) {
526 $("#notice", $form).show();
527 }
528 $("#email-address", $form).html(data.extra.email);
529 }
530 else {
531 $("#email-receipt, #notice", $form).hide();
532 }
533 }
534 });
535
536 {/literal}
537 {/if}
538
539 {literal}
540 //keep read only always checked.
541 CRM.$(function($) {
542 var $form = $("form.{/literal}{$form.formClass}{literal}");
543 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
544 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
545 if ( allowAutoRenew || alreadyAutoRenew ) {
546 $( "#auto_renew" ).click(function( ) {
547 if ( $(this).attr( 'readonly' ) ) {
548 $(this).prop('checked', true );
549 }
550 });
551 }
552
553 {/literal}
554 {if !empty($existingContactMemberships)}
555
556 var alert, memberorgs = {$existingContactMemberships|@json_encode};
557
558 {literal}
559 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
560
561
562
563 function checkExistingMemOrg () {
564 alert && alert.close && alert.close();
565 var selectedorg = $("select[name='membership_type_id[0]']").val();
566 if (selectedorg in memberorgs) {
567 var andEndDate = '',
568 endDate = memberorgs[selectedorg].membership_end_date,
569 org = $('option:selected', "select[name='membership_type_id[0]']").text();
570 if (endDate) {
571 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
572 andEndDate = ' ' + ts(andEndDate, {1:endDate});
573 }
574
575 alert = CRM.alert(
576 // Mixing client-side variables with a translated string in smarty is awkward!
577 ts({/literal}'{ts escape='js' 1='%1' 2='%2' 3='%3' 4='%4'}This contact has an existing %1 membership at %2 with %3 status%4.{/ts}'{literal}, {1:memberorgs[selectedorg].membership_type, 2: org, 3: memberorgs[selectedorg].membership_status, 4: andEndDate})
578 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
579 + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}'
580 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
581 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
582 + '</a></li></ul>',
583 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
584 }
585 }
586 checkExistingMemOrg();
587 {/literal}
588 {/if}
589
590 {literal}
591
592 });
593 {/literal}
594
595 {if $membershipMode or $action eq 2}
596 {literal}
597
598 buildAutoRenew( null, null );
599
600 function buildAutoRenew( membershipType, processorId ) {
601 var mode = {/literal}'{$membershipMode}'{literal};
602 var action = {/literal}'{$action}'{literal};
603
604 //for update lets hide it when not already recurring.
605 if ( action == 2 ) {
606 //user can't cancel auto renew by unchecking.
607 if ( cj("#auto_renew").prop('checked' ) ) {
608 cj("#auto_renew").attr( 'readonly', true );
609 }
610 else {
611 cj("#autoRenew").hide( );
612 }
613 }
614
615 //we should do all auto renew for cc memberships.
616 if ( !mode ) return;
617
618 //get the required values in case missing.
619 if ( !processorId ) processorId = cj( '#payment_processor_id' ).val( );
620 if ( !membershipType ) membershipType = parseInt( cj('#membership_type_id_1').val( ) );
621
622 //we don't have both required values.
623 if ( !processorId || !membershipType ) {
624 cj("#auto_renew").prop('checked', false );
625 cj("#autoRenew").hide( );
626 return;
627 }
628
629 var recurProcessors = {/literal}{$recurProcessor}{literal};
630 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
631 var currentOption = autoRenewOptions[membershipType];
632
633 if ( !currentOption || !recurProcessors[processorId] ) {
634 cj("#auto_renew").prop('checked', false );
635 cj("#autoRenew").hide( );
636 return;
637 }
638
639 if ( currentOption == 1 ) {
640 cj("#autoRenew").show( );
641 if ( cj("#auto_renew").attr( 'readonly' ) ) {
642 cj("#auto_renew").prop('checked', false );
643 cj("#auto_renew").removeAttr( 'readonly' );
644 }
645 }
646 else if ( currentOption == 2 ) {
647 cj("#autoRenew").show( );
648 cj("#auto_renew").prop('checked', true );
649 cj("#auto_renew").attr( 'readonly', true );
650 }
651 else {
652 cj("#auto_renew").prop('checked', false );
653 cj("#autoRenew").hide( );
654 }
655
656 //play w/ receipt option.
657 if ( cj("#auto_renew").prop('checked' ) ) {
658 cj("#notice").hide( );
659 cj("#send_receipt").prop('checked', false );
660 cj("#send-receipt").hide( );
661 }
662 else {
663 cj("#send-receipt").show( );
664 if ( cj("#send_receipt").prop('checked' ) ) {
665 cj("#notice").show( );
666 }
667 }
668 }
669 {/literal}
670 {/if}
671
672 {literal}
673 function buildReceiptANDNotice( ) {
674 if ( cj("#auto_renew").prop('checked' ) ) {
675 cj("#notice").hide( );
676 cj("#send-receipt").hide( );
677 }
678 else {
679 cj("#send-receipt").show( );
680 if ( cj("#send_receipt").prop('checked' ) ) {
681 cj("#notice").show( );
682 }
683 }
684 }
685
686 var customDataType = '{/literal}{$customDataType}{literal}';
687
688 // load form during form rule.
689 {/literal}{if $buildPriceSet}{literal}
690 cj( "#totalAmountORPriceSet" ).hide( );
691 cj( "#mem_type_id" ).hide( );
692 cj('#total_amount').attr("readonly", true);
693 cj( "#num_terms_row" ).hide( );
694 cj(".crm-membership-form-block-financial_type_id-mode").hide();
695 {/literal}{/if}{literal}
696
697 function buildAmount( priceSetId ) {
698 if ( !priceSetId ) {
699 priceSetId = cj("#price_set_id").val( );
700 }
701 var fname = '#priceset';
702 if ( !priceSetId ) {
703 cj('#membership_type_id_1').val(0);
704 CRM.buildCustomData(customDataType, 'null' );
705
706 // hide price set fields.
707 cj( fname ).hide( );
708
709 // show/hide price set amount and total amount.
710 cj( "#mem_type_id").show( );
711 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
712 cj("#price_set_id option[value='']").html( choose );
713 cj( "#totalAmountORPriceSet" ).show( );
714 cj('#total_amount').removeAttr("readonly");
715 cj( "#num_terms_row").show( );
716 cj(".crm-membership-form-block-financial_type_id-mode").show();
717
718 {/literal}{if $allowAutoRenew}{literal}
719 cj('#autoRenew').hide();
720 var autoRenew = cj("#auto_renew");
721 autoRenew.removeAttr( 'readOnly' );
722 autoRenew.prop('checked', false );
723 {/literal}{/if}{literal}
724 return;
725 }
726
727 cj( "#total_amount" ).val( '' );
728 cj('#total_amount').attr("readonly", true);
729
730 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
731
732 var response = cj.ajax({
733 url: dataUrl,
734 async: false
735 }).responseText;
736
737 cj( fname ).show( ).html( response );
738 // freeze total amount text field.
739
740 cj( "#totalAmountORPriceSet" ).hide( );
741 cj( "#mem_type_id" ).hide( );
742 var manual = "{/literal}{ts}Manual membership and price{/ts}{literal}";
743 cj("#price_set_id option[value='']").html( manual );
744 cj( "#num_terms_row" ).hide( );
745 cj(".crm-membership-form-block-financial_type_id-mode").hide();
746 }
747
748 buildMaxRelated(cj('#membership_type_id_1', false).val());
749
750 function buildMaxRelated( memType, setDefault ) {
751 var allMemberships = {/literal}{$allMembershipInfo}{literal};
752
753 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
754 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
755 cj('#maxRelated').show();
756 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
757 if (cid) {
758 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
759 success: function(result) {
760 var relatable;
761 if (result.result === 0) {
762 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
763 }
764 else if (result.result === 1) {
765 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
766 }
767 else {
768 relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}';
769 relatable = ts(relatable, {1: result});
770 }
771 cj('#max_related').siblings('.description').append(' ' + relatable);
772 }
773 });
774 }
775 } else {
776 cj('#max_related').val('');
777 cj('#maxRelated').hide();
778 }
779 }
780
781 var lastMembershipTypes = [];
782 var optionsMembershipTypes = [];
783
784 // function to load custom data for selected membership types through priceset
785 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
786 var currentMembershipType = [];
787 var count = 0;
788 var loadCustomData = 0;
789 if ( membershipValues ) {
790 optionsMembershipTypes = membershipValues;
791 }
792
793 if ( reload ) {
794 lastMembershipTypes = [];
795 {/literal}{if $allowAutoRenew}{literal}
796 cj('#autoRenew').hide();
797 var autoRenew = cj("#auto_renew");
798 autoRenew.removeAttr( 'readOnly' );
799 autoRenew.prop('checked', false );
800 if ( autoRenewOption == 1 ) {
801 cj('#autoRenew').show();
802 }
803 else if ( autoRenewOption == 2 ) {
804 autoRenew.attr( 'readOnly', true );
805 autoRenew.prop('checked', true );
806 cj('#autoRenew').show();
807 }
808 {/literal}{/if}{literal}
809 }
810
811 cj("input,#priceset select,#priceset").each(function () {
812 if ( cj(this).attr('price') ) {
813 switch( cj(this).attr('type') ) {
814 case 'checkbox':
815 if ( cj(this).prop('checked') ) {
816 eval( 'var option = ' + cj(this).attr('price') ) ;
817 var ele = option[0];
818 var memTypeId = optionsMembershipTypes[ele];
819 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
820 currentMembershipType[count] = memTypeId;
821 count++;
822 }
823 }
824 if ( reload ) {
825 cj(this).click( function( ) {
826 processMembershipPriceset();
827 });
828 }
829 break;
830
831 case 'radio':
832 if ( cj(this).prop('checked') && cj(this).val() ) {
833 var memTypeId = optionsMembershipTypes[cj(this).val()];
834 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
835 currentMembershipType[count] = memTypeId;
836 count++;
837 }
838 }
839 if ( reload ) {
840 cj(this).click( function( ) {
841 processMembershipPriceset();
842 });
843 }
844 break;
845
846 case 'select-one':
847 if ( cj(this).val( ) ) {
848 var memTypeId = optionsMembershipTypes[cj(this).val()];
849 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
850 currentMembershipType[count] = memTypeId;
851 count++;
852 }
853 }
854 if ( reload ) {
855 cj(this).change( function( ) {
856 processMembershipPriceset();
857 });
858 }
859 break;
860 }
861 }
862 });
863
864 for( i in currentMembershipType ) {
865 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
866 loadCustomData = 1;
867 break;
868 }
869 }
870
871 if ( !loadCustomData ) {
872 for( i in lastMembershipTypes) {
873 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
874 loadCustomData = 1;
875 break;
876 }
877 }
878 }
879
880 lastMembershipTypes = currentMembershipType;
881
882 // load custom data only if change in membership type selection
883 if ( !loadCustomData ) {
884 return;
885 }
886
887 subTypeNames = currentMembershipType.join(',');
888 if ( subTypeNames.length < 1 ) {
889 subTypeNames = 'null';
890 }
891
892 CRM.buildCustomData( customDataType, subTypeNames );
893 }
894
895 function enableAmountSection( setContributionType ) {
896 if ( !cj('#record_contribution').prop('checked') ) {
897 cj('#record_contribution').click( );
898 cj('#recordContribution').show( );
899 }
900 if ( setContributionType ) {
901 cj('#financial_type_id').val(setContributionType);
902 }
903 }
904 </script>
905 {/literal}
906 {/if} {* closing of delete check if *}
907 {/if}{* closing of custom data if *}