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