2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
26 {* This file provides the HTML for the on-behalf-of form. Can also be used for related contact edit form. *}
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">
34 {$form.org_option.html}
39 <div id="select_org" class="crm-section">
40 {foreach from=$onBehalfOfFields item=onBehaldField key=fieldName}
41 {if $onBehalfOfFields.$fieldName.skipDisplay}
44 {if $onBehalfOfFields.$fieldName.field_type eq "Formatting"}
45 {$onBehalfOfFields.$fieldName.help_pre}
48 <div class="crm-section {$onBehalfOfFields.$fieldName.name}-section">
49 {if $onBehalfOfFields.$fieldName.help_pre}
50 <span class='description'>{$onBehalfOfFields.$fieldName.help_pre}</span>
53 {if ( $fieldName eq 'organization_name' ) and $organizationName}
54 <div id='org_name' class="label">{$form.onbehalf.$fieldName.label}</div>
56 {$form.onbehalf.$fieldName.html|crmAddClass:big}
58 ( <a id='createNewOrg' href="#" onclick="createNew( ); return false;">{ts}Enter a new organization{/ts}</a> )
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}
63 {if $onBehalfOfFields.$fieldName.help_post}
64 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
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"}
73 <table class="form-layout-compressed">
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}
79 {assign var="index" value=`$index+1`}
81 <td class="labels font-light">{$form.onbehalf.$fieldName.$key.html}</td>
82 {if $count == $onBehalfOfFields.$fieldName.options_per_line}
85 {assign var="count" value="1"}
87 {assign var="count" value=`$count+1`}
94 {if $onBehalfOfFields.$fieldName.help_post}
95 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
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>
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}
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}
115 {if $onBehalfOfFields.$fieldName.help_post}
116 <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
121 <div class="clear"></div>
125 <div>{$form.mode.html}</div>
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( );
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' );
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';
157 urlPath = urlPath + '&reset=' + reset;
164 success : function ( content ) {
165 cj( "#onBehalfOfOrg" ).html( content );
170 cj( "#onBehalfOfOrg" ).html('');
171 cj( "#for_organization" ).html( '' );
176 function resetValues( filter ) {
178 cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) {
179 if ( cj(this).attr('name') != 'onbehalf[organization_name]' ) {
185 cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) {
189 cj("#select_org tr td").find( 'input[type=radio], input[type=checkbox]' ).each(function( ) {
190 cj(this).attr('checked', false);
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');
200 resetValues( false );
203 textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
204 cj("#mode").attr('checked', 'checked');
207 cj("#createNewOrg").text(textMessage);
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);
219 function setLocationDetails(contactID) {
221 var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
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');
233 else if (data[ele].type == 'CheckBox') {
234 if (data[ele].value) {
235 cj("input[name='"+ ele +"']").attr('checked','checked');
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');
243 else if (data[ele].type == 'Autocomplete-Select') {
244 cj('#' + ele ).val( data[ele].value );
245 cj('#' + ele + '_id').val(data[ele].id);
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();
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');
260 cj('#' + ele ).val(data[ele].value);
264 error : function(XMLHttpRequest, textStatus, errorThrown) {
265 console.error("HTTP error status: ", textStatus);
271 cj("input:radio[name='org_option']").click( function( ) {
272 orgOption = cj("input:radio[name='org_option']:checked").val( );
273 selectCreateOrg(orgOption, true);
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,
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] );
290 else if ( orgOption == 1 ) {
291 cj("input#onbehalf_organization_name").removeClass( 'ac_input' ).unautocomplete( );
292 cj("div#id-onbehalf-orgname-help").hide( );
296 resetValues( false );
301 {if ($relatedOrganizationFound or $onBehalfRequired) and $reset and $organizationName}
304 cj("#orgOptions").show( );
305 var orgOption = cj("input:radio[name=org_option]:checked").val( );
306 selectCreateOrg(orgOption, false);
309 {* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
310 {if $membershipContactID}
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}" );