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