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