Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
3 | | CiviCRM version 4.3 | | |
4 | +--------------------------------------------------------------------+ | |
5 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 file provides the HTML for the on-behalf-of form. Can also be used for related contact edit form. *} | |
27 | ||
28 | {if $buildOnBehalfForm or $onBehalfRequired} | |
29 | <fieldset id="for_organization" class="for_organization-group"> | |
30 | <legend>{$fieldSetTitle}</legend> | |
31 | {if ( $relatedOrganizationFound or $onBehalfRequired ) and !$organizationName} | |
32 | <div id='orgOptions' class="section crm-section"> | |
33 | <div class="content"> | |
34 | {$form.org_option.html} | |
35 | </div> | |
36 | </div> | |
37 | {/if} | |
38 | ||
39 | <div id="select_org" class="crm-section"> | |
40 | {foreach from=$onBehalfOfFields item=onBehaldField key=fieldName} | |
41 | {if $onBehalfOfFields.$fieldName.skipDisplay} | |
42 | {continue} | |
43 | {/if} | |
44 | {if $onBehalfOfFields.$fieldName.field_type eq "Formatting"} | |
45 | {$onBehalfOfFields.$fieldName.help_pre} | |
46 | {continue} | |
47 | {/if} | |
48 | <div class="crm-section {$onBehalfOfFields.$fieldName.name}-section"> | |
49 | {if $onBehalfOfFields.$fieldName.help_pre} | |
50 | <span class='description'>{$onBehalfOfFields.$fieldName.help_pre}</span> | |
51 | {/if} | |
52 | ||
53 | {if ( $fieldName eq 'organization_name' ) and $organizationName} | |
54 | <div id='org_name' class="label">{$form.onbehalf.$fieldName.label}</div> | |
55 | <div class="content"> | |
56 | {$form.onbehalf.$fieldName.html|crmAddClass:big} | |
57 | <span> | |
b7054e52 | 58 | ( <a id='createNewOrg' href="#" onclick="createNew( ); return false;">{ts}Enter a new organization{/ts}</a> ) |
6a488035 TO |
59 | </span> |
60 | <div id="id-onbehalf-orgname-enter-help" class="description"> | |
61 | {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} | |
62 | </div> | |
63 | {if $onBehalfOfFields.$fieldName.help_post} | |
64 | <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span> | |
65 | {/if} | |
66 | </div> | |
67 | {else} | |
68 | {if $onBehalfOfFields.$fieldName.options_per_line != 0} | |
69 | <div class="label option-label">{$form.onbehalf.$fieldName.label}</div> | |
70 | <div class="content 3"> | |
71 | {assign var="count" value="1"} | |
72 | {strip} | |
73 | <table class="form-layout-compressed"> | |
74 | <tr> | |
75 | {* sort by fails for option per line. Added a variable to iterate through the element array*} | |
76 | {assign var="index" value="1"} | |
77 | {foreach name=outer key=key item=item from=$field} | |
78 | {if $index < 10} | |
79 | {assign var="index" value=`$index+1`} | |
80 | {else} | |
81 | <td class="labels font-light">{$form.onbehalf.$fieldName.$key.html}</td> | |
82 | {if $count == $onBehalfOfFields.$fieldName.options_per_line} | |
83 | </tr> | |
84 | <tr> | |
85 | {assign var="count" value="1"} | |
86 | {else} | |
87 | {assign var="count" value=`$count+1`} | |
88 | {/if} | |
89 | {/if} | |
90 | {/foreach} | |
91 | </tr> | |
92 | </table> | |
93 | {/strip} | |
94 | {if $onBehalfOfFields.$fieldName.help_post} | |
95 | <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span> | |
96 | {/if} | |
97 | </div> | |
98 | {else} | |
99 | <div class="label">{$form.onbehalf.$fieldName.label}</div> | |
100 | <div class="content"> | |
101 | {$form.onbehalf.$fieldName.html} | |
102 | {if $fieldName eq 'organization_name'} | |
103 | <div id="id-onbehalf-orgname-help" class="description">{ts}Start typing the name of an organization that you have saved previously to use it again. Otherwise click "Enter a new organization" above.{/ts}</div> | |
104 | {/if} | |
105 | {if !empty($onBehalfOfFields.$fieldName.html_type) && $onBehalfOfFields.$fieldName.html_type eq 'Autocomplete-Select'} | |
106 | {assign var=elementName value=onbehalf[$fieldName]} | |
107 | {include file="CRM/Custom/Form/AutoComplete.tpl" element_name=$elementName} | |
108 | {/if} | |
109 | {if $onBehalfOfFields.$fieldName.name|substr:0:5 eq 'phone'} | |
110 | {assign var="phone_ext_field" value=$onBehalfOfFields.$fieldName.name|replace:'phone':'phone_ext'} | |
111 | {if $form.onbehalf.$phone_ext_field.html} | |
112 | {$form.onbehalf.$phone_ext_field.html} | |
113 | {/if} | |
114 | {/if} | |
115 | {if $onBehalfOfFields.$fieldName.help_post} | |
116 | <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span> | |
117 | {/if} | |
118 | </div> | |
119 | {/if} | |
120 | {/if} | |
121 | <div class="clear"></div> | |
122 | </div> | |
123 | {/foreach} | |
124 | </div> | |
125 | <div>{$form.mode.html}</div> | |
126 | {/if} | |
127 | ||
128 | {literal} | |
129 | <script type="text/javascript"> | |
130 | var reset = {/literal}"{$reset}"{literal}; | |
131 | var onBehalfRequired = {/literal}"{$onBehalfRequired}"{literal}; | |
132 | var mainDisplay = {/literal}"{$mainDisplay}"{literal}; | |
133 | var mode = {/literal}"{$mode}"{literal}; | |
134 | cj( "div#id-onbehalf-orgname-help").hide( ); | |
135 | ||
136 | if (mainDisplay) { | |
137 | showOnBehalf(false); | |
138 | } | |
139 | ||
140 | cj( "#mode" ).hide( ); | |
141 | cj( "#mode" ).attr( 'checked', 'checked' ); | |
142 | if ( cj( "#mode" ).attr( 'checked' ) && !reset ) { | |
143 | $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} '; | |
144 | cj( "#createNewOrg" ).text( $text ); | |
145 | cj( "#mode" ).removeAttr( 'checked' ); | |
146 | } | |
147 | ||
148 | function showOnBehalf(onBehalfRequired) { | |
149 | if ( cj( "#is_for_organization" ).attr( 'checked' ) || onBehalfRequired ) { | |
150 | cj( "#for_organization" ).html( '' ); | |
151 | var urlPath = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&onbehalf=1'}"{literal}; | |
152 | urlPath = urlPath + {/literal}"{$urlParams}"{literal}; | |
153 | if ( mode == 'test' ) { | |
154 | urlPath = urlPath + '&action=preview'; | |
155 | } | |
156 | if ( reset ) { | |
157 | urlPath = urlPath + '&reset=' + reset; | |
158 | } | |
159 | ||
160 | cj.ajax({ | |
161 | url : urlPath, | |
162 | async : false, | |
163 | global : false, | |
164 | success : function ( content ) { | |
165 | cj( "#onBehalfOfOrg" ).html( content ); | |
166 | } | |
167 | }); | |
168 | } | |
169 | else { | |
170 | cj( "#onBehalfOfOrg" ).html(''); | |
171 | cj( "#for_organization" ).html( '' ); | |
172 | return; | |
173 | } | |
174 | } | |
175 | ||
176 | function resetValues( filter ) { | |
177 | if (filter) { | |
178 | cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) { | |
179 | if ( cj(this).attr('name') != 'onbehalf[organization_name]' ) { | |
180 | cj(this).val(''); | |
181 | } | |
182 | }); | |
183 | } | |
184 | else { | |
185 | cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) { | |
186 | cj(this).val( '' ); | |
187 | }); | |
188 | } | |
189 | cj("#select_org tr td").find( 'input[type=radio], input[type=checkbox]' ).each(function( ) { | |
190 | cj(this).attr('checked', false); | |
191 | }); | |
192 | } | |
193 | ||
194 | function createNew( ) { | |
195 | if (cj("#mode").attr('checked')) { | |
196 | textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} '; | |
197 | cj("#onbehalf_organization_name").removeAttr('readonly'); | |
198 | cj("#mode").removeAttr('checked'); | |
199 | ||
200 | resetValues( false ); | |
201 | } | |
202 | else { | |
203 | textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} '; | |
204 | cj("#mode").attr('checked', 'checked'); | |
205 | setOrgName( ); | |
206 | } | |
207 | cj("#createNewOrg").text(textMessage); | |
208 | } | |
209 | ||
210 | function setOrgName( ) { | |
211 | var orgName = "{/literal}{$organizationName}{literal}"; | |
212 | var orgId = "{/literal}{$orgId}{literal}"; | |
213 | cj("#onbehalf_organization_name").val(orgName); | |
214 | cj("#onbehalf_organization_name").attr('readonly', true); | |
215 | setLocationDetails(orgId); | |
216 | } | |
217 | ||
218 | ||
219 | function setLocationDetails(contactID) { | |
220 | resetValues(true); | |
221 | var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal}; | |
222 | cj.ajax({ | |
223 | url : locationUrl, | |
224 | dataType : "json", | |
225 | timeout : 5000, //Time in milliseconds | |
226 | success : function(data, status) { | |
227 | for (var ele in data) { | |
228 | if (data[ele].type == 'Radio') { | |
229 | if (data[ele].value) { | |
230 | cj("input[name='"+ ele +"']").filter("[value=" + data[ele].value + "]").attr('checked', 'checked'); | |
231 | } | |
232 | } | |
233 | else if (data[ele].type == 'CheckBox') { | |
234 | if (data[ele].value) { | |
235 | cj("input[name='"+ ele +"']").attr('checked','checked'); | |
236 | } | |
237 | } | |
238 | else if (data[ele].type == 'Multi-Select') { | |
239 | for (var selectedOption in data[ele].value) { | |
240 | cj('#' + ele + " option[value='" + selectedOption + "']").attr('selected', 'selected'); | |
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'); | |
257 | } | |
258 | } | |
259 | else { | |
260 | cj('#' + ele ).val(data[ele].value); | |
261 | } | |
262 | } | |
263 | }, | |
264 | error : function(XMLHttpRequest, textStatus, errorThrown) { | |
265 | console.error("HTTP error status: ", textStatus); | |
266 | } | |
267 | }); | |
268 | } | |
269 | ||
270 | var orgOption = ''; | |
271 | cj("input:radio[name='org_option']").click( function( ) { | |
272 | orgOption = cj("input:radio[name='org_option']:checked").val( ); | |
273 | selectCreateOrg(orgOption, true); | |
274 | }); | |
275 | ||
276 | function selectCreateOrg( orgOption, reset ) { | |
277 | if (orgOption == 0) { | |
278 | cj("div#id-onbehalf-orgname-help").show( ); | |
279 | var dataUrl = {/literal}"{$employerDataURL}"{literal}; | |
280 | cj('#onbehalf_organization_name').autocomplete( dataUrl, | |
281 | { width : 180, | |
282 | selectFirst : false, | |
283 | matchContains : true | |
284 | }).result( function( event, data, formatted ) { | |
285 | cj('#onbehalf_organization_name').val( data[0] ); | |
286 | cj('#onbehalfof_id').val( data[1] ); | |
287 | setLocationDetails( data[1] ); | |
288 | }); | |
289 | } | |
290 | else if ( orgOption == 1 ) { | |
291 | cj("input#onbehalf_organization_name").removeClass( 'ac_input' ).unautocomplete( ); | |
292 | cj("div#id-onbehalf-orgname-help").hide( ); | |
293 | } | |
294 | ||
295 | if ( reset ) { | |
296 | resetValues( false ); | |
297 | } | |
298 | } | |
299 | ||
300 | {/literal} | |
301 | {if ($relatedOrganizationFound or $onBehalfRequired) and $reset and $organizationName} | |
302 | setOrgName( ); | |
303 | {else} | |
304 | cj("#orgOptions").show( ); | |
305 | var orgOption = cj("input:radio[name=org_option]:checked").val( ); | |
306 | selectCreateOrg(orgOption, false); | |
307 | {/if} | |
308 | ||
309 | {* If mid present in the url, take the required action (poping up related existing contact ..etc) *} | |
310 | {if $membershipContactID} | |
311 | {literal} | |
312 | cj( function( ) { | |
313 | cj('#organization_id').val("{/literal}{$membershipContactName}{literal}"); | |
314 | cj('#organization_name').val("{/literal}{$membershipContactName}{literal}"); | |
315 | cj('#onbehalfof_id').val("{/literal}{$membershipContactID}{literal}"); | |
316 | setLocationDetails( "{/literal}{$membershipContactID}{literal}" ); | |
317 | }); | |
318 | {/literal} | |
319 | {/if} | |
320 | ||
321 | </script> | |
b7054e52 | 322 | </fieldset> |