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