Merge pull request #16610 from mattwire/settingstrait_datepicker
[civicrm-core.git] / templates / CRM / Member / Form / Membership.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
8 +--------------------------------------------------------------------+
9 *}
10 {* this template is used for adding/editing/deleting memberships for a contact *}
11 {if $isRecur}
12 <div class="messages status no-popup">
13 <div class="icon inform-icon"></div>
14 <p>{ts}This membership is set to renew automatically {if $endDate}on {$endDate|crmDate}{/if}. Please be aware that any changes that you make here may not be reflected in the payment processor. Please ensure that you alter the related subscription at the payment processor.{/ts}</p>
15 {if $cancelAutoRenew}<p>{ts 1=$cancelAutoRenew}To stop the automatic renewal:
16 <a href="%1">Cancel auto-renew</a>
17 {/ts}</p>{/if}
18 </div>
19 {/if}
20 <div class="spacer"></div>
21 {if $priceSetId}
22 {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Membership"}
23 {literal}
24 <script type="text/javascript">
25 CRM.$(function($) {
26 var membershipValues = [];
27 {/literal}{foreach from=$optionsMembershipTypes item=memType key=opId}{literal}
28 membershipValues[{/literal}{$opId}{literal}] = {/literal}{$memType}{literal};
29 {/literal}{/foreach}{literal}
30 processMembershipPriceset(membershipValues, {/literal}{$autoRenewOption}{literal}, 1);
31 {/literal}{if !$membershipMode}{literal}
32 enableAmountSection({/literal}{$contributionType}{literal});
33 {/literal}{/if}{literal}
34 });
35 </script>
36 {/literal}
37 {else}
38 {if $membershipMode == 'test' }
39 {assign var=registerMode value="TEST"}
40 {elseif $membershipMode == 'live'}
41 {assign var=registerMode value="LIVE"}
42 {/if}
43 {if !$emailExists and $action neq 8 and $context neq 'standalone'}
44 <div class="messages status no-popup">
45 <div class="icon inform-icon"></div>
46 <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>
47 </div>
48 {/if}
49 {if $membershipMode}
50 <div class="help">
51 {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}
52 </div>
53 {/if}
54 <div class="crm-block crm-form-block crm-membership-form-block">
55 {if $newCredit AND $action EQ 1 AND $membershipMode EQ null}
56 <div class="action-link css_right crm-link-credit-card-mode">
57 {if $contactId}
58 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/membership' q="reset=1&action=add&cid=`$contactId`&context=`$context`&mode=live"}{/capture}
59 {else}
60 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/membership' q="reset=1&action=add&context=standalone&mode=live"}{/capture}
61 {/if}
62 <a class="open-inline-noreturn action-item crm-hover-button" href="{$ccModeLink}"><i class="crm-i fa-credit-card" aria-hidden="true"></i> {ts}submit credit card membership{/ts}</a>
63 </div>
64 {/if}
65 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
66 {if $action eq 8}
67 <div class="messages status no-popup">
68 <div class="icon inform-icon"></div>&nbsp;
69 {$deleteMessage}
70 </div>
71 {else}
72 <table class="form-layout-compressed">
73 <tr class="crm-membership-form-contact-id">
74 <td class="label">{$form.contact_id.label}</td>
75 <td>{$form.contact_id.html}</td>
76 </tr>
77 <tr class="crm-membership-form-block-membership_type_id">
78 <td class="label">{$form.membership_type_id.label}</td>
79 <td id="mem_type_id-readonly">
80 <span id="membership_type_id_0-readonly"></span> : <span id="membership_type_id_1-readonly"></span>
81 <span id="mem-type-override">
82 <a href="#" class="crm-hover-button action-item override-mem-type" id="show-mem-type">
83 {ts}Override organization and type{/ts}
84 </a>
85 {help id="override_membership_type"}
86 </span>
87 </td>
88 <td id="mem_type_id-editable"><span id='mem_type_id'>{$form.membership_type_id.html}</span>
89 {if $hasPriceSets}
90 <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
91 <span id='selectPriceSet'>{$form.price_set_id.html}</span>
92 {if $buildPriceSet && $priceSet}
93 <div id="priceset"><br/>{include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"}</div>
94 {else}
95 <div id="priceset" class="hiddenElement"></div>
96 {/if}
97 {/if}
98 {if $member_is_test} {ts}(test){/ts}{/if}<br />
99 <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>
100 </td>
101 </tr>
102 <tr id="maxRelated" class="crm-membership-form-block-max_related">
103 <td class="label">{$form.max_related.label}</td>
104 <td>{$form.max_related.html}<br />
105 <span class="description">{ts}Maximum number of related memberships (leave blank for unlimited).{/ts} <span id="eligibleRelated"></span></span>
106 </td>
107 </tr>
108 {if $action eq 1}
109 <tr id="num_terms_row" class="crm-membership-form-block-num_terms">
110 <td class="label">{$form.num_terms.label}</td>
111 <td>&nbsp;{$form.num_terms.html}<br />
112 <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>
113 </td>
114 </tr>
115 {/if}
116 <tr class="crm-membership-form-block-source">
117 <td class="label">{$form.source.label}</td>
118 <td>&nbsp;{$form.source.html}<br />
119 <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td>
120 </tr>
121
122 {* CRM-7362 --add campaign to membership *}
123 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
124 campaignTrClass="crm-membership-form-block-campaign_id"}
125
126 <tr class="crm-membership-form-block-join_date"><td class="label">{$form.join_date.label}</td><td>{$form.join_date.html}
127 <br />
128 <span class="description">{ts}When did this contact first become a member?{/ts}</span></td></tr>
129 <tr class="crm-membership-form-block-start_date"><td class="label">{$form.start_date.label}</td><td>{$form.start_date.html}
130 <br />
131 <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>
132 <tr class="crm-membership-form-block-end_date"><td class="label">{$form.end_date.label}</td>
133 <td id="end-date-readonly">
134 {$endDate|crmDate}
135 <a href="#" class="crm-hover-button action-item override-date" id="show-end-date">
136 {ts}Override end date{/ts}
137 </a>
138 {help id="override_end_date"}
139 </td>
140 <td id="end-date-editable">
141 {$form.end_date.html}
142 <br />
143 <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>
144 </td>
145 </tr>
146 {if !$membershipMode}
147 <tr>
148 <td class="label">{$form.is_override.label} {help id="id-status-override"}</td>
149 <td>
150 <span id="is-override">{$form.is_override.html}</span>
151 <span id="status-override-end-date">{$form.status_override_end_date.html}</span>
152 </td>
153 </tr>
154 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
155 <tr id="memberStatus_show">
156 {if $action eq 2}
157 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
158 {/if}
159 </tr>
160
161 {* Show editable status field when is_override is TRUE *}
162 <tr id="memberStatus"><td class="label">{$form.status_id.label}</td><td>{$form.status_id.html}<br />
163 <span class="description">{ts}When <strong>Status Override</strong> is active, the selected status will remain in force (it will NOT be subject to membership status rules) until it is cancelled or become inactive.{/ts}</span></td></tr>
164 {/if}
165
166 {if $accessContribution and !$membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
167 <tr id="contri">
168 <td class="label">{if $onlinePendingContributionId}{ts}Update Payment Status{/ts}{else}{$form.record_contribution.label}{/if}</td>
169 <td>{$form.record_contribution.html}<br />
170 <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>
171 </tr>
172 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
173 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
174 {/if}
175 {include file="CRM/Member/Form/MembershipCommon.tpl"}
176 {if $emailExists and $isEmailEnabledForSite}
177 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
178 <td class="label">{$form.send_receipt.label}</td>
179 <td>
180 {$form.send_receipt.html}<br />
181 <span class="description">
182 {ts 1=$emailExists}Automatically email a membership confirmation and receipt to %1? OR if the payment is from a different contact, this email will only go to them.{/ts}
183 <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span>
184 </span>
185 </td>
186 </tr>
187 {elseif $context eq 'standalone' and $isEmailEnabledForSite}
188 <tr id="email-receipt" style="display:none;">
189 <td class="label">{$form.send_receipt.label}</td>
190 <td>
191 {$form.send_receipt.html}<br />
192 <span class="description">
193 {ts}Automatically email a membership confirmation and receipt to {/ts}<span id="email-address"></span>? {ts}OR if the payment is from a different contact, this email will only go to them.{/ts}
194 <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span>
195 </span>
196 </td>
197 </tr>
198 {/if}
199 <tr id="fromEmail" style="display: none" class="crm-contactEmail-form-block-fromEmailAddress crm-email-element">
200 <td class="label">{$form.from_email_address.label}</td>
201 <td>{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Email.hlp" isAdmin=$isAdmin}</td>
202 </tr>
203 <tr id='notice' style="display:none;">
204 <td class="label">{$form.receipt_text.label}</td>
205 <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>
206 {$form.receipt_text.html|crmAddClass:huge}</td>
207 </tr>
208 </table>
209 {include file="CRM/common/customDataBlock.tpl"}
210 {if $accessContribution and $action eq 2 and $rows.0.contribution_id}
211 <div class="crm-accordion-wrapper">
212 <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div>
213 <div class="crm-accordion-body">
214 {include file="CRM/Contribute/Form/Selector.tpl" context="Search"}
215 <script type="text/javascript">
216 var membershipID = {$entityID};
217 var contactID = {$contactId};
218 {literal}
219 CRM.$(function($) {
220 CRM.loadPage(
221 CRM.url(
222 'civicrm/membership/recurring-contributions',
223 {
224 reset: 1,
225 membershipID: membershipID,
226 cid: contactID
227 },
228 'back'
229 ),
230 {
231 target : '#membership-recurring-contributions',
232 dialog : false
233 }
234 );
235 });
236 {/literal}
237 </script>
238 <div id="membership-recurring-contributions"></div>
239 </div>
240 </div>
241 {/if}
242 {if $softCredit}
243 <div class="crm-accordion-wrapper">
244 <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div>
245 <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div>
246 </div>
247 {/if}
248 {/if}
249
250 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
251 </div> <!-- end form-block -->
252
253 {if $action neq 8} {* Jscript additions not need for Delete action *}
254 {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)}
255
256 {include file="CRM/common/showHideByFieldValue.tpl"
257 trigger_field_id ="record_contribution"
258 trigger_value =""
259 target_element_id ="recordContribution"
260 target_element_type ="table-row"
261 field_type ="radio"
262 invert = 0
263 }
264 {/if}
265
266 {literal}
267 <script type="text/javascript">
268 function setPaymentBlock(mode, checkboxEvent) {
269 var memType = parseInt(cj('#membership_type_id_1').val( ));
270 var isPriceSet = 0;
271 var existingAmount = {/literal}{if !empty($onlinePendingContributionId)}1{else}0{/if}{literal};
272
273 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
274 isPriceSet = 1;
275 }
276
277 if ( !memType || isPriceSet ) {
278 return;
279 }
280
281 var allMemberships = {/literal}{$allMembershipInfo}{literal};
282 if (!mode) {
283 //check the record_contribution checkbox if membership is a paid one
284 {/literal}{if $action eq 1}{literal}
285 if (!checkboxEvent) {
286 if (allMemberships[memType]['total_amount_numeric'] > 0) {
287 cj('#record_contribution').prop('checked','checked');
288 cj('#recordContribution').show();
289 }
290 else {
291 cj('#record_contribution').prop('checked', false);
292 cj('#recordContribution').hide();
293 }
294 }
295 {/literal}{/if}{literal}
296 }
297
298 // skip this for test and live modes because financial type is set automatically
299 cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']);
300 var term = cj('#num_terms').val();
301 var taxRates = {/literal}{$taxRates}{literal};
302 var taxTerm = {/literal}{$taxTerm|@json_encode}{literal};
303 var taxRate = taxRates[allMemberships[memType]['financial_type_id']];
304 var currency = {/literal}{$currency_symbol|@json_encode}{literal};
305 var taxAmount = (taxRate/100)*allMemberships[memType]['total_amount_numeric'];
306 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
307 if (term) {
308 if (!taxRate) {
309 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
310 }
311 else {
312 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number
313 (allMemberships[memType]['total_amount_numeric'] * term );
314 }
315 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
316 }
317 else {
318 if (taxRate) {
319 var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
320 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
321 }
322 else {
323 var feeTotal = allMemberships[memType]['total_amount'];
324 if (!existingAmount) {
325 // CRM-16680 don't set amount if there is an existing contribution.
326 cj("#total_amount").val(allMemberships[memType]['total_amount']);
327 }
328 }
329 }
330 var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
331 cj('.totaltaxAmount').html(taxMessage);
332 }
333
334
335 CRM.$(function($) {
336 var mode = {/literal}'{$membershipMode}'{literal};
337 if ( !mode ) {
338 // Offline form (mode = false) has the record_contribution checkbox
339 cj('#record_contribution').click( function( ) {
340 if ( cj(this).prop('checked') ) {
341 cj('#recordContribution').show( );
342 setPaymentBlock( false, true);
343 }
344 else {
345 cj('#recordContribution').hide( );
346 }
347 });
348 }
349
350 cj('#membership_type_id_1').change( function( ) {
351 setPaymentBlock(mode);
352 });
353 cj('#num_terms').change( function( ) {
354 setPaymentBlock(mode);
355 });
356 setPaymentBlock(mode);
357
358 // show/hide different contact section
359 setDifferentContactBlock();
360 cj('#is_different_contribution_contact').change( function() {
361 setDifferentContactBlock();
362 });
363
364 // give option to override membership type for auto-renew memberships - dev/core#1331
365 {/literal}
366 {if $isRecur}
367 cj('#membership_type_id_0-readonly').text(cj('#membership_type_id_0 option:selected').text());
368 cj('#membership_type_id_1-readonly').text(cj('#membership_type_id_1 option:selected').text());
369 cj('#mem_type_id-readonly').show();
370 cj('#mem_type_id-editable').hide();
371 {else}
372 cj('#mem_type_id-readonly').hide();
373 cj('#mem_type_id-editable').show();
374 {/if}
375 {literal}
376
377 cj('#show-mem-type').click( function( e ) {
378 e.preventDefault();
379 cj('#mem_type_id-readonly').hide();
380 cj('#mem_type_id-editable').show();
381 });
382
383 // give option to override end-date for auto-renew memberships
384 {/literal}
385 {if $isRecur && $endDate}
386 cj('#end-date-readonly').show();
387 cj('#end-date-editable').hide();
388 {else}
389 cj('#end-date-readonly').hide();
390 cj('#end-date-editable').show();
391 {/if}
392 {literal}
393
394 cj('#show-end-date').click( function( e ) {
395 e.preventDefault();
396 cj('#end-date-readonly').hide();
397 cj('#end-date-editable').show();
398 });
399
400 });
401
402 function setDifferentContactBlock( ) {
403 // show/hide different contact section
404 if ( cj('#is_different_contribution_contact').prop('checked') ) {
405 cj('#record-different-contact').show();
406 }
407 else {
408 cj('#record-different-contact').hide();
409 }
410 }
411
412 function showEmailOptions() {
413 {/literal}
414 // @todo emailExists refers to the primary contact for the page.
415 // elsewhere some script determines if there is a paying contact the
416 // email should go to instead (e.g gift membership). This should be checked for here
417 // and that merged into that code as currently behaviour is inconsistent.
418 var emailExists = {$emailExists|json_encode};
419 var isStandalone = {if $context == 'standalone'}true{else}false{/if};
420 var isEmailEnabledForSite = {if $isEmailEnabledForSite}true{else}false{/if};
421
422 {literal}
423 var isEmailable = (isEmailEnabledForSite && (emailExists || isStandalone));
424
425 if (isEmailable && cj('#send_receipt').prop('checked') && !cj('#auto_renew').prop('checked')) {
426 // Hide extra message and from email for recurring as they cannot be stored until use.
427 cj('#notice').show();
428 cj('#fromEmail').show();
429 }
430 else {
431 cj('#notice').hide();
432 cj('#fromEmail').hide();
433 }
434 }
435 </script>
436 <script type="text/javascript">
437
438 {/literal}{if !$membershipMode}{literal}
439 cj( "#is_override" ).change(function() {
440 showHideMemberStatus();
441 });
442
443 showHideMemberStatus();
444 function showHideMemberStatus() {
445 var isOverride = cj( "#is_override" ).val();
446 switch (isOverride) {
447 case '0':
448 cj('#memberStatus').hide();
449 cj('#memberStatus_show').show();
450 cj('#status-override-end-date').hide();
451 break;
452 case '1':
453 cj('#memberStatus').show();
454 cj('#memberStatus_show').hide();
455 cj('#status-override-end-date').hide();
456 break;
457 case '2':
458 cj('#memberStatus').show();
459 cj('#memberStatus_show').hide();
460 cj('#status-override-end-date').show();
461 break;
462 default :
463 cj('#memberStatus').hide( );
464 cj('#memberStatus_show').show( );
465 cj('#status-override-end-date').hide();
466 break;
467 }
468 }
469 {/literal}{/if}
470
471 {if $context eq 'standalone' and $isEmailEnabledForSite }
472 {literal}
473 CRM.$(function($) {
474 var $form = $("form.{/literal}{$form.formClass}{literal}");
475 $("#contact_id", $form).change(checkEmail);
476 checkEmail( );
477
478 function checkEmail( ) {
479 var data = $("#contact_id", $form).select2('data');
480 if (data && data.extra && data.extra.email && data.extra.email.length) {
481 $("#email-receipt", $form).show();
482 if ($("#send_receipt", $form).is(':checked')) {
483 $("#notice", $form).show();
484 }
485 $("#email-address", $form).html(data.extra.email);
486 }
487 else {
488 $("#email-receipt, #notice", $form).hide();
489 }
490 }
491 });
492
493 {/literal}
494 {/if}
495
496 {literal}
497 //keep read only always checked.
498 CRM.$(function($) {
499 var $form = $("form.{/literal}{$form.formClass}{literal}");
500 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
501 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
502 if ( allowAutoRenew || alreadyAutoRenew ) {
503 $( "#auto_renew" ).click(function( ) {
504 if ( $(this).attr( 'readonly' ) ) {
505 $(this).prop('checked', true );
506 }
507 showEmailOptions();
508 });
509 }
510
511 {/literal}
512 {if !empty($existingContactMemberships)}
513
514 var alert, memberorgs = {$existingContactMemberships|@json_encode};
515
516 {literal}
517 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
518
519
520
521 function checkExistingMemOrg () {
522 alert && alert.close && alert.close();
523 var selectedorg = $("select[name='membership_type_id[0]']").val();
524 if (selectedorg in memberorgs) {
525 var andEndDate = '',
526 endDate = memberorgs[selectedorg].membership_end_date,
527 org = $('option:selected', "select[name='membership_type_id[0]']").text();
528 if (endDate) {
529 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
530 andEndDate = ' ' + ts(andEndDate, {1:endDate});
531 }
532
533 alert = CRM.alert(
534 // Mixing client-side variables with a translated string in smarty is awkward!
535 ts({/literal}'{ts escape='js'}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})
536 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
537 + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}'
538 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
539 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
540 + '</a></li></ul>',
541 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
542 }
543 }
544 checkExistingMemOrg();
545 {/literal}
546 {/if}
547
548 {literal}
549
550 });
551 {/literal}
552
553 {if $membershipMode or $action eq 2}
554 buildAutoRenew( null, null, '{$membershipMode}');
555 {/if}
556 {literal}
557 function buildAutoRenew( membershipType, processorId, mode ) {
558 var action = {/literal}'{$action}'{literal};
559
560 //for update lets hide it when not already recurring.
561 if (action == 2) {
562 //user can't cancel auto renew by unchecking.
563 if (cj("#auto_renew").prop('checked')) {
564 cj("#auto_renew").attr('readonly', true);
565 }
566 else {
567 cj("#autoRenew").hide( );
568 }
569 }
570
571 //we should do all auto renew for cc memberships.
572 if (!mode) {
573 return;
574 }
575
576 //get the required values in case missing.
577 if (!processorId) {
578 processorId = cj( '#payment_processor_id' ).val( );
579 }
580 if (!membershipType) {
581 membershipType = parseInt( cj('#membership_type_id_1').val( ) );
582 }
583
584 //we don't have both required values.
585 if (!processorId || !membershipType) {
586 cj("#auto_renew").prop('checked', false);
587 cj("#autoRenew").hide();
588 showEmailOptions();
589 return;
590 }
591
592 var recurProcessors = {/literal}{$recurProcessor}{literal};
593 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
594 var currentOption = autoRenewOptions[membershipType];
595
596 if (!currentOption || !recurProcessors[processorId]) {
597 cj("#auto_renew").prop('checked', false );
598 cj("#autoRenew").hide();
599 return;
600 }
601
602 if (currentOption == 1) {
603 cj("#autoRenew").show();
604 if (cj("#auto_renew").attr('readonly')) {
605 cj("#auto_renew").prop('checked', false).removeAttr('readonly');
606 }
607 }
608 else if ( currentOption == 2 ) {
609 cj("#autoRenew").show();
610 cj("#auto_renew").prop('checked', true).attr('readonly', true);
611 }
612 else {
613 cj("#auto_renew").prop('checked', false);
614 cj("#autoRenew").hide( );
615 }
616 showEmailOptions();
617 }
618
619 var customDataType = {/literal}{$customDataType|@json_encode}{literal};
620
621 // load form during form rule.
622 {/literal}{if $buildPriceSet}{literal}
623 cj("#totalAmountORPriceSet, #mem_type_id, #num_terms_row, .crm-membership-form-block-financial_type_id-mode").hide();
624 cj('#total_amount').attr("readonly", true);
625 {/literal}{/if}{literal}
626
627 function buildAmount( priceSetId ) {
628 if (!priceSetId) {
629 priceSetId = cj("#price_set_id").val();
630 }
631 var fname = '#priceset';
632 if ( !priceSetId ) {
633 cj('#membership_type_id_1').val(0);
634 CRM.buildCustomData(customDataType, null);
635
636 // hide price set fields.
637 cj( fname ).hide( );
638
639 // show/hide price set amount and total amount.
640 cj( "#mem_type_id").show( );
641 var choose = "{/literal}{ts escape='js'}Choose price set{/ts}{literal}";
642 cj("#price_set_id option[value='']").html( choose );
643 cj( "#totalAmountORPriceSet" ).show( );
644 cj('#total_amount').removeAttr("readonly");
645 cj( "#num_terms_row").show( );
646 cj(".crm-membership-form-block-financial_type_id-mode").show();
647
648 {/literal}{if $allowAutoRenew}{literal}
649 cj('#autoRenew').hide();
650 cj("#auto_renew").removeAttr('readOnly').prop('checked', false );
651 {/literal}{/if}{literal}
652 return;
653 }
654
655 cj( "#total_amount" ).val('').attr("readonly", true);
656
657 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
658
659 var response = cj.ajax({
660 url: dataUrl,
661 async: false
662 }).responseText;
663
664 cj( fname ).show( ).html( response );
665 // freeze total amount text field.
666
667 cj( "#totalAmountORPriceSet" ).hide( );
668 cj( "#mem_type_id" ).hide( );
669 var manual = "{/literal}{ts escape='js'}Manual membership and price{/ts}{literal}";
670 cj("#price_set_id option[value='']").html( manual );
671 cj( "#num_terms_row" ).hide( );
672 cj(".crm-membership-form-block-financial_type_id-mode").hide();
673 }
674
675 buildMaxRelated(cj('#membership_type_id_1', false).val());
676
677 function buildMaxRelated( memType, setDefault ) {
678 var allMemberships = {/literal}{$allMembershipInfo}{literal};
679
680 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
681 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
682 cj('#maxRelated').show();
683 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
684 if (cid) {
685 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
686 success: function(result) {
687 var relatable;
688 if (result.result === 0) {
689 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
690 }
691 else if (result.result === 1) {
692 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
693 }
694 else {
695 relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}';
696 relatable = ts(relatable, {1: result});
697 }
698 cj('#eligibleRelated').text(relatable);
699 }
700 });
701 }
702 } else {
703 cj('#max_related').val('');
704 cj('#maxRelated').hide();
705 }
706 }
707
708 var lastMembershipTypes = [];
709 var optionsMembershipTypes = [];
710
711 // function to load custom data for selected membership types through priceset
712 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
713 var currentMembershipType = [];
714 var count = 0;
715 var loadCustomData = 0;
716 if ( membershipValues ) {
717 optionsMembershipTypes = membershipValues;
718 }
719
720 if ( reload ) {
721 lastMembershipTypes = [];
722 {/literal}{if $allowAutoRenew}{literal}
723 cj('#autoRenew').hide();
724 var autoRenew = cj("#auto_renew");
725 autoRenew.removeAttr('readOnly').prop('checked', false );
726 if (autoRenewOption == 1) {
727 cj('#autoRenew').show();
728 }
729 else if (autoRenewOption == 2) {
730 autoRenew.attr('readOnly', true).prop('checked', true );
731 cj('#autoRenew').show();
732 }
733 {/literal}{/if}{literal}
734 }
735
736 cj("input,#priceset select,#priceset").each(function () {
737 if ( cj(this).attr('price') ) {
738 switch( cj(this).attr('type') ) {
739 case 'checkbox':
740 if ( cj(this).prop('checked') ) {
741 eval( 'var option = ' + cj(this).attr('price') ) ;
742 var ele = option[0];
743 var memTypeId = optionsMembershipTypes[ele];
744 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
745 currentMembershipType[count] = memTypeId;
746 count++;
747 }
748 }
749 if ( reload ) {
750 cj(this).click( function( ) {
751 processMembershipPriceset();
752 });
753 }
754 break;
755
756 case 'radio':
757 if ( cj(this).prop('checked') && cj(this).val() ) {
758 var memTypeId = optionsMembershipTypes[cj(this).val()];
759 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
760 currentMembershipType[count] = memTypeId;
761 count++;
762 }
763 }
764 if ( reload ) {
765 cj(this).click( function( ) {
766 processMembershipPriceset();
767 });
768 }
769 break;
770
771 case 'select-one':
772 if ( cj(this).val( ) ) {
773 var memTypeId = optionsMembershipTypes[cj(this).val()];
774 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
775 currentMembershipType[count] = memTypeId;
776 count++;
777 }
778 }
779 if ( reload ) {
780 cj(this).change( function( ) {
781 processMembershipPriceset();
782 });
783 }
784 break;
785 }
786 }
787 });
788
789 for( i in currentMembershipType ) {
790 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
791 loadCustomData = 1;
792 break;
793 }
794 }
795
796 if ( !loadCustomData ) {
797 for( i in lastMembershipTypes) {
798 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
799 loadCustomData = 1;
800 break;
801 }
802 }
803 }
804
805 lastMembershipTypes = currentMembershipType;
806
807 // load custom data only if change in membership type selection
808 if ( !loadCustomData ) {
809 return;
810 }
811
812 subTypeNames = currentMembershipType.join(',');
813 if ( subTypeNames.length < 1 ) {
814 subTypeNames = null;
815 }
816
817 CRM.buildCustomData(customDataType, subTypeNames);
818 }
819
820 function enableAmountSection( setContributionType ) {
821 if ( !cj('#record_contribution').prop('checked') ) {
822 cj('#record_contribution').click( );
823 cj('#recordContribution').show( );
824 }
825 if ( setContributionType ) {
826 cj('#financial_type_id').val(setContributionType);
827 }
828 }
829 </script>
830 {/literal}
831 {/if} {* closing of delete check if *}
832 {/if}{* closing of custom data if *}