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