commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / 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><td class="label">{$form.payment_processor_id.label}</td><td>{$form.payment_processor_id.html}</td></tr>
90 {/if}
91 <tr class="crm-membership-form-block-membership_type_id">
92 <td class="label">{$form.membership_type_id.label}</td>
93 <td><span id='mem_type_id'>{$form.membership_type_id.html}</span>
94 {if $hasPriceSets}
95 <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
96 <span id='selectPriceSet'>{$form.price_set_id.html}</span>
97 {if $buildPriceSet && $priceSet}
98 <div id="priceset"><br/>{include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"}</div>
99 {else}
100 <div id="priceset" class="hiddenElement"></div>
101 {/if}
102 {/if}
103 {if $member_is_test} {ts}(test){/ts}{/if}<br />
104 <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>
105 </td>
106 </tr>
107 <tr id="maxRelated" class="crm-membership-form-block-max_related">
108 <td class="label">{$form.max_related.label}</td>
109 <td>{$form.max_related.html}<br />
110 <span class="description">{ts}Maximum number of related memberships (leave blank for unlimited).{/ts}</span>
111 </td>
112 </tr>
113 {if $action eq 1}
114 <tr id="num_terms_row" class="crm-membership-form-block-num_terms">
115 <td class="label">{$form.num_terms.label}</td>
116 <td>&nbsp;{$form.num_terms.html}<br />
117 <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>
118 </td>
119 </tr>
120 {/if}
121 <tr class="crm-membership-form-block-source">
122 <td class="label">{$form.source.label}</td>
123 <td>&nbsp;{$form.source.html}<br />
124 <span class="description">{ts}Source of this membership. This value is searchable.{/ts}</span></td>
125 </tr>
126
127 {* CRM-7362 --add campaign to membership *}
128 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl"
129 campaignTrClass="crm-membership-form-block-campaign_id"}
130
131 <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}
132 <br />
133 <span class="description">{ts}When did this contact first become a member?{/ts}</span></td></tr>
134 <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}
135 <br />
136 <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>
137 <tr class="crm-membership-form-block-end_date"><td class="label">{$form.end_date.label}</td>
138 <td id="end-date-readonly">
139 {$endDate|crmDate}
140 <a href="#" class="crm-hover-button action-item override-date" id="show-end-date">
141 {ts}Over-ride end date{/ts}
142 </a>
143 {help id="override_end_date"}
144 </td>
145 <td id="end-date-editable">
146 {include file="CRM/common/jcalendar.tpl" elementName=end_date}
147 <br />
148 <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>
149 </td>
150 </tr>
151 {if !empty($form.auto_renew)}
152 <tr id="autoRenew" class="crm-membership-form-block-auto_renew">
153 <td class="label"> {$form.auto_renew.label} {help id="id-auto_renew" file="CRM/Member/Form/Membership.hlp" action=$action} </td>
154 <td> {$form.auto_renew.html} </td>
155 </tr>
156 {/if}
157 {if !$membershipMode}
158 <tr><td class="label">{$form.is_override.label} {help id="id-status-override"}</td><td>{$form.is_override.html}</td></tr>
159 {/if}
160
161 {if ! $membershipMode}
162 {* Show read-only Status block - when action is UPDATE and is_override is FALSE *}
163 <tr id="memberStatus_show">
164 {if $action eq 2}
165 <td class="label">{$form.status_id.label}</td><td class="view-value">{$membershipStatus}</td>
166 {/if}
167 </tr>
168
169 {* Show editable status field when is_override is TRUE *}
170 <tr id="memberStatus"><td class="label">{$form.status_id.label}</td><td>{$form.status_id.html}<br />
171 <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>
172
173 {elseif $membershipMode}
174 <tr class="crm-membership-form-block-financial_type_id-mode">
175 <td class="label">{$form.financial_type_id.label}</td>
176 <td>{$form.financial_type_id.html}<br />
177 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
178 </tr>
179 <tr class="crm-membership-form-block-total_amount">
180 <td class="label">{$form.total_amount.label}</td>
181 <td>{$form.total_amount.html}<br />
182 <span class="description">{ts}Membership payment amount.{/ts}</span><div class="totaltaxAmount"></div></td>
183 </tr>
184 <tr class="crm-membership-form-block-contribution-contact">
185 <td class="label">{$form.is_different_contribution_contact.label}</td>
186 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
187 </tr>
188 <tr id="record-different-contact">
189 <td>&nbsp;</td>
190 <td>
191 <table class="compressed">
192 <tr class="crm-membership-form-block-soft-credit-type">
193 {*CRM-15366*}
194 <td class="label">{$form.soft_credit_type_id.label}</td>
195 <td>{$form.soft_credit_type_id.html}</td>
196 </tr>
197 <tr class="crm-membership-form-block-soft-credit-contact-id">
198 <td class="label">{$form.soft_credit_contact_id.label}</td>
199 <td>{$form.soft_credit_contact_id.html}</td>
200 </tr>
201 </table>
202 </td>
203 </tr>
204 <tr class="crm-membership-form-block-billing">
205 <td colspan="2">
206 {include file='CRM/Core/BillingBlock.tpl'}
207 </td>
208 </tr>
209 {/if}
210 {if $accessContribution and ! $membershipMode AND ($action neq 2 or (!$rows.0.contribution_id AND !$softCredit) or $onlinePendingContributionId)}
211 <tr id="contri">
212 <td class="label">{if $onlinePendingContributionId}{ts}Update Payment Status{/ts}{else}{$form.record_contribution.label}{/if}</td>
213 <td>{$form.record_contribution.html}<br />
214 <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>
215 </tr>
216 <tr class="crm-membership-form-block-record_contribution"><td colspan="2">
217 <fieldset id="recordContribution"><legend>{ts}Membership Payment and Receipt{/ts}</legend>
218 <table>
219 <tr class="crm-membership-form-block-contribution-contact">
220 <td class="label">{$form.is_different_contribution_contact.label}</td>
221 <td>{$form.is_different_contribution_contact.html}&nbsp;&nbsp;{help id="id-contribution_contact"}</td>
222 </tr>
223 <tr id="record-different-contact">
224 <td>&nbsp;</td>
225 <td>
226 <table class="compressed">
227 <tr class="crm-membership-form-block-soft-credit-type">
228 <td class="label">{$form.soft_credit_type_id.label}</td>
229 <td>{$form.soft_credit_type_id.html}</td>
230 </tr>
231 <tr class="crm-membership-form-block-soft-credit-contact-id">
232 <td class="label">{$form.soft_credit_contact_id.label}</td>
233 <td>{$form.soft_credit_contact_id.html}</td>
234 </tr>
235 </table>
236 </td>
237 </tr>
238 <tr class="crm-membership-form-block-financial_type_id">
239 <td class="label">{$form.financial_type_id.label}</td>
240 <td>{$form.financial_type_id.html}<br />
241 <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
242 </tr>
243 <tr class="crm-membership-form-block-total_amount">
244 <td class="label">{$form.total_amount.label}</td>
245 <td>{$form.total_amount.html}<br />
246 <span class="description">{ts}Membership payment amount. A contribution record will be created for this amount.{/ts}</span><div class="totaltaxAmount"></div></td>
247 </tr>
248 <tr class="crm-membership-form-block-receive_date">
249 <td class="label">{$form.receive_date.label}</td>
250 <td>{include file="CRM/common/jcalendar.tpl" elementName=receive_date}</td>
251 </tr>
252 <tr class="crm-membership-form-block-payment_instrument_id">
253 <td class="label">{$form.payment_instrument_id.label}<span class="marker"> *</span></td>
254 <td>{$form.payment_instrument_id.html} {help id="payment_instrument_id" file="CRM/Contribute/Page/Tab.hlp"}</td>
255 </tr>
256 <tr id="checkNumber" class="crm-membership-form-block-check_number">
257 <td class="label">{$form.check_number.label}</td>
258 <td>{$form.check_number.html|crmAddClass:six}</td>
259 </tr>
260 {if $action neq 2 }
261 <tr class="crm-membership-form-block-trxn_id">
262 <td class="label">{$form.trxn_id.label}</td>
263 <td>{$form.trxn_id.html}</td>
264 </tr>
265 {/if}
266 <tr class="crm-membership-form-block-contribution_status_id">
267 <td class="label">{$form.contribution_status_id.label}</td>
268 <td>{$form.contribution_status_id.html}</td>
269 </tr>
270 </table>
271 </fieldset>
272 </td></tr>
273 {else}
274 <div class="spacer"></div>
275 {/if}
276
277 {if $emailExists and $outBound_option != 2 }
278 <tr id="send-receipt" class="crm-membership-form-block-send_receipt">
279 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
280 <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>
281 </tr>
282 {elseif $context eq 'standalone' and $outBound_option != 2 }
283 <tr id="email-receipt" style="display:none;">
284 <td class="label">{$form.send_receipt.label}</td><td>{$form.send_receipt.html}<br />
285 <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>
286 </tr>
287 {/if}
288 <tr id="fromEmail" style="display:none;">
289 <td class="label">{$form.from_email_address.label}</td>
290 <td>{$form.from_email_address.html}</td>
291 </tr>
292 <tr id='notice' style="display:none;">
293 <td class="label">{$form.receipt_text_signup.label}</td>
294 <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>
295 {$form.receipt_text_signup.html|crmAddClass:huge}</td>
296 </tr>
297 </table>
298 <div id="customData"></div>
299 {*include custom data js file*}
300 {include file="CRM/common/customData.tpl"}
301 {literal}
302 <script type="text/javascript">
303 CRM.$(function($) {
304 {/literal}
305 CRM.buildCustomData( '{$customDataType}' );
306 {if $customDataSubType}
307 CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
308 {/if}
309 {literal}
310 });
311 </script>
312 {/literal}
313 {if $accessContribution and $action eq 2 and $rows.0.contribution_id}
314 <div class="crm-accordion-wrapper">
315 <div class="crm-accordion-header">{ts}Related Contributions{/ts}</div>
316 <div class="crm-accordion-body">{include file="CRM/Contribute/Form/Selector.tpl" context="Search"}</div>
317 </div>
318 {/if}
319 {if $softCredit}
320 <div class="crm-accordion-wrapper">
321 <div class="crm-accordion-header">{ts}Related Soft Contributions{/ts}</div>
322 <div class="crm-accordion-body">{include file="CRM/Contribute/Page/ContributionSoft.tpl" context="membership"}</div>
323 </div>
324 {/if}
325 {/if}
326
327 <div class="spacer"></div>
328 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
329 </div> <!-- end form-block -->
330
331 {if $action neq 8} {* Jscript additions not need for Delete action *}
332 {if $accessContribution and !$membershipMode AND ($action neq 2 or !$rows.0.contribution_id or $onlinePendingContributionId)}
333
334 {include file="CRM/common/showHideByFieldValue.tpl"
335 trigger_field_id ="record_contribution"
336 trigger_value =""
337 target_element_id ="recordContribution"
338 target_element_type ="table-row"
339 field_type ="radio"
340 invert = 0
341 }
342 {include file="CRM/common/showHideByFieldValue.tpl"
343 trigger_field_id ="payment_instrument_id"
344 trigger_value = '4'
345 target_element_id ="checkNumber"
346 target_element_type ="table-row"
347 field_type ="select"
348 invert = 0
349 }
350 {/if}
351
352 {literal}
353 <script type="text/javascript">
354 function setPaymentBlock(mode, checkboxEvent) {
355 var memType = parseInt(cj('#membership_type_id_1').val( ));
356 var isPriceSet = 0;
357 var existingAmount = {/literal}{if !empty($onlinePendingContributionId)}1{else}0{/if}{literal};
358
359 if ( cj('#price_set_id').length > 0 && cj('#price_set_id').val() ) {
360 isPriceSet = 1;
361 }
362
363 if ( !memType || isPriceSet ) {
364 return;
365 }
366
367 var allMemberships = {/literal}{$allMembershipInfo}{literal};
368 if (!mode) {
369 //check the record_contribution checkbox if membership is a paid one
370 {/literal}{if $action eq 1}{literal}
371 if (!checkboxEvent) {
372 if (allMemberships[memType]['total_amount_numeric'] > 0) {
373 cj('#record_contribution').prop('checked','checked');
374 cj('#recordContribution').show();
375 }
376 else {
377 cj('#record_contribution').prop('checked', false);
378 cj('#recordContribution').hide();
379 }
380 }
381 {/literal}{/if}{literal}
382 }
383
384 // skip this for test and live modes because financial type is set automatically
385 cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']);
386 var term = cj('#num_terms').val();
387 var taxRates = '{/literal}{$taxRates}{literal}';
388 var taxTerm = '{/literal}{$taxTerm}{literal}';
389 var taxRates = JSON.parse(taxRates);
390 var taxRate = taxRates[allMemberships[memType]['financial_type_id']];
391 var currency = '{/literal}{$currency}{literal}';
392 var taxAmount = (taxRate/100)*allMemberships[memType]['total_amount_numeric'];
393 taxAmount = isNaN (taxAmount) ? 0:taxAmount;
394 if ( term ) {
395 if (!taxRate) {
396 var feeTotal = allMemberships[memType]['total_amount_numeric'] * term;
397 }
398 else {
399 var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number(allMemberships[memType]['total_amount_numeric'] * term );
400 }
401 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
402 }
403 else {
404 if (taxRate) {
405 var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
406 cj("#total_amount").val(CRM.formatMoney(feeTotal, true));
407 }
408 else {
409 var feeTotal = allMemberships[memType]['total_amount'];
410 if (!existingAmount) {
411 // CRM-16680 don't set amount if there is an existing contribution.
412 cj("#total_amount").val(allMemberships[memType]['total_amount']);
413 }
414 }
415 }
416 var taxMessage = taxRate!=undefined ? 'Includes '+taxTerm+' amount of '+currency+' '+taxAmount:'';
417 cj('.totaltaxAmount').html(taxMessage);
418 }
419
420
421 CRM.$(function($) {
422 var mode = {/literal}'{$membershipMode}'{literal};
423 if ( !mode ) {
424 // Offline form (mode = false) has the record_contribution checkbox
425 cj('#record_contribution').click( function( ) {
426 if ( cj(this).prop('checked') ) {
427 cj('#recordContribution').show( );
428 setPaymentBlock( false, true);
429 }
430 else {
431 cj('#recordContribution').hide( );
432 }
433 });
434 }
435
436 cj('#membership_type_id_1').change( function( ) {
437 setPaymentBlock(mode);
438 });
439 cj('#num_terms').change( function( ) {
440 setPaymentBlock(mode);
441 });
442 setPaymentBlock(mode);
443
444 // show/hide different contact section
445 setDifferentContactBlock();
446 cj('#is_different_contribution_contact').change( function() {
447 setDifferentContactBlock();
448 });
449
450 // give option to override end-date for auto-renew memberships
451 {/literal}
452 {if $isRecur && $endDate}
453 cj('#end-date-readonly').show();
454 cj('#end-date-editable').hide();
455 {else}
456 cj('#end-date-readonly').hide();
457 cj('#end-date-editable').show();
458 {/if}
459 {literal}
460
461 cj('#show-end-date').click( function( e ) {
462 e.preventDefault();
463 cj('#end-date-readonly').hide();
464 cj('#end-date-editable').show();
465 });
466
467 });
468
469 function setDifferentContactBlock( ) {
470 // show/hide different contact section
471 if ( cj('#is_different_contribution_contact').prop('checked') ) {
472 cj('#record-different-contact').show();
473 }
474 else {
475 cj('#record-different-contact').hide();
476 }
477 }
478
479 </script>
480 {/literal}
481
482 {if ($emailExists and $outBound_option != 2) OR $context eq 'standalone' }
483 {include file="CRM/common/showHideByFieldValue.tpl"
484 trigger_field_id ="send_receipt"
485 trigger_value =""
486 target_element_id ="notice"
487 target_element_type ="table-row"
488 field_type ="radio"
489 invert = 0
490 }
491 {include file="CRM/common/showHideByFieldValue.tpl"
492 trigger_field_id ="send_receipt"
493 trigger_value =""
494 target_element_id ="fromEmail"
495 target_element_type ="table-row"
496 field_type ="radio"
497 invert = 0
498 }
499 {/if}
500 {literal}
501
502 <script type="text/javascript">
503
504 {/literal}{if !$membershipMode}{literal}
505 showHideMemberStatus();
506 function showHideMemberStatus() {
507 if ( cj( "#is_override" ).prop('checked' ) ) {
508 cj('#memberStatus').show( );
509 cj('#memberStatus_show').hide( );
510 }
511 else {
512 cj('#memberStatus').hide( );
513 cj('#memberStatus_show').show( );
514 }
515 }
516 {/literal}{/if}
517
518 {if $context eq 'standalone' and $outBound_option != 2 }
519 {literal}
520 CRM.$(function($) {
521 var $form = $("form.{/literal}{$form.formClass}{literal}");
522 $("#contact_id", $form).change(checkEmail);
523 checkEmail( );
524
525 function checkEmail( ) {
526 var data = $("#contact_id", $form).select2('data');
527 if (data && data.extra && data.extra.email && data.extra.email.length) {
528 $("#email-receipt", $form).show();
529 if ($("#send_receipt", $form).is(':checked')) {
530 $("#notice", $form).show();
531 }
532 $("#email-address", $form).html(data.extra.email);
533 }
534 else {
535 $("#email-receipt, #notice", $form).hide();
536 }
537 }
538 });
539
540 {/literal}
541 {/if}
542
543 {literal}
544 //keep read only always checked.
545 CRM.$(function($) {
546 var $form = $("form.{/literal}{$form.formClass}{literal}");
547 var allowAutoRenew = {/literal}'{$allowAutoRenew}'{literal};
548 var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
549 if ( allowAutoRenew || alreadyAutoRenew ) {
550 $( "#auto_renew" ).click(function( ) {
551 if ( $(this).attr( 'readonly' ) ) {
552 $(this).prop('checked', true );
553 }
554 });
555 }
556
557 {/literal}
558 {if !empty($existingContactMemberships)}
559
560 var alert, memberorgs = {$existingContactMemberships|@json_encode};
561
562 {literal}
563 $("select[name='membership_type_id[0]']").change(checkExistingMemOrg);
564
565
566
567 function checkExistingMemOrg () {
568 alert && alert.close && alert.close();
569 var selectedorg = $("select[name='membership_type_id[0]']").val();
570 if (selectedorg in memberorgs) {
571 var andEndDate = '',
572 endDate = memberorgs[selectedorg].membership_end_date,
573 org = $('option:selected', "select[name='membership_type_id[0]']").text();
574 if (endDate) {
575 andEndDate = '{/literal}{ts escape='js' 1='%1'}and end date of %1{/ts}{literal}';
576 andEndDate = ' ' + ts(andEndDate, {1:endDate});
577 }
578
579 alert = CRM.alert(
580 // Mixing client-side variables with a translated string in smarty is awkward!
581 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})
582 + '<ul><li><a href="' + memberorgs[selectedorg].renewUrl + '">'
583 + {/literal}'{ts escape='js'}Renew the existing membership instead{/ts}'
584 + '</a></li><li><a href="' + memberorgs[selectedorg].membershipTab + '">'
585 + '{ts escape='js'}View all existing and / or expired memberships for this contact{/ts}'{literal}
586 + '</a></li></ul>',
587 '{/literal}{ts escape='js'}Duplicate Membership?{/ts}{literal}', 'alert');
588 }
589 }
590 checkExistingMemOrg();
591 {/literal}
592 {/if}
593
594 {literal}
595
596 });
597 {/literal}
598
599 {if $membershipMode or $action eq 2}
600 {literal}
601
602 buildAutoRenew( null, null );
603
604 function buildAutoRenew( membershipType, processorId ) {
605 var mode = {/literal}'{$membershipMode}'{literal};
606 var action = {/literal}'{$action}'{literal};
607
608 //for update lets hide it when not already recurring.
609 if ( action == 2 ) {
610 //user can't cancel auto renew by unchecking.
611 if ( cj("#auto_renew").prop('checked' ) ) {
612 cj("#auto_renew").attr( 'readonly', true );
613 }
614 else {
615 cj("#autoRenew").hide( );
616 }
617 }
618
619 //we should do all auto renew for cc memberships.
620 if ( !mode ) return;
621
622 //get the required values in case missing.
623 if ( !processorId ) processorId = cj( '#payment_processor_id' ).val( );
624 if ( !membershipType ) membershipType = parseInt( cj('#membership_type_id_1').val( ) );
625
626 //we don't have both required values.
627 if ( !processorId || !membershipType ) {
628 cj("#auto_renew").prop('checked', false );
629 cj("#autoRenew").hide( );
630 return;
631 }
632
633 var recurProcessors = {/literal}{$recurProcessor}{literal};
634 var autoRenewOptions = {/literal}{$autoRenewOptions}{literal};
635 var currentOption = autoRenewOptions[membershipType];
636
637 if ( !currentOption || !recurProcessors[processorId] ) {
638 cj("#auto_renew").prop('checked', false );
639 cj("#autoRenew").hide( );
640 return;
641 }
642
643 if ( currentOption == 1 ) {
644 cj("#autoRenew").show( );
645 if ( cj("#auto_renew").attr( 'readonly' ) ) {
646 cj("#auto_renew").prop('checked', false );
647 cj("#auto_renew").removeAttr( 'readonly' );
648 }
649 }
650 else if ( currentOption == 2 ) {
651 cj("#autoRenew").show( );
652 cj("#auto_renew").prop('checked', true );
653 cj("#auto_renew").attr( 'readonly', true );
654 }
655 else {
656 cj("#auto_renew").prop('checked', false );
657 cj("#autoRenew").hide( );
658 }
659
660 //play w/ receipt option.
661 if ( cj("#auto_renew").prop('checked' ) ) {
662 cj("#notice").hide( );
663 cj("#send_receipt").prop('checked', false );
664 cj("#send-receipt").hide( );
665 }
666 else {
667 cj("#send-receipt").show( );
668 if ( cj("#send_receipt").prop('checked' ) ) {
669 cj("#notice").show( );
670 }
671 }
672 }
673 {/literal}
674 {/if}
675
676 {literal}
677 function buildReceiptANDNotice( ) {
678 if ( cj("#auto_renew").prop('checked' ) ) {
679 cj("#notice").hide( );
680 cj("#send-receipt").hide( );
681 }
682 else {
683 cj("#send-receipt").show( );
684 if ( cj("#send_receipt").prop('checked' ) ) {
685 cj("#notice").show( );
686 }
687 }
688 }
689
690 var customDataType = '{/literal}{$customDataType}{literal}';
691
692 // load form during form rule.
693 {/literal}{if $buildPriceSet}{literal}
694 cj( "#totalAmountORPriceSet" ).hide( );
695 cj( "#mem_type_id" ).hide( );
696 cj('#total_amount').attr("readonly", true);
697 cj( "#num_terms_row" ).hide( );
698 cj(".crm-membership-form-block-financial_type_id-mode").hide();
699 {/literal}{/if}{literal}
700
701 function buildAmount( priceSetId ) {
702 if ( !priceSetId ) {
703 priceSetId = cj("#price_set_id").val( );
704 }
705 var fname = '#priceset';
706 if ( !priceSetId ) {
707 cj('#membership_type_id_1').val(0);
708 CRM.buildCustomData(customDataType, 'null' );
709
710 // hide price set fields.
711 cj( fname ).hide( );
712
713 // show/hide price set amount and total amount.
714 cj( "#mem_type_id").show( );
715 var choose = "{/literal}{ts}Choose price set{/ts}{literal}";
716 cj("#price_set_id option[value='']").html( choose );
717 cj( "#totalAmountORPriceSet" ).show( );
718 cj('#total_amount').removeAttr("readonly");
719 cj( "#num_terms_row").show( );
720 cj(".crm-membership-form-block-financial_type_id-mode").show();
721
722 {/literal}{if $allowAutoRenew}{literal}
723 cj('#autoRenew').hide();
724 var autoRenew = cj("#auto_renew");
725 autoRenew.removeAttr( 'readOnly' );
726 autoRenew.prop('checked', false );
727 {/literal}{/if}{literal}
728 return;
729 }
730
731 cj( "#total_amount" ).val( '' );
732 cj('#total_amount').attr("readonly", true);
733
734 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&priceSetId=' + priceSetId;
735
736 var response = cj.ajax({
737 url: dataUrl,
738 async: false
739 }).responseText;
740
741 cj( fname ).show( ).html( response );
742 // freeze total amount text field.
743
744 cj( "#totalAmountORPriceSet" ).hide( );
745 cj( "#mem_type_id" ).hide( );
746 var manual = "{/literal}{ts}Manual membership and price{/ts}{literal}";
747 cj("#price_set_id option[value='']").html( manual );
748 cj( "#num_terms_row" ).hide( );
749 cj(".crm-membership-form-block-financial_type_id-mode").hide();
750 }
751
752 buildMaxRelated(cj('#membership_type_id_1', false).val());
753
754 function buildMaxRelated( memType, setDefault ) {
755 var allMemberships = {/literal}{$allMembershipInfo}{literal};
756
757 if ((memType > 0) && (allMemberships[memType]['has_related'])) {
758 if (setDefault) cj('#max_related').val(allMemberships[memType]['max_related']);
759 cj('#maxRelated').show();
760 var cid = {/literal}{if $contactID}{$contactID}{else}null{/if}{literal};
761 if (cid) {
762 CRM.api('relationship', 'getcount', {contact_id: cid, membership_type_id: memType}, {
763 success: function(result) {
764 var relatable;
765 if (result.result === 0) {
766 relatable = '{/literal}{ts escape='js'}No contacts are currently eligible to inherit this relationship.{/ts}{literal}';
767 }
768 else if (result.result === 1) {
769 relatable = '{/literal}{ts escape='js'}One contact is currently eligible to inherit this relationship.{/ts}{literal}';
770 }
771 else {
772 relatable = '{/literal}{ts escape='js' 1='%1'}%1 contacts are currently eligible to inherit this relationship.{/ts}{literal}';
773 relatable = ts(relatable, {1: result});
774 }
775 cj('#max_related').siblings('.description').append(' ' + relatable);
776 }
777 });
778 }
779 } else {
780 cj('#max_related').val('');
781 cj('#maxRelated').hide();
782 }
783 }
784
785 var lastMembershipTypes = [];
786 var optionsMembershipTypes = [];
787
788 // function to load custom data for selected membership types through priceset
789 function processMembershipPriceset( membershipValues, autoRenewOption, reload ) {
790 var currentMembershipType = [];
791 var count = 0;
792 var loadCustomData = 0;
793 if ( membershipValues ) {
794 optionsMembershipTypes = membershipValues;
795 }
796
797 if ( reload ) {
798 lastMembershipTypes = [];
799 {/literal}{if $allowAutoRenew}{literal}
800 cj('#autoRenew').hide();
801 var autoRenew = cj("#auto_renew");
802 autoRenew.removeAttr( 'readOnly' );
803 autoRenew.prop('checked', false );
804 if ( autoRenewOption == 1 ) {
805 cj('#autoRenew').show();
806 }
807 else if ( autoRenewOption == 2 ) {
808 autoRenew.attr( 'readOnly', true );
809 autoRenew.prop('checked', true );
810 cj('#autoRenew').show();
811 }
812 {/literal}{/if}{literal}
813 }
814
815 cj("input,#priceset select,#priceset").each(function () {
816 if ( cj(this).attr('price') ) {
817 switch( cj(this).attr('type') ) {
818 case 'checkbox':
819 if ( cj(this).prop('checked') ) {
820 eval( 'var option = ' + cj(this).attr('price') ) ;
821 var ele = option[0];
822 var memTypeId = optionsMembershipTypes[ele];
823 if ( memTypeId && cj.inArray(optionsMembershipTypes[ele], currentMembershipType) == -1 ) {
824 currentMembershipType[count] = memTypeId;
825 count++;
826 }
827 }
828 if ( reload ) {
829 cj(this).click( function( ) {
830 processMembershipPriceset();
831 });
832 }
833 break;
834
835 case 'radio':
836 if ( cj(this).prop('checked') && cj(this).val() ) {
837 var memTypeId = optionsMembershipTypes[cj(this).val()];
838 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
839 currentMembershipType[count] = memTypeId;
840 count++;
841 }
842 }
843 if ( reload ) {
844 cj(this).click( function( ) {
845 processMembershipPriceset();
846 });
847 }
848 break;
849
850 case 'select-one':
851 if ( cj(this).val( ) ) {
852 var memTypeId = optionsMembershipTypes[cj(this).val()];
853 if ( memTypeId && cj.inArray(memTypeId, currentMembershipType) == -1 ) {
854 currentMembershipType[count] = memTypeId;
855 count++;
856 }
857 }
858 if ( reload ) {
859 cj(this).change( function( ) {
860 processMembershipPriceset();
861 });
862 }
863 break;
864 }
865 }
866 });
867
868 for( i in currentMembershipType ) {
869 if ( cj.inArray(currentMembershipType[i], lastMembershipTypes) == -1 ) {
870 loadCustomData = 1;
871 break;
872 }
873 }
874
875 if ( !loadCustomData ) {
876 for( i in lastMembershipTypes) {
877 if ( cj.inArray(lastMembershipTypes[i], currentMembershipType) == -1 ) {
878 loadCustomData = 1;
879 break;
880 }
881 }
882 }
883
884 lastMembershipTypes = currentMembershipType;
885
886 // load custom data only if change in membership type selection
887 if ( !loadCustomData ) {
888 return;
889 }
890
891 subTypeNames = currentMembershipType.join(',');
892 if ( subTypeNames.length < 1 ) {
893 subTypeNames = 'null';
894 }
895
896 CRM.buildCustomData( customDataType, subTypeNames );
897 }
898
899 function enableAmountSection( setContributionType ) {
900 if ( !cj('#record_contribution').prop('checked') ) {
901 cj('#record_contribution').click( );
902 cj('#recordContribution').show( );
903 }
904 if ( setContributionType ) {
905 cj('#financial_type_id').val(setContributionType);
906 }
907 }
908 </script>
909 {/literal}
910 {/if} {* closing of delete check if *}
911 {/if}{* closing of custom data if *}