Merge pull request #20136 from eileenmcnaughton/dom
[civicrm-core.git] / templates / CRM / Member / Form / Membership.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
1188c7a8 3 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 4 | |
1188c7a8
TO
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 |
6a488035
TO
8 +--------------------------------------------------------------------+
9*}
10{* this template is used for adding/editing/deleting memberships for a contact *}
abdb0d27 11{if $isRecur}
6a488035 12 <div class="messages status no-popup">
34d6cec4 13 {icon icon="fa-info-circle"}{/icon}
abdb0d27 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>
4c98c2ab 15 {if $cancelAutoRenew}<p>{ts 1=$cancelAutoRenew}To stop the automatic renewal:
abdb0d27
WM
16 <a href="%1">Cancel auto-renew</a>
17 {/ts}</p>{/if}
6a488035
TO
18 </div>
19{/if}
20<div class="spacer"></div>
39082712 21{if $priceSetId}
6a488035
TO
22 {include file="CRM/Price/Form/PriceSet.tpl" context="standalone" extends="Membership"}
23 {literal}
24 <script type="text/javascript">
3cc60a06 25 CRM.$(function($) {
ae8f569f 26 var membershipValues = [];
6a488035
TO
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">
34d6cec4 45 {icon icon="fa-info-circle"}{/icon}
6a488035
TO
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}
6a488035 49 {if $membershipMode}
f6eedce7 50 <div class="help">
6a488035
TO
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">
67121256
PN
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}
13a3d214 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>
67121256
PN
63 </div>
64 {/if}
6a488035
TO
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">
34d6cec4 68 {icon icon="fa-info-circle"}{/icon}
59c798c9 69 {$deleteMessage}
6a488035
TO
70 </div>
71 {else}
72 <table class="form-layout-compressed">
ac0ef1dc 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>
6a488035
TO
77 <tr class="crm-membership-form-block-membership_type_id">
78 <td class="label">{$form.membership_type_id.label}</td>
595ae4d0
WM
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>
6a488035
TO
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 />
5384bd2f 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>
6a488035
TO
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 />
a67d7de7 105 <span class="description">{ts}Maximum number of related memberships (leave blank for unlimited).{/ts} <span id="eligibleRelated"></span></span>
6a488035
TO
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
59c798c9 126 <tr class="crm-membership-form-block-join_date"><td class="label">{$form.join_date.label}</td><td>{$form.join_date.html}
6a488035
TO
127 <br />
128 <span class="description">{ts}When did this contact first become a member?{/ts}</span></td></tr>
59c798c9 129 <tr class="crm-membership-form-block-start_date"><td class="label">{$form.start_date.label}</td><td>{$form.start_date.html}
6a488035
TO
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>
e4444728
DG
133 <td id="end-date-readonly">
134 {$endDate|crmDate}
135 <a href="#" class="crm-hover-button action-item override-date" id="show-end-date">
580eab37 136 {ts}Override end date{/ts}
e4444728
DG
137 </a>
138 {help id="override_end_date"}
139 </td>
140 <td id="end-date-editable">
59c798c9 141 {$form.end_date.html}
6a488035 142 <br />
e4444728
DG
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>
378ea9fc 146 {if !$membershipMode}
e136f704
O
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>
6a488035
TO
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 />
e136f704 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>
6a488035 164 {/if}
186a737c 165
f8cb4d16 166 {if $accessContribution and !$membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit))}
6a488035 167 <tr id="contri">
f8cb4d16 168 <td class="label">{$form.record_contribution.label}</td>
6a488035
TO
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>
b58b2053 174 {/if}
c3ec2f80 175 {include file="CRM/Member/Form/MembershipCommon.tpl"}
8c80f3f9 176 {if $emailExists and $isEmailEnabledForSite}
6a488035 177 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
cbc5bc5c
WM
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>
6a488035 186 </tr>
cbc5bc5c 187 {elseif $context eq 'standalone' and $isEmailEnabledForSite}
6a488035 188 <tr id="email-receipt" style="display:none;">
cbc5bc5c
WM
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>
6a488035
TO
197 </tr>
198 {/if}
beac1417 199 <tr id="fromEmail" style="display: none" class="crm-contactEmail-form-block-fromEmailAddress crm-email-element">
6a488035 200 <td class="label">{$form.from_email_address.label}</td>
beac1417 201 <td>{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Email.hlp" isAdmin=$isAdmin}</td>
6a488035
TO
202 </tr>
203 <tr id='notice' style="display:none;">
186a737c 204 <td class="label">{$form.receipt_text.label}</td>
6a488035 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>
186a737c 206 {$form.receipt_text.html|crmAddClass:huge}</td>
6a488035
TO
207 </tr>
208 </table>
67bb6495 209 {include file="CRM/common/customDataBlock.tpl"}
6a488035 210 {if $accessContribution and $action eq 2 and $rows.0.contribution_id}
eb3cfcd6 211 <div class="crm-accordion-wrapper">
64c1e6ea 212 <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div>
669fc25e
CR
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>
eb3cfcd6 240 </div>
241 {/if}
242 {if $softCredit}
243 <div class="crm-accordion-wrapper">
64c1e6ea 244 <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div>
eb3cfcd6 245 <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div>
246 </div>
6a488035
TO
247 {/if}
248 {/if}
249
6a488035
TO
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 *}
f8cb4d16 254 {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id)}
6a488035
TO
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 }
6a488035
TO
264 {/if}
265
266 {literal}
267 <script type="text/javascript">
2c407361 268 function setPaymentBlock(mode, checkboxEvent) {
19c05caa 269 if (cj('#price_set_id').length > 0 && cj('#price_set_id').val()) {
270 return;
2c407361 271 }
19c05caa 272 var membershipTypeID = parseInt(cj('#membership_type_id_1').val());
273 if (!membershipTypeID) {
2c407361
CW
274 return;
275 }
276
277 var allMemberships = {/literal}{$allMembershipInfo}{literal};
19c05caa 278 membershipType = allMemberships[membershipTypeID];
2b339b18 279 if (!mode) {
2c407361
CW
280 //check the record_contribution checkbox if membership is a paid one
281 {/literal}{if $action eq 1}{literal}
282 if (!checkboxEvent) {
19c05caa 283 if (membershipType['total_amount_numeric'] > 0) {
2c407361
CW
284 cj('#record_contribution').prop('checked','checked');
285 cj('#recordContribution').show();
286 }
287 else {
288 cj('#record_contribution').prop('checked', false);
289 cj('#recordContribution').hide();
290 }
291 }
292 {/literal}{/if}{literal}
293 }
294
295 // skip this for test and live modes because financial type is set automatically
19c05caa 296 cj("#financial_type_id").val(membershipType['financial_type_id']);
5af114ec
FW
297 // Get the number of terms from the form, default to 1 if no num_terms element.
298 var term = cj('#num_terms').val() || 1;
8838f818 299 var taxTerm = {/literal}{$taxTerm|@json_encode}{literal};
9d3a6f9f 300 var currency = {/literal}{$currency_symbol|@json_encode}{literal};
0139cfb4 301 var taxExclusiveAmount = membershipType['total_amount_numeric'] * term;
f837be9e 302 var taxAmount = (membershipType['tax_rate']/100)*taxExclusiveAmount;
4f7df658 303 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
0139cfb4 304 cj("#total_amount").val(CRM.formatMoney(taxExclusiveAmount + taxAmount, true));
118838c0 305
f837be9e 306 var taxMessage = taxAmount > 0 ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
46611472 307 cj('.totaltaxAmount').html(taxMessage);
2c407361
CW
308 }
309
310
3cc60a06 311 CRM.$(function($) {
6a488035
TO
312 var mode = {/literal}'{$membershipMode}'{literal};
313 if ( !mode ) {
314 // Offline form (mode = false) has the record_contribution checkbox
315 cj('#record_contribution').click( function( ) {
8539f25d 316 if ( cj(this).prop('checked') ) {
6a488035
TO
317 cj('#recordContribution').show( );
318 setPaymentBlock( false, true);
319 }
320 else {
321 cj('#recordContribution').hide( );
322 }
323 });
324 }
325
326 cj('#membership_type_id_1').change( function( ) {
327 setPaymentBlock(mode);
328 });
329 cj('#num_terms').change( function( ) {
330 setPaymentBlock(mode);
331 });
6a488035
TO
332
333 // show/hide different contact section
334 setDifferentContactBlock();
335 cj('#is_different_contribution_contact').change( function() {
336 setDifferentContactBlock();
337 });
186a737c 338
595ae4d0
WM
339 // give option to override membership type for auto-renew memberships - dev/core#1331
340 {/literal}
341 {if $isRecur}
342 cj('#membership_type_id_0-readonly').text(cj('#membership_type_id_0 option:selected').text());
343 cj('#membership_type_id_1-readonly').text(cj('#membership_type_id_1 option:selected').text());
344 cj('#mem_type_id-readonly').show();
345 cj('#mem_type_id-editable').hide();
346 {else}
347 cj('#mem_type_id-readonly').hide();
348 cj('#mem_type_id-editable').show();
349 {/if}
350 {literal}
351
352 cj('#show-mem-type').click( function( e ) {
353 e.preventDefault();
354 cj('#mem_type_id-readonly').hide();
355 cj('#mem_type_id-editable').show();
356 });
357
e4444728
DG
358 // give option to override end-date for auto-renew memberships
359 {/literal}
360 {if $isRecur && $endDate}
361 cj('#end-date-readonly').show();
362 cj('#end-date-editable').hide();
363 {else}
364 cj('#end-date-readonly').hide();
365 cj('#end-date-editable').show();
366 {/if}
367 {literal}
368
369 cj('#show-end-date').click( function( e ) {
370 e.preventDefault();
371 cj('#end-date-readonly').hide();
372 cj('#end-date-editable').show();
373 });
374
6a488035
TO
375 });
376
377 function setDifferentContactBlock( ) {
378 // show/hide different contact section
8539f25d 379 if ( cj('#is_different_contribution_contact').prop('checked') ) {
6a488035
TO
380 cj('#record-different-contact').show();
381 }
382 else {
383 cj('#record-different-contact').hide();
384 }
385 }
186a737c 386
8c80f3f9 387 function showEmailOptions() {
388 {/literal}
389 // @todo emailExists refers to the primary contact for the page.
390 // elsewhere some script determines if there is a paying contact the
391 // email should go to instead (e.g gift membership). This should be checked for here
392 // and that merged into that code as currently behaviour is inconsistent.
fa9a2fb7
SM
393 var emailExists = {$emailExists|json_encode};
394 var isStandalone = {if $context == 'standalone'}true{else}false{/if};
5817a4e7 395 var isEmailEnabledForSite = {if $isEmailEnabledForSite}true{else}false{/if};
6a488035 396
8c80f3f9 397 {literal}
398 var isEmailable = (isEmailEnabledForSite && (emailExists || isStandalone));
6a488035 399
8c80f3f9 400 if (isEmailable && cj('#send_receipt').prop('checked') && !cj('#auto_renew').prop('checked')) {
401 // Hide extra message and from email for recurring as they cannot be stored until use.
402 cj('#notice').show();
403 cj('#fromEmail').show();
404 }
405 else {
406 cj('#notice').hide();
407 cj('#fromEmail').hide();
408 }
409 }
410 </script>
6a488035
TO
411 <script type="text/javascript">
412
413 {/literal}{if !$membershipMode}{literal}
e136f704
O
414 cj( "#is_override" ).change(function() {
415 showHideMemberStatus();
416 });
417
6a488035
TO
418 showHideMemberStatus();
419 function showHideMemberStatus() {
e136f704
O
420 var isOverride = cj( "#is_override" ).val();
421 switch (isOverride) {
422 case '0':
423 cj('#memberStatus').hide();
424 cj('#memberStatus_show').show();
425 cj('#status-override-end-date').hide();
426 break;
427 case '1':
428 cj('#memberStatus').show();
429 cj('#memberStatus_show').hide();
430 cj('#status-override-end-date').hide();
431 break;
432 case '2':
433 cj('#memberStatus').show();
434 cj('#memberStatus_show').hide();
435 cj('#status-override-end-date').show();
436 break;
437 default :
438 cj('#memberStatus').hide( );
439 cj('#memberStatus_show').show( );
440 cj('#status-override-end-date').hide();
441 break;
6a488035
TO
442 }
443 }
444 {/literal}{/if}
1ed3da9e 445
8c80f3f9 446 {if $context eq 'standalone' and $isEmailEnabledForSite }
6a488035 447 {literal}
3cc60a06 448 CRM.$(function($) {
b50fdacc 449 var $form = $("form.{/literal}{$form.formClass}{literal}");
74dd0d90 450 $("#contact_id", $form).change(checkEmail);
6a488035 451 checkEmail( );
6a488035 452
74dd0d90
CW
453 function checkEmail( ) {
454 var data = $("#contact_id", $form).select2('data');
455 if (data && data.extra && data.extra.email && data.extra.email.length) {
456 $("#email-receipt", $form).show();
457 if ($("#send_receipt", $form).is(':checked')) {
458 $("#notice", $form).show();
6a488035 459 }
74dd0d90
CW
460 $("#email-address", $form).html(data.extra.email);
461 }
462 else {
463 $("#email-receipt, #notice", $form).hide();
464 }
6a488035 465 }
74dd0d90 466 });
6a488035 467
6a488035
TO
468 {/literal}
469 {/if}
470
471 {literal}
472 //keep read only always checked.
3cc60a06 473 CRM.$(function($) {
b50fdacc 474 var $form = $("form.{/literal}{$form.formClass}{literal}");
6a488035
TO
475 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
476 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
477 if ( allowAutoRenew || alreadyAutoRenew ) {
74dd0d90
CW
478 $( "#auto_renew" ).click(function( ) {
479 if ( $(this).attr( 'readonly' ) ) {
480 $(this).prop('checked', true );
6a488035 481 }
8c80f3f9 482 showEmailOptions();
6a488035
TO
483 });
484 }
74dd0d90
CW
485
486 {/literal}
487 {if !empty($existingContactMemberships)}
488
489 var alert, memberorgs = {$existingContactMemberships|@json_encode};
490
491 {literal}
492 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
493
494
495
496 function checkExistingMemOrg () {
497 alert && alert.close && alert.close();
498 var selectedorg = $("select[name='membership_type_id[0]']").val();
499 if (selectedorg in memberorgs) {
500 var andEndDate = '',
501 endDate = memberorgs[selectedorg].membership_end_date,
502 org = $('option:selected', "select[name='membership_type_id[0]']").text();
503 if (endDate) {
ec2b84a1
CW
504 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
505 andEndDate = ' ' + ts(andEndDate, {1:endDate});
74dd0d90
CW
506 }
507
508 alert = CRM.alert(
509 // Mixing client-side variables with a translated string in smarty is awkward!
824530a5 510 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})
74dd0d90 511 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
ec2b84a1 512 + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}'
74dd0d90
CW
513 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
514 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
515 + '</a></li></ul>',
ec2b84a1 516 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
74dd0d90
CW
517 }
518 }
519 checkExistingMemOrg();
520 {/literal}
521 {/if}
522
523 {literal}
524
6a488035
TO
525 });
526 {/literal}
527
528 {if $membershipMode or $action eq 2}
38f6574d 529 buildAutoRenew( null, null, '{$membershipMode}');
530 {/if}
8c80f3f9 531 {literal}
4cc824c6 532 function buildAutoRenew(membershipTypeID, processorId, mode ) {
6a488035
TO
533 var action = {/literal}'{$action}'{literal};
534
535 //for update lets hide it when not already recurring.
8838f818 536 if (action == 2) {
6a488035 537 //user can't cancel auto renew by unchecking.
8838f818
CW
538 if (cj("#auto_renew").prop('checked')) {
539 cj("#auto_renew").attr('readonly', true);
6a488035
TO
540 }
541 else {
542 cj("#autoRenew").hide( );
543 }
544 }
545
546 //we should do all auto renew for cc memberships.
8838f818
CW
547 if (!mode) {
548 return;
549 }
6a488035
TO
550
551 //get the required values in case missing.
8838f818
CW
552 if (!processorId) {
553 processorId = cj( '#payment_processor_id' ).val( );
554 }
cfab7c9d 555 if (!membershipTypeID) {
556 membershipTypeID = parseInt( cj('#membership_type_id_1').val( ) );
8838f818 557 }
6a488035
TO
558
559 //we don't have both required values.
cfab7c9d 560 if (!processorId || !membershipTypeID) {
8838f818
CW
561 cj("#auto_renew").prop('checked', false);
562 cj("#autoRenew").hide();
8c80f3f9 563 showEmailOptions();
6a488035
TO
564 return;
565 }
566
567 var recurProcessors = {/literal}{$recurProcessor}{literal};
568 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
cfab7c9d 569 var currentOption = autoRenewOptions[membershipTypeID];
6a488035 570
8838f818 571 if (!currentOption || !recurProcessors[processorId]) {
8539f25d 572 cj("#auto_renew").prop('checked', false );
8c80f3f9 573 cj("#autoRenew").hide();
6a488035
TO
574 return;
575 }
576
8838f818
CW
577 if (currentOption == 1) {
578 cj("#autoRenew").show();
579 if (cj("#auto_renew").attr('readonly')) {
580 cj("#auto_renew").prop('checked', false).removeAttr('readonly');
6a488035
TO
581 }
582 }
583 else if ( currentOption == 2 ) {
8838f818
CW
584 cj("#autoRenew").show();
585 cj("#auto_renew").prop('checked', true).attr('readonly', true);
6a488035
TO
586 }
587 else {
8838f818 588 cj("#auto_renew").prop('checked', false);
6a488035
TO
589 cj("#autoRenew").hide( );
590 }
8c80f3f9 591 showEmailOptions();
6a488035 592 }
6a488035 593
8838f818 594 var customDataType = {/literal}{$customDataType|@json_encode}{literal};
6a488035
TO
595
596 // load form during form rule.
597 {/literal}{if $buildPriceSet}{literal}
8838f818
CW
598 cj("#totalAmountORPriceSet, #mem_type_id, #num_terms_row, .crm-membership-form-block-financial_type_id-mode").hide();
599 cj('#total_amount').attr("readonly", true);
6a488035
TO
600 {/literal}{/if}{literal}
601
602 function buildAmount( priceSetId ) {
8838f818
CW
603 if (!priceSetId) {
604 priceSetId = cj("#price_set_id").val();
605 }
6a488035
TO
606 var fname = '#priceset';
607 if ( !priceSetId ) {
608 cj('#membership_type_id_1').val(0);
62e185a9 609 CRM.buildCustomData(customDataType, null);
6a488035
TO
610
611 // hide price set fields.
612 cj( fname ).hide( );
613
614 // show/hide price set amount and total amount.
615 cj( "#mem_type_id").show( );
8838f818 616 var choose = "{/literal}{ts escape='js'}Choose price set{/ts}{literal}";
5384bd2f 617 cj("#price_set_id option[value='']").html( choose );
6a488035
TO
618 cj( "#totalAmountORPriceSet" ).show( );
619 cj('#total_amount').removeAttr("readonly");
620 cj( "#num_terms_row").show( );
5a9c4d4a 621 cj(".crm-membership-form-block-financial_type_id-mode").show();
6a488035
TO
622
623 {/literal}{if $allowAutoRenew}{literal}
8838f818
CW
624 cj('#autoRenew').hide();
625 cj("#auto_renew").removeAttr('readOnly').prop('checked', false );
6a488035
TO
626 {/literal}{/if}{literal}
627 return;
628 }
629
8838f818 630 cj( "#total_amount" ).val('').attr("readonly", true);
6a488035
TO
631
632 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
633
634 var response = cj.ajax({
635 url: dataUrl,
636 async: false
637 }).responseText;
638
639 cj( fname ).show( ).html( response );
640 // freeze total amount text field.
641
642 cj( "#totalAmountORPriceSet" ).hide( );
643 cj( "#mem_type_id" ).hide( );
8838f818 644 var manual = "{/literal}{ts escape='js'}Manual membership and price{/ts}{literal}";
5384bd2f 645 cj("#price_set_id option[value='']").html( manual );
6a488035 646 cj( "#num_terms_row" ).hide( );
5a9c4d4a 647 cj(".crm-membership-form-block-financial_type_id-mode").hide();
6a488035
TO
648 }
649
650 buildMaxRelated(cj('#membership_type_id_1', false).val());
651
652 function buildMaxRelated( memType, setDefault ) {
653 var allMemberships = {/literal}{$allMembershipInfo}{literal};
654
655 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
656 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
657 cj('#maxRelated').show();
f1d5011f
CW
658 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
659 if (cid) {
660 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
c9c41397 661 success: function(result) {
ec2b84a1
CW
662 var relatable;
663 if (result.result === 0) {
664 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
c9c41397 665 }
ec2b84a1
CW
666 else if (result.result === 1) {
667 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
c9c41397 668 }
ec2b84a1
CW
669 else {
670 relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}';
671 relatable = ts(relatable, {1: result});
672 }
a67d7de7 673 cj('#eligibleRelated').text(relatable);
c9c41397 674 }
675 });
676 }
6a488035
TO
677 } else {
678 cj('#max_related').val('');
679 cj('#maxRelated').hide();
680 }
681 }
682
ae8f569f
CW
683 var lastMembershipTypes = [];
684 var optionsMembershipTypes = [];
6a488035
TO
685
686 // function to load custom data for selected membership types through priceset
687 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
ae8f569f 688 var currentMembershipType = [];
6a488035
TO
689 var count = 0;
690 var loadCustomData = 0;
691 if ( membershipValues ) {
692 optionsMembershipTypes = membershipValues;
693 }
694
695 if ( reload ) {
ae8f569f 696 lastMembershipTypes = [];
6a488035
TO
697 {/literal}{if $allowAutoRenew}{literal}
698 cj('#autoRenew').hide();
699 var autoRenew = cj("#auto_renew");
8838f818
CW
700 autoRenew.removeAttr('readOnly').prop('checked', false );
701 if (autoRenewOption == 1) {
6a488035
TO
702 cj('#autoRenew').show();
703 }
8838f818
CW
704 else if (autoRenewOption == 2) {
705 autoRenew.attr('readOnly', true).prop('checked', true );
6a488035
TO
706 cj('#autoRenew').show();
707 }
708 {/literal}{/if}{literal}
709 }
710
711 cj("input,#priceset select,#priceset").each(function () {
712 if ( cj(this).attr('price') ) {
713 switch( cj(this).attr('type') ) {
714 case 'checkbox':
8539f25d 715 if ( cj(this).prop('checked') ) {
6a488035
TO
716 eval( 'var option = ' + cj(this).attr('price') ) ;
717 var ele = option[0];
718 var memTypeId = optionsMembershipTypes[ele];
719 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
720 currentMembershipType[count] = memTypeId;
721 count++;
722 }
723 }
724 if ( reload ) {
725 cj(this).click( function( ) {
726 processMembershipPriceset();
727 });
728 }
729 break;
730
731 case 'radio':
8539f25d 732 if ( cj(this).prop('checked') && cj(this).val() ) {
6a488035
TO
733 var memTypeId = optionsMembershipTypes[cj(this).val()];
734 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
735 currentMembershipType[count] = memTypeId;
736 count++;
737 }
738 }
739 if ( reload ) {
740 cj(this).click( function( ) {
741 processMembershipPriceset();
742 });
743 }
744 break;
745
746 case 'select-one':
747 if ( cj(this).val( ) ) {
748 var memTypeId = optionsMembershipTypes[cj(this).val()];
749 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
750 currentMembershipType[count] = memTypeId;
751 count++;
752 }
753 }
754 if ( reload ) {
755 cj(this).change( function( ) {
756 processMembershipPriceset();
757 });
758 }
759 break;
760 }
761 }
762 });
763
764 for( i in currentMembershipType ) {
765 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
766 loadCustomData = 1;
767 break;
768 }
769 }
770
771 if ( !loadCustomData ) {
772 for( i in lastMembershipTypes) {
773 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
774 loadCustomData = 1;
775 break;
776 }
777 }
778 }
779
780 lastMembershipTypes = currentMembershipType;
781
782 // load custom data only if change in membership type selection
783 if ( !loadCustomData ) {
784 return;
785 }
786
787 subTypeNames = currentMembershipType.join(',');
788 if ( subTypeNames.length < 1 ) {
4929bbc2 789 subTypeNames = null;
6a488035
TO
790 }
791
62e185a9 792 CRM.buildCustomData(customDataType, subTypeNames);
6a488035
TO
793 }
794
795 function enableAmountSection( setContributionType ) {
8539f25d 796 if ( !cj('#record_contribution').prop('checked') ) {
6a488035
TO
797 cj('#record_contribution').click( );
798 cj('#recordContribution').show( );
799 }
800 if ( setContributionType ) {
801 cj('#financial_type_id').val(setContributionType);
802 }
803 }
804 </script>
805 {/literal}
806 {/if} {* closing of delete check if *}
807{/if}{* closing of custom data if *}