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