CRM-20264 support card_type_id and pan_truncation in all backoffice form
[civicrm-core.git] / templates / CRM / Member / Form / Membership.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2017 |
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 class="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 {/if}
175 {include file="CRM/Member/Form/MembershipCommon.tpl"}
176
177 {if $emailExists and $isEmailEnabledForSite}
178 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
179 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
180 <span class="description">{ts 1=$emailExists}Automatically email a membership confirmation and receipt to %1? OR if the payment is from a different contact, this email will only go to them.{/ts}</span></td>
181 <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span>
182 </tr>
183 {elseif $context eq 'standalone' and $isEmailEnabledForSite}
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 <span class="auto-renew-text">{ts}For auto-renewing memberships the emails are sent when each payment is received{/ts}</span>
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 {/if}
245
246 {literal}
247 <script type="text/javascript">
248 function setPaymentBlock(mode, checkboxEvent) {
249 var memType = parseInt(cj('#membership_type_id_1').val( ));
250 var isPriceSet = 0;
251 var existingAmount = {/literal}{if !empty($onlinePendingContributionId)}1{else}0{/if}{literal};
252
253 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
254 isPriceSet = 1;
255 }
256
257 if ( !memType || isPriceSet ) {
258 return;
259 }
260
261 var allMemberships = {/literal}{$allMembershipInfo}{literal};
262 if (!mode) {
263 //check the record_contribution checkbox if membership is a paid one
264 {/literal}{if $action eq 1}{literal}
265 if (!checkboxEvent) {
266 if (allMemberships[memType]['total_amount_numeric'] > 0) {
267 cj('#record_contribution').prop('checked','checked');
268 cj('#recordContribution').show();
269 }
270 else {
271 cj('#record_contribution').prop('checked', false);
272 cj('#recordContribution').hide();
273 }
274 }
275 {/literal}{/if}{literal}
276 }
277
278 // skip this for test and live modes because financial type is set automatically
279 cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']);
280 var term = cj('#num_terms').val();
281 var taxRates = '{/literal}{$taxRates}{literal}';
282 var taxTerm = '{/literal}{$taxTerm}{literal}';
283 var taxRates = JSON.parse(taxRates);
284 var taxRate = taxRates[allMemberships[memType]['financial_type_id']];
285 var currency = '{/literal}{$currency}{literal}';
286 var taxAmount = (taxRate/100)*allMemberships[memType]['total_amount_numeric'];
287 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
288 if (term) {
289 if (!taxRate) {
290 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
291 }
292 else {
293 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number
294 (allMemberships[memType]['total_amount_numeric'] * term );
295 }
296 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
297 }
298 else {
299 if (taxRate) {
300 var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
301 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
302 }
303 else {
304 var feeTotal = allMemberships[memType]['total_amount'];
305 if (!existingAmount) {
306 // CRM-16680 don't set amount if there is an existing contribution.
307 cj("#total_amount").val(allMemberships[memType]['total_amount']);
308 }
309 }
310 }
311 var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
312 cj('.totaltaxAmount').html(taxMessage);
313 }
314
315
316 CRM.$(function($) {
317 var mode = {/literal}'{$membershipMode}'{literal};
318 if ( !mode ) {
319 // Offline form (mode = false) has the record_contribution checkbox
320 cj('#record_contribution').click( function( ) {
321 if ( cj(this).prop('checked') ) {
322 cj('#recordContribution').show( );
323 setPaymentBlock( false, true);
324 }
325 else {
326 cj('#recordContribution').hide( );
327 }
328 });
329 }
330
331 cj('#membership_type_id_1').change( function( ) {
332 setPaymentBlock(mode);
333 });
334 cj('#num_terms').change( function( ) {
335 setPaymentBlock(mode);
336 });
337 setPaymentBlock(mode);
338
339 // show/hide different contact section
340 setDifferentContactBlock();
341 cj('#is_different_contribution_contact').change( function() {
342 setDifferentContactBlock();
343 });
344
345 // give option to override end-date for auto-renew memberships
346 {/literal}
347 {if $isRecur && $endDate}
348 cj('#end-date-readonly').show();
349 cj('#end-date-editable').hide();
350 {else}
351 cj('#end-date-readonly').hide();
352 cj('#end-date-editable').show();
353 {/if}
354 {literal}
355
356 cj('#show-end-date').click( function( e ) {
357 e.preventDefault();
358 cj('#end-date-readonly').hide();
359 cj('#end-date-editable').show();
360 });
361
362 });
363
364 function setDifferentContactBlock( ) {
365 // show/hide different contact section
366 if ( cj('#is_different_contribution_contact').prop('checked') ) {
367 cj('#record-different-contact').show();
368 }
369 else {
370 cj('#record-different-contact').hide();
371 }
372 }
373
374 function showEmailOptions() {
375 {/literal}
376 // @todo emailExists refers to the primary contact for the page.
377 // elsewhere some script determines if there is a paying contact the
378 // email should go to instead (e.g gift membership). This should be checked for here
379 // and that merged into that code as currently behaviour is inconsistent.
380 var emailExists = '{$emailExists}';
381 var isStandalone = ('{$context}' == 'standalone');
382 var isEmailEnabledForSite = {if $isEmailEnabledForSite}true{else}false{/if};
383
384 {literal}
385 var isEmailable = (isEmailEnabledForSite && (emailExists || isStandalone));
386
387 if (isEmailable && cj('#send_receipt').prop('checked') && !cj('#auto_renew').prop('checked')) {
388 // Hide extra message and from email for recurring as they cannot be stored until use.
389 cj('#notice').show();
390 cj('#fromEmail').show();
391 }
392 else {
393 cj('#notice').hide();
394 cj('#fromEmail').hide();
395 }
396 }
397 </script>
398 <script type="text/javascript">
399
400 {/literal}{if !$membershipMode}{literal}
401 showHideMemberStatus();
402 function showHideMemberStatus() {
403 if ( cj( "#is_override" ).prop('checked') ) {
404 cj('#memberStatus').show( );
405 cj('#memberStatus_show').hide( );
406 }
407 else {
408 cj('#memberStatus').hide( );
409 cj('#memberStatus_show').show( );
410 }
411 }
412 {/literal}{/if}
413
414 {if $context eq 'standalone' and $isEmailEnabledForSite }
415 {literal}
416 CRM.$(function($) {
417 var $form = $("form.{/literal}{$form.formClass}{literal}");
418 $("#contact_id", $form).change(checkEmail);
419 checkEmail( );
420
421 function checkEmail( ) {
422 var data = $("#contact_id", $form).select2('data');
423 if (data && data.extra && data.extra.email && data.extra.email.length) {
424 $("#email-receipt", $form).show();
425 if ($("#send_receipt", $form).is(':checked')) {
426 $("#notice", $form).show();
427 }
428 $("#email-address", $form).html(data.extra.email);
429 }
430 else {
431 $("#email-receipt, #notice", $form).hide();
432 }
433 }
434 });
435
436 {/literal}
437 {/if}
438
439 {literal}
440 //keep read only always checked.
441 CRM.$(function($) {
442 var $form = $("form.{/literal}{$form.formClass}{literal}");
443 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
444 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
445 if ( allowAutoRenew || alreadyAutoRenew ) {
446 $( "#auto_renew" ).click(function( ) {
447 if ( $(this).attr( 'readonly' ) ) {
448 $(this).prop('checked', true );
449 }
450 showEmailOptions();
451 });
452 }
453
454 {/literal}
455 {if !empty($existingContactMemberships)}
456
457 var alert, memberorgs = {$existingContactMemberships|@json_encode};
458
459 {literal}
460 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
461
462
463
464 function checkExistingMemOrg () {
465 alert && alert.close && alert.close();
466 var selectedorg = $("select[name='membership_type_id[0]']").val();
467 if (selectedorg in memberorgs) {
468 var andEndDate = '',
469 endDate = memberorgs[selectedorg].membership_end_date,
470 org = $('option:selected', "select[name='membership_type_id[0]']").text();
471 if (endDate) {
472 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
473 andEndDate = ' ' + ts(andEndDate, {1:endDate});
474 }
475
476 alert = CRM.alert(
477 // Mixing client-side variables with a translated string in smarty is awkward!
478 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})
479 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
480 + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}'
481 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
482 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
483 + '</a></li></ul>',
484 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
485 }
486 }
487 checkExistingMemOrg();
488 {/literal}
489 {/if}
490
491 {literal}
492
493 });
494 {/literal}
495
496 {if $membershipMode or $action eq 2}
497
498 buildAutoRenew( null, null, '{$membershipMode}');
499 {literal}
500 function buildAutoRenew( membershipType, processorId, mode ) {
501 var action = {/literal}'{$action}'{literal};
502
503 //for update lets hide it when not already recurring.
504 if ( action == 2 ) {
505 //user can't cancel auto renew by unchecking.
506 if ( cj("#auto_renew").prop('checked' ) ) {
507 cj("#auto_renew").attr( 'readonly', true );
508 }
509 else {
510 cj("#autoRenew").hide( );
511 }
512 }
513
514 //we should do all auto renew for cc memberships.
515 if ( !mode ) return;
516
517 //get the required values in case missing.
518 if ( !processorId ) processorId = cj( '#payment_processor_id' ).val( );
519 if ( !membershipType ) membershipType = parseInt( cj('#membership_type_id_1').val( ) );
520
521 //we don't have both required values.
522 if ( !processorId || !membershipType ) {
523 cj("#auto_renew").prop('checked', false );
524 cj("#autoRenew").hide( );
525 showEmailOptions();
526 return;
527 }
528
529 var recurProcessors = {/literal}{$recurProcessor}{literal};
530 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
531 var currentOption = autoRenewOptions[membershipType];
532
533 if ( !currentOption || !recurProcessors[processorId] ) {
534 cj("#auto_renew").prop('checked', false );
535 cj("#autoRenew").hide();
536 return;
537 }
538
539 if ( currentOption == 1 ) {
540 cj("#autoRenew").show( );
541 if ( cj("#auto_renew").attr( 'readonly' ) ) {
542 cj("#auto_renew").prop('checked', false );
543 cj("#auto_renew").removeAttr( 'readonly' );
544 }
545 }
546 else if ( currentOption == 2 ) {
547 cj("#autoRenew").show( );
548 cj("#auto_renew").prop('checked', true );
549 cj("#auto_renew").attr( 'readonly', true );
550 }
551 else {
552 cj("#auto_renew").prop('checked', false );
553 cj("#autoRenew").hide( );
554 }
555 showEmailOptions();
556 }
557 {/literal}
558 {/if}
559
560 {literal}
561
562 var customDataType = '{/literal}{$customDataType}{literal}';
563
564 // load form during form rule.
565 {/literal}{if $buildPriceSet}{literal}
566 cj( "#totalAmountORPriceSet" ).hide( );
567 cj( "#mem_type_id" ).hide( );
568 cj('#total_amount').attr("readonly", true);
569 cj( "#num_terms_row" ).hide( );
570 cj(".crm-membership-form-block-financial_type_id-mode").hide();
571 {/literal}{/if}{literal}
572
573 function buildAmount( priceSetId ) {
574 if ( !priceSetId ) {
575 priceSetId = cj("#price_set_id").val( );
576 }
577 var fname = '#priceset';
578 if ( !priceSetId ) {
579 cj('#membership_type_id_1').val(0);
580 CRM.buildCustomData(customDataType, 'null' );
581
582 // hide price set fields.
583 cj( fname ).hide( );
584
585 // show/hide price set amount and total amount.
586 cj( "#mem_type_id").show( );
587 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
588 cj("#price_set_id option[value='']").html( choose );
589 cj( "#totalAmountORPriceSet" ).show( );
590 cj('#total_amount').removeAttr("readonly");
591 cj( "#num_terms_row").show( );
592 cj(".crm-membership-form-block-financial_type_id-mode").show();
593
594 {/literal}{if $allowAutoRenew}{literal}
595 cj('#autoRenew').hide();
596 var autoRenew = cj("#auto_renew");
597 autoRenew.removeAttr( 'readOnly' );
598 autoRenew.prop('checked', false );
599 {/literal}{/if}{literal}
600 return;
601 }
602
603 cj( "#total_amount" ).val( '' );
604 cj('#total_amount').attr("readonly", true);
605
606 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
607
608 var response = cj.ajax({
609 url: dataUrl,
610 async: false
611 }).responseText;
612
613 cj( fname ).show( ).html( response );
614 // freeze total amount text field.
615
616 cj( "#totalAmountORPriceSet" ).hide( );
617 cj( "#mem_type_id" ).hide( );
618 var manual = "{/literal}{ts}Manual membership and price{/ts}{literal}";
619 cj("#price_set_id option[value='']").html( manual );
620 cj( "#num_terms_row" ).hide( );
621 cj(".crm-membership-form-block-financial_type_id-mode").hide();
622 }
623
624 buildMaxRelated(cj('#membership_type_id_1', false).val());
625
626 function buildMaxRelated( memType, setDefault ) {
627 var allMemberships = {/literal}{$allMembershipInfo}{literal};
628
629 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
630 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
631 cj('#maxRelated').show();
632 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
633 if (cid) {
634 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
635 success: function(result) {
636 var relatable;
637 if (result.result === 0) {
638 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
639 }
640 else if (result.result === 1) {
641 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
642 }
643 else {
644 relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}';
645 relatable = ts(relatable, {1: result});
646 }
647 cj('#max_related').siblings('.description').append(' ' + relatable);
648 }
649 });
650 }
651 } else {
652 cj('#max_related').val('');
653 cj('#maxRelated').hide();
654 }
655 }
656
657 var lastMembershipTypes = [];
658 var optionsMembershipTypes = [];
659
660 // function to load custom data for selected membership types through priceset
661 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
662 var currentMembershipType = [];
663 var count = 0;
664 var loadCustomData = 0;
665 if ( membershipValues ) {
666 optionsMembershipTypes = membershipValues;
667 }
668
669 if ( reload ) {
670 lastMembershipTypes = [];
671 {/literal}{if $allowAutoRenew}{literal}
672 cj('#autoRenew').hide();
673 var autoRenew = cj("#auto_renew");
674 autoRenew.removeAttr( 'readOnly' );
675 autoRenew.prop('checked', false );
676 if ( autoRenewOption == 1 ) {
677 cj('#autoRenew').show();
678 }
679 else if ( autoRenewOption == 2 ) {
680 autoRenew.attr( 'readOnly', true );
681 autoRenew.prop('checked', true );
682 cj('#autoRenew').show();
683 }
684 {/literal}{/if}{literal}
685 }
686
687 cj("input,#priceset select,#priceset").each(function () {
688 if ( cj(this).attr('price') ) {
689 switch( cj(this).attr('type') ) {
690 case 'checkbox':
691 if ( cj(this).prop('checked') ) {
692 eval( 'var option = ' + cj(this).attr('price') ) ;
693 var ele = option[0];
694 var memTypeId = optionsMembershipTypes[ele];
695 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
696 currentMembershipType[count] = memTypeId;
697 count++;
698 }
699 }
700 if ( reload ) {
701 cj(this).click( function( ) {
702 processMembershipPriceset();
703 });
704 }
705 break;
706
707 case 'radio':
708 if ( cj(this).prop('checked') && cj(this).val() ) {
709 var memTypeId = optionsMembershipTypes[cj(this).val()];
710 if ( memTypeId && cj.inArray(memTypeId, 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 'select-one':
723 if ( 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).change( function( ) {
732 processMembershipPriceset();
733 });
734 }
735 break;
736 }
737 }
738 });
739
740 for( i in currentMembershipType ) {
741 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
742 loadCustomData = 1;
743 break;
744 }
745 }
746
747 if ( !loadCustomData ) {
748 for( i in lastMembershipTypes) {
749 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
750 loadCustomData = 1;
751 break;
752 }
753 }
754 }
755
756 lastMembershipTypes = currentMembershipType;
757
758 // load custom data only if change in membership type selection
759 if ( !loadCustomData ) {
760 return;
761 }
762
763 subTypeNames = currentMembershipType.join(',');
764 if ( subTypeNames.length < 1 ) {
765 subTypeNames = 'null';
766 }
767
768 CRM.buildCustomData( customDataType, subTypeNames );
769 }
770
771 function enableAmountSection( setContributionType ) {
772 if ( !cj('#record_contribution').prop('checked') ) {
773 cj('#record_contribution').click( );
774 cj('#recordContribution').show( );
775 }
776 if ( setContributionType ) {
777 cj('#financial_type_id').val(setContributionType);
778 }
779 }
780 </script>
781 {/literal}
782 {/if} {* closing of delete check if *}
783 {/if}{* closing of custom data if *}