CRM-21733: Adding the ability to override membership temporarily until specific date
[civicrm-core.git] / templates / CRM / Member / Form / Membership.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2017 |
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 <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>
85 </div>
86 {else}
87 <table class="form-layout-compressed">
88 {if $context neq 'standalone'}
89 <tr>
90 <td class="font-size12pt label"><strong>{ts}Member{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
91 </tr>
92 {else}
93 <td class="label">{$form.contact_id.label}</td>
94 <td>{$form.contact_id.html}</td>
95 {/if}
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>
99 {if $hasPriceSets}
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>
104 {else}
105 <div id="priceset" class="hiddenElement"></div>
106 {/if}
107 {/if}
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>
110 </td>
111 </tr>
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>
116 </td>
117 </tr>
118 {if $action eq 1}
119 <tr id="num_terms_row" class="crm-membership-form-block-num_terms">
120 <td class="label">{$form.num_terms.label}</td>
121 <td>&nbsp;{$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>
123 </td>
124 </tr>
125 {/if}
126 <tr class="crm-membership-form-block-source">
127 <td class="label">{$form.source.label}</td>
128 <td>&nbsp;{$form.source.html}<br />
129 <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td>
130 </tr>
131
132 {* CRM-7362 --add campaign to membership *}
133 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
134 campaignTrClass="crm-membership-form-block-campaign_id"}
135
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}
137 <br />
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}
140 <br />
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">
144 {$endDate|crmDate}
145 <a href="#" class="crm-hover-button action-item override-date" id="show-end-date">
146 {ts}Over-ride end date{/ts}
147 </a>
148 {help id="override_end_date"}
149 </td>
150 <td id="end-date-editable">
151 {include file="CRM/common/jcalendar.tpl" elementName=end_date}
152 <br />
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>
154 </td>
155 </tr>
156 {if !$membershipMode}
157 <tr>
158 <td class="label">{$form.is_override.label} {help id="id-status-override"}</td>
159 <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>
162 </td>
163 </tr>
164 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
165 <tr id="memberStatus_show">
166 {if $action eq 2}
167 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
168 {/if}
169 </tr>
170
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>
174 {/if}
175
176 {if $accessContribution and !$membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
177 <tr id="contri">
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>
181 </tr>
182 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
183 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
184 {/if}
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>
191 </tr>
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>
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 <div id="customData"></div>
210 {*include custom data js file*}
211 {include file="CRM/common/customData.tpl"}
212 {literal}
213 <script type="text/javascript">
214 CRM.$(function($) {
215 {/literal}
216 CRM.buildCustomData( '{$customDataType}' );
217 {if $customDataSubType}
218 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
219 {/if}
220 {literal}
221 });
222 </script>
223 {/literal}
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>
228 </div>
229 {/if}
230 {if $softCredit}
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>
234 </div>
235 {/if}
236 {/if}
237
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 -->
241
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)}
244
245 {include file="CRM/common/showHideByFieldValue.tpl"
246 trigger_field_id ="record_contribution"
247 trigger_value =""
248 target_element_id ="recordContribution"
249 target_element_type ="table-row"
250 field_type ="radio"
251 invert = 0
252 }
253 {/if}
254
255 {literal}
256 <script type="text/javascript">
257 function setPaymentBlock(mode, checkboxEvent) {
258 var memType = parseInt(cj('#membership_type_id_1').val( ));
259 var isPriceSet = 0;
260 var existingAmount = {/literal}{if !empty($onlinePendingContributionId)}1{else}0{/if}{literal};
261
262 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
263 isPriceSet = 1;
264 }
265
266 if ( !memType || isPriceSet ) {
267 return;
268 }
269
270 var allMemberships = {/literal}{$allMembershipInfo}{literal};
271 if (!mode) {
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();
278 }
279 else {
280 cj('#record_contribution').prop('checked', false);
281 cj('#recordContribution').hide();
282 }
283 }
284 {/literal}{/if}{literal}
285 }
286
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;
297 if (term) {
298 if (!taxRate) {
299 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
300 }
301 else {
302 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number
303 (allMemberships[memType]['total_amount_numeric'] * term );
304 }
305 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
306 }
307 else {
308 if (taxRate) {
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));
311 }
312 else {
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']);
317 }
318 }
319 }
320 var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
321 cj('.totaltaxAmount').html(taxMessage);
322 }
323
324
325 CRM.$(function($) {
326 var mode = {/literal}'{$membershipMode}'{literal};
327 if ( !mode ) {
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);
333 }
334 else {
335 cj('#recordContribution').hide( );
336 }
337 });
338 }
339
340 cj('#membership_type_id_1').change( function( ) {
341 setPaymentBlock(mode);
342 });
343 cj('#num_terms').change( function( ) {
344 setPaymentBlock(mode);
345 });
346 setPaymentBlock(mode);
347
348 // show/hide different contact section
349 setDifferentContactBlock();
350 cj('#is_different_contribution_contact').change( function() {
351 setDifferentContactBlock();
352 });
353
354 // give option to override end-date for auto-renew memberships
355 {/literal}
356 {if $isRecur && $endDate}
357 cj('#end-date-readonly').show();
358 cj('#end-date-editable').hide();
359 {else}
360 cj('#end-date-readonly').hide();
361 cj('#end-date-editable').show();
362 {/if}
363 {literal}
364
365 cj('#show-end-date').click( function( e ) {
366 e.preventDefault();
367 cj('#end-date-readonly').hide();
368 cj('#end-date-editable').show();
369 });
370
371 });
372
373 function setDifferentContactBlock( ) {
374 // show/hide different contact section
375 if ( cj('#is_different_contribution_contact').prop('checked') ) {
376 cj('#record-different-contact').show();
377 }
378 else {
379 cj('#record-different-contact').hide();
380 }
381 }
382
383 function showEmailOptions() {
384 {/literal}
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};
392
393 {literal}
394 var isEmailable = (isEmailEnabledForSite && (emailExists || isStandalone));
395
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();
400 }
401 else {
402 cj('#notice').hide();
403 cj('#fromEmail').hide();
404 }
405 }
406 </script>
407 <script type="text/javascript">
408
409 {/literal}{if !$membershipMode}{literal}
410 cj( "#is_override" ).change(function() {
411 showHideMemberStatus();
412 });
413
414 showHideMemberStatus();
415 function showHideMemberStatus() {
416 var isOverride = cj( "#is_override" ).val();
417 switch (isOverride) {
418 case '0':
419 cj('#memberStatus').hide();
420 cj('#memberStatus_show').show();
421 cj('#status-override-end-date').hide();
422 break;
423 case '1':
424 cj('#memberStatus').show();
425 cj('#memberStatus_show').hide();
426 cj('#status-override-end-date').hide();
427 break;
428 case '2':
429 cj('#memberStatus').show();
430 cj('#memberStatus_show').hide();
431 cj('#status-override-end-date').show();
432 break;
433 default :
434 cj('#memberStatus').hide( );
435 cj('#memberStatus_show').show( );
436 cj('#status-override-end-date').hide();
437 break;
438 }
439 }
440 {/literal}{/if}
441
442 {if $context eq 'standalone' and $isEmailEnabledForSite }
443 {literal}
444 CRM.$(function($) {
445 var $form = $("form.{/literal}{$form.formClass}{literal}");
446 $("#contact_id", $form).change(checkEmail);
447 checkEmail( );
448
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();
455 }
456 $("#email-address", $form).html(data.extra.email);
457 }
458 else {
459 $("#email-receipt, #notice", $form).hide();
460 }
461 }
462 });
463
464 {/literal}
465 {/if}
466
467 {literal}
468 //keep read only always checked.
469 CRM.$(function($) {
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 );
477 }
478 showEmailOptions();
479 });
480 }
481
482 {/literal}
483 {if !empty($existingContactMemberships)}
484
485 var alert, memberorgs = {$existingContactMemberships|@json_encode};
486
487 {literal}
488 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
489
490
491
492 function checkExistingMemOrg () {
493 alert && alert.close && alert.close();
494 var selectedorg = $("select[name='membership_type_id[0]']").val();
495 if (selectedorg in memberorgs) {
496 var andEndDate = '',
497 endDate = memberorgs[selectedorg].membership_end_date,
498 org = $('option:selected', "select[name='membership_type_id[0]']").text();
499 if (endDate) {
500 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
501 andEndDate = ' ' + ts(andEndDate, {1:endDate});
502 }
503
504 alert = CRM.alert(
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}
511 + '</a></li></ul>',
512 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
513 }
514 }
515 checkExistingMemOrg();
516 {/literal}
517 {/if}
518
519 {literal}
520
521 });
522 {/literal}
523
524 {if $membershipMode or $action eq 2}
525
526 buildAutoRenew( null, null, '{$membershipMode}');
527 {literal}
528 function buildAutoRenew( membershipType, processorId, mode ) {
529 var action = {/literal}'{$action}'{literal};
530
531 //for update lets hide it when not already recurring.
532 if ( action == 2 ) {
533 //user can't cancel auto renew by unchecking.
534 if ( cj("#auto_renew").prop('checked' ) ) {
535 cj("#auto_renew").attr( 'readonly', true );
536 }
537 else {
538 cj("#autoRenew").hide( );
539 }
540 }
541
542 //we should do all auto renew for cc memberships.
543 if ( !mode ) return;
544
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( ) );
548
549 //we don't have both required values.
550 if ( !processorId || !membershipType ) {
551 cj("#auto_renew").prop('checked', false );
552 cj("#autoRenew").hide( );
553 showEmailOptions();
554 return;
555 }
556
557 var recurProcessors = {/literal}{$recurProcessor}{literal};
558 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
559 var currentOption = autoRenewOptions[membershipType];
560
561 if ( !currentOption || !recurProcessors[processorId] ) {
562 cj("#auto_renew").prop('checked', false );
563 cj("#autoRenew").hide();
564 return;
565 }
566
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' );
572 }
573 }
574 else if ( currentOption == 2 ) {
575 cj("#autoRenew").show( );
576 cj("#auto_renew").prop('checked', true );
577 cj("#auto_renew").attr( 'readonly', true );
578 }
579 else {
580 cj("#auto_renew").prop('checked', false );
581 cj("#autoRenew").hide( );
582 }
583 showEmailOptions();
584 }
585 {/literal}
586 {/if}
587
588 {literal}
589
590 var customDataType = '{/literal}{$customDataType}{literal}';
591
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}
600
601 function buildAmount( priceSetId ) {
602 if ( !priceSetId ) {
603 priceSetId = cj("#price_set_id").val( );
604 }
605 var fname = '#priceset';
606 if ( !priceSetId ) {
607 cj('#membership_type_id_1').val(0);
608 CRM.buildCustomData(customDataType, 'null' );
609
610 // hide price set fields.
611 cj( fname ).hide( );
612
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();
621
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}
628 return;
629 }
630
631 cj( "#total_amount" ).val( '' );
632 cj('#total_amount').attr("readonly", true);
633
634 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
635
636 var response = cj.ajax({
637 url: dataUrl,
638 async: false
639 }).responseText;
640
641 cj( fname ).show( ).html( response );
642 // freeze total amount text field.
643
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();
650 }
651
652 buildMaxRelated(cj('#membership_type_id_1', false).val());
653
654 function buildMaxRelated( memType, setDefault ) {
655 var allMemberships = {/literal}{$allMembershipInfo}{literal};
656
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};
661 if (cid) {
662 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
663 success: function(result) {
664 var relatable;
665 if (result.result === 0) {
666 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
667 }
668 else if (result.result === 1) {
669 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
670 }
671 else {
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});
674 }
675 cj('#max_related').siblings('.description').append(' ' + relatable);
676 }
677 });
678 }
679 } else {
680 cj('#max_related').val('');
681 cj('#maxRelated').hide();
682 }
683 }
684
685 var lastMembershipTypes = [];
686 var optionsMembershipTypes = [];
687
688 // function to load custom data for selected membership types through priceset
689 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
690 var currentMembershipType = [];
691 var count = 0;
692 var loadCustomData = 0;
693 if ( membershipValues ) {
694 optionsMembershipTypes = membershipValues;
695 }
696
697 if ( reload ) {
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();
706 }
707 else if ( autoRenewOption == 2 ) {
708 autoRenew.attr( 'readOnly', true );
709 autoRenew.prop('checked', true );
710 cj('#autoRenew').show();
711 }
712 {/literal}{/if}{literal}
713 }
714
715 cj("input,#priceset select,#priceset").each(function () {
716 if ( cj(this).attr('price') ) {
717 switch( cj(this).attr('type') ) {
718 case 'checkbox':
719 if ( cj(this).prop('checked') ) {
720 eval( 'var option = ' + cj(this).attr('price') ) ;
721 var ele = option[0];
722 var memTypeId = optionsMembershipTypes[ele];
723 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
724 currentMembershipType[count] = memTypeId;
725 count++;
726 }
727 }
728 if ( reload ) {
729 cj(this).click( function( ) {
730 processMembershipPriceset();
731 });
732 }
733 break;
734
735 case 'radio':
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;
740 count++;
741 }
742 }
743 if ( reload ) {
744 cj(this).click( function( ) {
745 processMembershipPriceset();
746 });
747 }
748 break;
749
750 case 'select-one':
751 if ( cj(this).val( ) ) {
752 var memTypeId = optionsMembershipTypes[cj(this).val()];
753 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
754 currentMembershipType[count] = memTypeId;
755 count++;
756 }
757 }
758 if ( reload ) {
759 cj(this).change( function( ) {
760 processMembershipPriceset();
761 });
762 }
763 break;
764 }
765 }
766 });
767
768 for( i in currentMembershipType ) {
769 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
770 loadCustomData = 1;
771 break;
772 }
773 }
774
775 if ( !loadCustomData ) {
776 for( i in lastMembershipTypes) {
777 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
778 loadCustomData = 1;
779 break;
780 }
781 }
782 }
783
784 lastMembershipTypes = currentMembershipType;
785
786 // load custom data only if change in membership type selection
787 if ( !loadCustomData ) {
788 return;
789 }
790
791 subTypeNames = currentMembershipType.join(',');
792 if ( subTypeNames.length < 1 ) {
793 subTypeNames = 'null';
794 }
795
796 CRM.buildCustomData( customDataType, subTypeNames );
797 }
798
799 function enableAmountSection( setContributionType ) {
800 if ( !cj('#record_contribution').prop('checked') ) {
801 cj('#record_contribution').click( );
802 cj('#recordContribution').show( );
803 }
804 if ( setContributionType ) {
805 cj('#financial_type_id').val(setContributionType);
806 }
807 }
808 </script>
809 {/literal}
810 {/if} {* closing of delete check if *}
811 {/if}{* closing of custom data if *}