2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2017 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
26 {* this template is used for adding/editing/deleting memberships for a contact *}
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>
33 <div class="spacer"></div>
35 {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Membership"}
37 <script type="text/javascript">
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}
51 {if $membershipMode == 'test' }
52 {assign var=registerMode value="TEST"}
53 {elseif $membershipMode == 'live'}
54 {assign var=registerMode value="LIVE"}
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>
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}
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">
71 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/membership' q="reset=1&action=add&cid=`$contactId`&context=`$context`&mode=live"}{/capture}
73 {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/membership' q="reset=1&action=add&context=standalone&mode=live"}{/capture}
75 <a class="open-inline-noreturn action-item crm-hover-button" href="{$ccModeLink}">» {ts}submit credit card membership{/ts}</a>
78 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
80 <div class="messages status no-popup">
81 <div class="icon inform-icon"></div>
82 <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>
83 <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>
84 <p>{ts}Click 'Delete' if you want to continue.{/ts}</p>
87 <table class="form-layout-compressed">
88 {if $context neq 'standalone'}
90 <td class="font-size12pt label"><strong>{ts}Member{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
93 <td class="label">{$form.contact_id.label}</td>
94 <td>{$form.contact_id.html}</td>
96 <tr class="crm-membership-form-block-membership_type_id">
97 <td class="label">{$form.membership_type_id.label}</td>
98 <td><span id='mem_type_id'>{$form.membership_type_id.html}</span>
100 <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
101 <span id='selectPriceSet'>{$form.price_set_id.html}</span>
102 {if $buildPriceSet && $priceSet}
103 <div id="priceset"><br/>{include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"}</div>
105 <div id="priceset" class="hiddenElement"></div>
108 {if $member_is_test} {ts}(test){/ts}{/if}<br />
109 <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>
112 <tr id="maxRelated" class="crm-membership-form-block-max_related">
113 <td class="label">{$form.max_related.label}</td>
114 <td>{$form.max_related.html}<br />
115 <span class="description">{ts}Maximum number of related memberships (leave blank for unlimited).{/ts}</span>
119 <tr id="num_terms_row" class="crm-membership-form-block-num_terms">
120 <td class="label">{$form.num_terms.label}</td>
121 <td> {$form.num_terms.html}<br />
122 <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>
126 <tr class="crm-membership-form-block-source">
127 <td class="label">{$form.source.label}</td>
128 <td> {$form.source.html}<br />
129 <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td>
132 {* CRM-7362 --add campaign to membership *}
133 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
134 campaignTrClass="crm-membership-form-block-campaign_id"}
136 <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}
138 <span class="description">{ts}When did this contact first become a member?{/ts}</span></td></tr>
139 <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}
141 <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>
142 <tr class="crm-membership-form-block-end_date"><td class="label">{$form.end_date.label}</td>
143 <td id="end-date-readonly">
145 <a href="#" class="crm-hover-button action-item override-date" id="show-end-date">
146 {ts}Over-ride end date{/ts}
148 {help id="override_end_date"}
150 <td id="end-date-editable">
151 {include file="CRM/common/jcalendar.tpl" elementName=end_date}
153 <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>
156 {if !$membershipMode}
158 <td class="label">{$form.is_override.label} {help id="id-status-override"}</td>
160 <span id="is-override">{$form.is_override.html}</span>
161 <span id="status-override-end-date">{$form.status_override_end_date.html}</span>
164 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
165 <tr id="memberStatus_show">
167 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
171 {* Show editable status field when is_override is TRUE *}
172 <tr id="memberStatus"><td class="label">{$form.status_id.label}</td><td>{$form.status_id.html}<br />
173 <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>
176 {if $accessContribution and !$membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
178 <td class="label">{if $onlinePendingContributionId}{ts}Update Payment Status{/ts}{else}{$form.record_contribution.label}{/if}</td>
179 <td>{$form.record_contribution.html}<br />
180 <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>
182 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
183 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
185 {include file="CRM/Member/Form/MembershipCommon.tpl"}
186 {if $emailExists and $isEmailEnabledForSite}
187 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
188 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
189 <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>
190 <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span>
192 {elseif $context eq 'standalone' and $isEmailEnabledForSite}
193 <tr id="email-receipt" style="display:none;">
194 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
195 <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>
196 <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span>
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>
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>
209 <div id="customData"></div>
210 {*include custom data js file*}
211 {include file="CRM/common/customData.tpl"}
213 <script type="text/javascript">
216 CRM.buildCustomData( '{$customDataType}' );
217 {if $customDataSubType}
218 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
224 {if $accessContribution and $action eq 2 and $rows.0.contribution_id}
225 <div class="crm-accordion-wrapper">
226 <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div>
227 <div class="crm-accordion-body">{include file="CRM/Contribute/Form/Selector.tpl" context="Search"}</div>
231 <div class="crm-accordion-wrapper">
232 <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div>
233 <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div>
238 <div class="spacer"></div>
239 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
240 </div> <!-- end form-block -->
242 {if $action neq 8} {* Jscript additions not need for Delete action *}
243 {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)}
245 {include file="CRM/common/showHideByFieldValue.tpl"
246 trigger_field_id ="record_contribution"
248 target_element_id ="recordContribution"
249 target_element_type ="table-row"
256 <script type="text/javascript">
257 function setPaymentBlock(mode, checkboxEvent) {
258 var memType = parseInt(cj('#membership_type_id_1').val( ));
260 var existingAmount = {/literal}{if !empty($onlinePendingContributionId)}1{else}0{/if}{literal};
262 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
266 if ( !memType || isPriceSet ) {
270 var allMemberships = {/literal}{$allMembershipInfo}{literal};
272 //check the record_contribution checkbox if membership is a paid one
273 {/literal}{if $action eq 1}{literal}
274 if (!checkboxEvent) {
275 if (allMemberships[memType]['total_amount_numeric'] > 0) {
276 cj('#record_contribution').prop('checked','checked');
277 cj('#recordContribution').show();
280 cj('#record_contribution').prop('checked', false);
281 cj('#recordContribution').hide();
284 {/literal}{/if}{literal}
287 // skip this for test and live modes because financial type is set automatically
288 cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']);
289 var term = cj('#num_terms').val();
290 var taxRates = '{/literal}{$taxRates}{literal}';
291 var taxTerm = '{/literal}{$taxTerm}{literal}';
292 var taxRates = JSON.parse(taxRates);
293 var taxRate = taxRates[allMemberships[memType]['financial_type_id']];
294 var currency = '{/literal}{$currency}{literal}';
295 var taxAmount = (taxRate/100)*allMemberships[memType]['total_amount_numeric'];
296 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
299 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
302 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number
303 (allMemberships[memType]['total_amount_numeric'] * term );
305 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
309 var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
310 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
313 var feeTotal = allMemberships[memType]['total_amount'];
314 if (!existingAmount) {
315 // CRM-16680 don't set amount if there is an existing contribution.
316 cj("#total_amount").val(allMemberships[memType]['total_amount']);
320 var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
321 cj('.totaltaxAmount').html(taxMessage);
326 var mode = {/literal}'{$membershipMode}'{literal};
328 // Offline form (mode = false) has the record_contribution checkbox
329 cj('#record_contribution').click( function( ) {
330 if ( cj(this).prop('checked') ) {
331 cj('#recordContribution').show( );
332 setPaymentBlock( false, true);
335 cj('#recordContribution').hide( );
340 cj('#membership_type_id_1').change( function( ) {
341 setPaymentBlock(mode);
343 cj('#num_terms').change( function( ) {
344 setPaymentBlock(mode);
346 setPaymentBlock(mode);
348 // show/hide different contact section
349 setDifferentContactBlock();
350 cj('#is_different_contribution_contact').change( function() {
351 setDifferentContactBlock();
354 // give option to override end-date for auto-renew memberships
356 {if $isRecur && $endDate}
357 cj('#end-date-readonly').show();
358 cj('#end-date-editable').hide();
360 cj('#end-date-readonly').hide();
361 cj('#end-date-editable').show();
365 cj('#show-end-date').click( function( e ) {
367 cj('#end-date-readonly').hide();
368 cj('#end-date-editable').show();
373 function setDifferentContactBlock( ) {
374 // show/hide different contact section
375 if ( cj('#is_different_contribution_contact').prop('checked') ) {
376 cj('#record-different-contact').show();
379 cj('#record-different-contact').hide();
383 function showEmailOptions() {
385 // @todo emailExists refers to the primary contact for the page.
386 // elsewhere some script determines if there is a paying contact the
387 // email should go to instead (e.g gift membership). This should be checked for here
388 // and that merged into that code as currently behaviour is inconsistent.
389 var emailExists = '{$emailExists}';
390 var isStandalone = ('{$context}' == 'standalone');
391 var isEmailEnabledForSite = {if $isEmailEnabledForSite}true{else}false{/if};
394 var isEmailable = (isEmailEnabledForSite && (emailExists || isStandalone));
396 if (isEmailable && cj('#send_receipt').prop('checked') && !cj('#auto_renew').prop('checked')) {
397 // Hide extra message and from email for recurring as they cannot be stored until use.
398 cj('#notice').show();
399 cj('#fromEmail').show();
402 cj('#notice').hide();
403 cj('#fromEmail').hide();
407 <script type="text/javascript">
409 {/literal}{if !$membershipMode}{literal}
410 cj( "#is_override" ).change(function() {
411 showHideMemberStatus();
414 showHideMemberStatus();
415 function showHideMemberStatus() {
416 var isOverride = cj( "#is_override" ).val();
417 switch (isOverride) {
419 cj('#memberStatus').hide();
420 cj('#memberStatus_show').show();
421 cj('#status-override-end-date').hide();
424 cj('#memberStatus').show();
425 cj('#memberStatus_show').hide();
426 cj('#status-override-end-date').hide();
429 cj('#memberStatus').show();
430 cj('#memberStatus_show').hide();
431 cj('#status-override-end-date').show();
434 cj('#memberStatus').hide( );
435 cj('#memberStatus_show').show( );
436 cj('#status-override-end-date').hide();
442 {if $context eq 'standalone' and $isEmailEnabledForSite }
445 var $form = $("form.{/literal}{$form.formClass}{literal}");
446 $("#contact_id", $form).change(checkEmail);
449 function checkEmail( ) {
450 var data = $("#contact_id", $form).select2('data');
451 if (data && data.extra && data.extra.email && data.extra.email.length) {
452 $("#email-receipt", $form).show();
453 if ($("#send_receipt", $form).is(':checked')) {
454 $("#notice", $form).show();
456 $("#email-address", $form).html(data.extra.email);
459 $("#email-receipt, #notice", $form).hide();
468 //keep read only always checked.
470 var $form = $("form.{/literal}{$form.formClass}{literal}");
471 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
472 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
473 if ( allowAutoRenew || alreadyAutoRenew ) {
474 $( "#auto_renew" ).click(function( ) {
475 if ( $(this).attr( 'readonly' ) ) {
476 $(this).prop('checked', true );
483 {if !empty($existingContactMemberships)}
485 var alert, memberorgs = {$existingContactMemberships|@json_encode};
488 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
492 function checkExistingMemOrg () {
493 alert && alert.close && alert.close();
494 var selectedorg = $("select[name='membership_type_id[0]']").val();
495 if (selectedorg in memberorgs) {
497 endDate = memberorgs[selectedorg].membership_end_date,
498 org = $('option:selected', "select[name='membership_type_id[0]']").text();
500 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
501 andEndDate = ' ' + ts(andEndDate, {1:endDate});
505 // Mixing client-side variables with a translated string in smarty is awkward!
506 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})
507 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
508 + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}'
509 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
510 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
512 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
515 checkExistingMemOrg();
524 {if $membershipMode or $action eq 2}
526 buildAutoRenew( null, null, '{$membershipMode}');
528 function buildAutoRenew( membershipType, processorId, mode ) {
529 var action = {/literal}'{$action}'{literal};
531 //for update lets hide it when not already recurring.
533 //user can't cancel auto renew by unchecking.
534 if ( cj("#auto_renew").prop('checked' ) ) {
535 cj("#auto_renew").attr( 'readonly', true );
538 cj("#autoRenew").hide( );
542 //we should do all auto renew for cc memberships.
545 //get the required values in case missing.
546 if ( !processorId ) processorId = cj( '#payment_processor_id' ).val( );
547 if ( !membershipType ) membershipType = parseInt( cj('#membership_type_id_1').val( ) );
549 //we don't have both required values.
550 if ( !processorId || !membershipType ) {
551 cj("#auto_renew").prop('checked', false );
552 cj("#autoRenew").hide( );
557 var recurProcessors = {/literal}{$recurProcessor}{literal};
558 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
559 var currentOption = autoRenewOptions[membershipType];
561 if ( !currentOption || !recurProcessors[processorId] ) {
562 cj("#auto_renew").prop('checked', false );
563 cj("#autoRenew").hide();
567 if ( currentOption == 1 ) {
568 cj("#autoRenew").show( );
569 if ( cj("#auto_renew").attr( 'readonly' ) ) {
570 cj("#auto_renew").prop('checked', false );
571 cj("#auto_renew").removeAttr( 'readonly' );
574 else if ( currentOption == 2 ) {
575 cj("#autoRenew").show( );
576 cj("#auto_renew").prop('checked', true );
577 cj("#auto_renew").attr( 'readonly', true );
580 cj("#auto_renew").prop('checked', false );
581 cj("#autoRenew").hide( );
590 var customDataType = '{/literal}{$customDataType}{literal}';
592 // load form during form rule.
593 {/literal}{if $buildPriceSet}{literal}
594 cj( "#totalAmountORPriceSet" ).hide( );
595 cj( "#mem_type_id" ).hide( );
596 cj('#total_amount').attr("readonly", true);
597 cj( "#num_terms_row" ).hide( );
598 cj(".crm-membership-form-block-financial_type_id-mode").hide();
599 {/literal}{/if}{literal}
601 function buildAmount( priceSetId ) {
603 priceSetId = cj("#price_set_id").val( );
605 var fname = '#priceset';
607 cj('#membership_type_id_1').val(0);
608 CRM.buildCustomData(customDataType, 'null' );
610 // hide price set fields.
613 // show/hide price set amount and total amount.
614 cj( "#mem_type_id").show( );
615 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
616 cj("#price_set_id option[value='']").html( choose );
617 cj( "#totalAmountORPriceSet" ).show( );
618 cj('#total_amount').removeAttr("readonly");
619 cj( "#num_terms_row").show( );
620 cj(".crm-membership-form-block-financial_type_id-mode").show();
622 {/literal}{if $allowAutoRenew}{literal}
623 cj('#autoRenew').hide();
624 var autoRenew = cj("#auto_renew");
625 autoRenew.removeAttr( 'readOnly' );
626 autoRenew.prop('checked', false );
627 {/literal}{/if}{literal}
631 cj( "#total_amount" ).val( '' );
632 cj('#total_amount').attr("readonly", true);
634 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
636 var response = cj.ajax({
641 cj( fname ).show( ).html( response );
642 // freeze total amount text field.
644 cj( "#totalAmountORPriceSet" ).hide( );
645 cj( "#mem_type_id" ).hide( );
646 var manual = "{/literal}{ts}Manual membership and price{/ts}{literal}";
647 cj("#price_set_id option[value='']").html( manual );
648 cj( "#num_terms_row" ).hide( );
649 cj(".crm-membership-form-block-financial_type_id-mode").hide();
652 buildMaxRelated(cj('#membership_type_id_1', false).val());
654 function buildMaxRelated( memType, setDefault ) {
655 var allMemberships = {/literal}{$allMembershipInfo}{literal};
657 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
658 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
659 cj('#maxRelated').show();
660 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
662 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
663 success: function(result) {
665 if (result.result === 0) {
666 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
668 else if (result.result === 1) {
669 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
672 relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}';
673 relatable = ts(relatable, {1: result});
675 cj('#max_related').siblings('.description').append(' ' + relatable);
680 cj('#max_related').val('');
681 cj('#maxRelated').hide();
685 var lastMembershipTypes = [];
686 var optionsMembershipTypes = [];
688 // function to load custom data for selected membership types through priceset
689 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
690 var currentMembershipType = [];
692 var loadCustomData = 0;
693 if ( membershipValues ) {
694 optionsMembershipTypes = membershipValues;
698 lastMembershipTypes = [];
699 {/literal}{if $allowAutoRenew}{literal}
700 cj('#autoRenew').hide();
701 var autoRenew = cj("#auto_renew");
702 autoRenew.removeAttr( 'readOnly' );
703 autoRenew.prop('checked', false );
704 if ( autoRenewOption == 1 ) {
705 cj('#autoRenew').show();
707 else if ( autoRenewOption == 2 ) {
708 autoRenew.attr( 'readOnly', true );
709 autoRenew.prop('checked', true );
710 cj('#autoRenew').show();
712 {/literal}{/if}{literal}
715 cj("input,#priceset select,#priceset").each(function () {
716 if ( cj(this).attr('price') ) {
717 switch( cj(this).attr('type') ) {
719 if ( cj(this).prop('checked') ) {
720 eval( 'var option = ' + cj(this).attr('price') ) ;
722 var memTypeId = optionsMembershipTypes[ele];
723 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
724 currentMembershipType[count] = memTypeId;
729 cj(this).click( function( ) {
730 processMembershipPriceset();
736 if ( cj(this).prop('checked') && cj(this).val() ) {
737 var memTypeId = optionsMembershipTypes[cj(this).val()];
738 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
739 currentMembershipType[count] = memTypeId;
744 cj(this).click( function( ) {
745 processMembershipPriceset();
751 if ( cj(this).val( ) ) {
752 var memTypeId = optionsMembershipTypes[cj(this).val()];
753 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
754 currentMembershipType[count] = memTypeId;
759 cj(this).change( function( ) {
760 processMembershipPriceset();
768 for( i in currentMembershipType ) {
769 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
775 if ( !loadCustomData ) {
776 for( i in lastMembershipTypes) {
777 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
784 lastMembershipTypes = currentMembershipType;
786 // load custom data only if change in membership type selection
787 if ( !loadCustomData ) {
791 subTypeNames = currentMembershipType.join(',');
792 if ( subTypeNames.length < 1 ) {
793 subTypeNames = 'null';
796 CRM.buildCustomData( customDataType, subTypeNames );
799 function enableAmountSection( setContributionType ) {
800 if ( !cj('#record_contribution').prop('checked') ) {
801 cj('#record_contribution').click( );
802 cj('#recordContribution').show( );
804 if ( setContributionType ) {
805 cj('#financial_type_id').val(setContributionType);
810 {/if} {* closing of delete check if *}
811 {/if}{* closing of custom data if *}