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