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