remove tabs, trailing spaces
[civicrm-core.git] / templates / CRM / Contribute / Form / Contribution / OnBehalfOf.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*}
061a96be 26{**
7f7fa13a 27 * This file provides the HTML for the on-behalf-of form.
061a96be
CW
28 * Also used for related contact edit form.
29 * FIXME: This is way more complex than it needs to be
061a96be
CW
30 * FIXME: Why are we not just using the dynamic form tpl to display this profile?
31 *}
6a488035
TO
32
33{if $buildOnBehalfForm or $onBehalfRequired}
34<fieldset id="for_organization" class="for_organization-group">
35<legend>{$fieldSetTitle}</legend>
36 {if ( $relatedOrganizationFound or $onBehalfRequired ) and !$organizationName}
f62e40cf
DG
37 <div id='orgOptions' class="section crm-section">
38 <div class="content">
39 {$form.org_option.html}
40 </div>
6a488035 41 </div>
6a488035
TO
42 {/if}
43
44<div id="select_org" class="crm-section">
45 {foreach from=$onBehalfOfFields item=onBehaldField key=fieldName}
46 {if $onBehalfOfFields.$fieldName.skipDisplay}
47 {continue}
48 {/if}
49 {if $onBehalfOfFields.$fieldName.field_type eq "Formatting"}
50 {$onBehalfOfFields.$fieldName.help_pre}
51 {continue}
52 {/if}
53 <div class="crm-section {$onBehalfOfFields.$fieldName.name}-section">
54 {if $onBehalfOfFields.$fieldName.help_pre}
55 &nbsp;&nbsp;<span class='description'>{$onBehalfOfFields.$fieldName.help_pre}</span>
56 {/if}
57
58 {if ( $fieldName eq 'organization_name' ) and $organizationName}
59 <div id='org_name' class="label">{$form.onbehalf.$fieldName.label}</div>
60 <div class="content">
61 {$form.onbehalf.$fieldName.html|crmAddClass:big}
62 <span>
f62e40cf
DG
63 ( <a id='createNewOrg' href="#" onclick="createNew( ); return false;">{ts}Enter a new organization{/ts}</a> )
64 </span>
6a488035
TO
65 <div id="id-onbehalf-orgname-enter-help" class="description">
66 {ts}Organization details have been prefilled for you. If this is not the organization you want to use, click "Enter a new organization" above.{/ts}
67 </div>
68 {if $onBehalfOfFields.$fieldName.help_post}
69 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
70 {/if}
71 </div>
f62e40cf
DG
72 {else}
73 {if $onBehalfOfFields.$fieldName.options_per_line}
6a488035 74 <div class="label option-label">{$form.onbehalf.$fieldName.label}</div>
f62e40cf 75 <div class="content">
6a488035
TO
76 {assign var="count" value="1"}
77 {strip}
78 <table class="form-layout-compressed">
79 <tr>
80 {* sort by fails for option per line. Added a variable to iterate through the element array*}
81 {assign var="index" value="1"}
f62e40cf 82 {foreach name=outer key=key item=item from=$form.onbehalf.$fieldName}
6a488035
TO
83 {if $index < 10}
84 {assign var="index" value=`$index+1`}
f62e40cf 85 {else}
6a488035
TO
86 <td class="labels font-light">{$form.onbehalf.$fieldName.$key.html}</td>
87 {if $count == $onBehalfOfFields.$fieldName.options_per_line}
f62e40cf
DG
88 </tr>
89 <tr>
6a488035 90 {assign var="count" value="1"}
f62e40cf 91 {else}
6a488035
TO
92 {assign var="count" value=`$count+1`}
93 {/if}
94 {/if}
95 {/foreach}
96 </tr>
97 </table>
98 {/strip}
99 {if $onBehalfOfFields.$fieldName.help_post}
100 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
101 {/if}
102 </div>
f62e40cf 103 {else}
6a488035
TO
104 <div class="label">{$form.onbehalf.$fieldName.label}</div>
105 <div class="content">
ca5bbc71
CW
106 {if $fieldName eq 'organization_name' and !empty($form.onbehalfof_id)}
107 {$form.onbehalfof_id.html}
6a488035 108 {/if}
6a488035 109 {$form.onbehalf.$fieldName.html}
6a488035
TO
110 {if !empty($onBehalfOfFields.$fieldName.html_type) && $onBehalfOfFields.$fieldName.html_type eq 'Autocomplete-Select'}
111 {assign var=elementName value=onbehalf[$fieldName]}
112 {include file="CRM/Custom/Form/AutoComplete.tpl" element_name=$elementName}
6a488035 113 {/if}
6a488035
TO
114 {if $onBehalfOfFields.$fieldName.name|substr:0:5 eq 'phone'}
115 {assign var="phone_ext_field" value=$onBehalfOfFields.$fieldName.name|replace:'phone':'phone_ext'}
116 {if $form.onbehalf.$phone_ext_field.html}
117 &nbsp;{$form.onbehalf.$phone_ext_field.html}
118 {/if}
7f7fa13a
EM
119 {/if}
120 {if $onBehalfOfFields.$fieldName.data_type eq 'Date'}
31e83de7 121 {assign var=elementName value=onbehalf[$fieldName]}
7f7fa13a 122 {include file="CRM/common/jcalendar.tpl" elementName=$elementName elementId=onbehalf_$fieldName}
6a488035
TO
123 {/if}
124 {if $onBehalfOfFields.$fieldName.help_post}
125 <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
126 {/if}
127 </div>
128 {/if}
129 {/if}
130 <div class="clear"></div>
131 </div>
132 {/foreach}
133</div>
134<div>{$form.mode.html}</div>
ab234a8a 135</fieldset>
6a488035 136{/if}
ab234a8a 137{if empty($snippet)}
6a488035
TO
138{literal}
139<script type="text/javascript">
6a488035 140
061a96be 141 showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
6a488035
TO
142
143 cj( "#mode" ).hide( );
8539f25d
CW
144 cj( "#mode" ).prop('checked', true );
145 if ( cj( "#mode" ).prop('checked' ) && !{/literal}"{$reset}"{literal} ) {
6a488035
TO
146 $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
147 cj( "#createNewOrg" ).text( $text );
8539f25d 148 cj( "#mode" ).prop('checked', false );
6a488035
TO
149 }
150
151function showOnBehalf(onBehalfRequired) {
9b10578b 152 if ( cj( "#is_for_organization" ).prop( 'checked' ) || onBehalfRequired ) {
ab234a8a 153 var urlPath = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&onbehalf=1&id=$contributionPageID&qfKey=$qfKey"}";
061a96be
CW
154 {if $mode eq 'test'}
155 urlPath += '&action=preview';
156 {/if}
157 {if $reset}
158 urlPath += '&reset={$reset}';
159 {/if}{literal}
160 cj("#onBehalfOfOrg").show();
ab234a8a
CW
161 if (cj("fieldset", '#onBehalfOfOrg').length < 1) {
162 cj('#onBehalfOfOrg').load(urlPath);
6a488035 163 }
6a488035
TO
164 }
165 else {
061a96be 166 cj("#onBehalfOfOrg").hide();
6a488035
TO
167 }
168}
169
c31d8ebb 170function resetValues() {
2fd2fc79
CW
171 // Don't trip chain-select when clearing values
172 cj('.crm-chain-select-control', "#select_org div").select2('val', '');
173 cj('input[type=text], select, textarea', "#select_org div").not('.crm-chain-select-control, #onbehalfof_id').val('').change();
174 cj('input[type=radio], input[type=checkbox]', "#select_org div").prop('checked', false).change();
6a488035
TO
175}
176
177function createNew( ) {
8539f25d 178 if (cj("#mode").prop('checked')) {
061a96be 179 var textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
8282178a 180 cj("#onbehalf_organization_name").prop('readonly', false);
8539f25d 181 cj("#mode").prop('checked', false);
c31d8ebb 182 resetValues();
6a488035
TO
183 }
184 else {
061a96be 185 var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
8539f25d 186 cj("#mode").prop('checked', true);
6a488035
TO
187 setOrgName( );
188 }
189 cj("#createNewOrg").text(textMessage);
190}
191
192function setOrgName( ) {
193 var orgName = "{/literal}{$organizationName}{literal}";
194 var orgId = "{/literal}{$orgId}{literal}";
195 cj("#onbehalf_organization_name").val(orgName);
196 cj("#onbehalf_organization_name").attr('readonly', true);
197 setLocationDetails(orgId);
198}
199
200
8d7965a3 201function setLocationDetails(contactID , reset) {
202 var submittedCID = {/literal}"{$submittedOnBehalf}"{literal};
203 var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
d940bda2 204 if (submittedOnBehalfInfo) {
205 submittedOnBehalfInfo = cj.parseJSON(submittedOnBehalfInfo);
0f449ae6 206
207 if (submittedCID == contactID) {
208 cj.each(submittedOnBehalfInfo, function(key, value) {
209 cj('#onbehalf_' + key ).val(value);
210 });
211 return;
212 }
8d7965a3 213 }
214
c31d8ebb 215 resetValues();
6a488035
TO
216 var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
217 cj.ajax({
218 url : locationUrl,
219 dataType : "json",
220 timeout : 5000, //Time in milliseconds
221 success : function(data, status) {
222 for (var ele in data) {
2fd2fc79
CW
223 if (cj("#"+ ele).hasClass('crm-chain-select-target')) {
224 cj("#"+ ele).data('newVal', data[ele].value).off('.autofill').on('crmOptionsUpdated.autofill', function() {console.log(this.id, cj(this).data('newVal'));
225 cj(this).off('.autofill').val(cj(this).data('newVal')).change();
226 });
227 }
6a488035
TO
228 if (data[ele].type == 'Radio') {
229 if (data[ele].value) {
8539f25d 230 cj("input[name='"+ ele +"']").filter("[value=" + data[ele].value + "]").prop('checked', true);
6a488035
TO
231 }
232 }
233 else if (data[ele].type == 'CheckBox') {
234 if (data[ele].value) {
8539f25d 235 cj("input[name='"+ ele +"']").prop('checked','checked');
6a488035
TO
236 }
237 }
238 else if (data[ele].type == 'Multi-Select') {
239 for (var selectedOption in data[ele].value) {
6f9cd76f 240 cj('#' + ele + " option[value='" + selectedOption + "']").prop('selected', true);
6a488035
TO
241 }
242 }
243 else if (data[ele].type == 'Autocomplete-Select') {
244 cj('#' + ele ).val( data[ele].value );
245 cj('#' + ele + '_id').val(data[ele].id);
246 }
247 else if (data[ele].type == 'AdvMulti-Select') {
248 var customFld = ele.replace('onbehalf_', '');
249 // remove empty value if any
250 cj('#onbehalf\\['+ customFld +'\\]-f option[value=""]').remove();
251 cj('#onbehalf\\['+ customFld +'\\]-t option[value=""]').remove();
252
253 for (var selectedOption in data[ele].value) {
254 // remove selected values from left and selected values to right
255 cj('#onbehalf\\['+ customFld +'\\]-f option[value="' + selectedOption + '"]').remove()
256 .appendTo('#onbehalf\\['+ customFld +'\\]-t');
d940bda2 257 cj('#onbehalf_'+ customFld).val(selectedOption);
6a488035
TO
258 }
259 }
260 else {
2fd2fc79 261 cj('#' + ele ).val(data[ele].value).change();
6a488035
TO
262 }
263 }
264 },
265 error : function(XMLHttpRequest, textStatus, errorThrown) {
822863c1 266 CRM.console('error', "HTTP error status: ", textStatus);
6a488035
TO
267 }
268 });
269}
270
6a488035 271cj("input:radio[name='org_option']").click( function( ) {
ca5bbc71 272 var orgOption = cj(this).val();
6a488035
TO
273 selectCreateOrg(orgOption, true);
274});
275
ca5bbc71
CW
276cj('#onbehalfof_id').change(function() {
277 setLocationDetails(cj(this).val());
278}).change();
279
6a488035
TO
280function selectCreateOrg( orgOption, reset ) {
281 if (orgOption == 0) {
ca5bbc71 282 cj("#onbehalfof_id").show().change();
c343285b 283 cj("input#onbehalf_organization_name").hide();
6a488035
TO
284 }
285 else if ( orgOption == 1 ) {
ca5bbc71
CW
286 cj("input#onbehalf_organization_name").show();
287 cj("#onbehalfof_id").hide();
6a488035
TO
288 }
289
290 if ( reset ) {
c31d8ebb 291 resetValues();
6a488035
TO
292 }
293}
294
295{/literal}
296{if ($relatedOrganizationFound or $onBehalfRequired) and $reset and $organizationName}
297 setOrgName( );
298{else}
299 cj("#orgOptions").show( );
300 var orgOption = cj("input:radio[name=org_option]:checked").val( );
301 selectCreateOrg(orgOption, false);
302{/if}
303
304{* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
305{if $membershipContactID}
306{literal}
3cc60a06 307 CRM.$(function($) {
ae8f569f
CW
308 $('#organization_id').val("{/literal}{$membershipContactName}{literal}");
309 $('#organization_name').val("{/literal}{$membershipContactName}{literal}");
310 $('#onbehalfof_id').val("{/literal}{$membershipContactID}{literal}");
6a488035
TO
311 setLocationDetails( "{/literal}{$membershipContactID}{literal}" );
312 });
313{/literal}
314{/if}
315
316</script>
ab234a8a 317{/if}