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