2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
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 +--------------------------------------------------------------------+
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?
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}
38 <div id='orgOptions' class="section crm-section">
40 {$form.org_option.html}
45 <div id="select_org" class="crm-section">
46 {foreach from=$onBehalfOfFields item=onBehaldField key=fieldName}
47 {if $onBehalfOfFields.$fieldName.skipDisplay}
50 {if $onBehalfOfFields.$fieldName.field_type eq "Formatting"}
51 {$onBehalfOfFields.$fieldName.help_pre}
54 <div class="crm-section {$onBehalfOfFields.$fieldName.name}-section">
55 {if $onBehalfOfFields.$fieldName.help_pre}
56 <span class='description'>{$onBehalfOfFields.$fieldName.help_pre}</span>
59 {if ( $fieldName eq 'organization_name' ) and $organizationName}
60 <div id='org_name' class="label">{$form.onbehalf.$fieldName.label}</div>
62 {$form.onbehalf.$fieldName.html|crmAddClass:big}
64 ( <a id='createNewOrg' href="#" onclick="createNew( ); return false;">{ts}Enter a new organization{/ts}</a> )
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}
69 {if $onBehalfOfFields.$fieldName.help_post}
70 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
74 {if $onBehalfOfFields.$fieldName.options_per_line}
75 <div class="label option-label">{$form.onbehalf.$fieldName.label}</div>
77 {assign var="count" value="1"}
79 <table class="form-layout-compressed">
81 {* sort by fails for option per line. Added a variable to iterate through the element array*}
82 {assign var="index" value="1"}
83 {foreach name=outer key=key item=item from=$form.onbehalf.$fieldName}
85 {assign var="index" value=`$index+1`}
87 <td class="labels font-light">{$form.onbehalf.$fieldName.$key.html}</td>
88 {if $count == $onBehalfOfFields.$fieldName.options_per_line}
91 {assign var="count" value="1"}
93 {assign var="count" value=`$count+1`}
100 {if $onBehalfOfFields.$fieldName.help_post}
101 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
105 <div class="label">{$form.onbehalf.$fieldName.label}</div>
106 <div class="content">
107 {$form.onbehalf.$fieldName.html}
108 {if $fieldName eq 'organization_name'}
109 <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>
111 {if $onBehalfOfFields.$fieldName.name|substr:0:5 eq 'phone'}
112 {assign var="phone_ext_field" value=$onBehalfOfFields.$fieldName.name|replace:'phone':'phone_ext'}
113 {if $form.onbehalf.$phone_ext_field.html}
114 {$form.onbehalf.$phone_ext_field.html}
117 {if $onBehalfOfFields.$fieldName.help_post}
118 <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
123 <div class="clear"></div>
127 <div>{$form.mode.html}</div>
132 <script type="text/javascript">
133 cj( "div#id-onbehalf-orgname-help").hide( );
135 showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
137 cj( "#mode" ).hide( );
138 cj( "#mode" ).prop('checked', true );
139 if ( cj( "#mode" ).prop('checked' ) && !{/literal}"{$reset}"{literal} ) {
140 $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
141 cj( "#createNewOrg" ).text( $text );
142 cj( "#mode" ).prop('checked', false );
145 function showOnBehalf(onBehalfRequired) {
146 if ( cj( "#is_for_organization" ).prop( 'checked' ) || onBehalfRequired ) {
147 var urlPath = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&onbehalf=1&id=$contributionPageID&qfKey=$qfKey"}";
149 urlPath += '&action=preview';
152 urlPath += '&reset={$reset}';
154 cj("#onBehalfOfOrg").show();
155 if (cj("fieldset", '#onBehalfOfOrg').length < 1) {
156 cj('#onBehalfOfOrg').load(urlPath);
160 cj("#onBehalfOfOrg").hide();
164 function resetValues( filter ) {
166 cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) {
167 if ( cj(this).attr('name') != 'onbehalf[organization_name]' ) {
173 cj("#select_org div").find( 'input[type=text], select, textarea' ).each(function( ) {
177 cj("#select_org tr td").find( 'input[type=radio], input[type=checkbox]' ).each(function( ) {
178 cj(this).prop('checked', false);
182 function createNew( ) {
183 if (cj("#mode").prop('checked')) {
184 var textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
185 cj("#onbehalf_organization_name").removeAttr('readonly');
186 cj("#mode").prop('checked', false);
187 resetValues( false );
190 var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
191 cj("#mode").prop('checked', true);
194 cj("#createNewOrg").text(textMessage);
197 function setOrgName( ) {
198 var orgName = "{/literal}{$organizationName}{literal}";
199 var orgId = "{/literal}{$orgId}{literal}";
200 cj("#onbehalf_organization_name").val(orgName);
201 cj("#onbehalf_organization_name").attr('readonly', true);
202 setLocationDetails(orgId);
206 function setLocationDetails(contactID) {
208 var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
212 timeout : 5000, //Time in milliseconds
213 success : function(data, status) {
214 for (var ele in data) {
215 if (data[ele].type == 'Radio') {
216 if (data[ele].value) {
217 cj("input[name='"+ ele +"']").filter("[value=" + data[ele].value + "]").prop('checked', true);
220 else if (data[ele].type == 'CheckBox') {
221 if (data[ele].value) {
222 cj("input[name='"+ ele +"']").prop('checked','checked');
225 else if (data[ele].type == 'Multi-Select') {
226 for (var selectedOption in data[ele].value) {
227 cj('#' + ele + " option[value='" + selectedOption + "']").prop('selected', true);
230 else if (data[ele].type == 'Autocomplete-Select') {
231 cj('#' + ele ).val( data[ele].value );
232 cj('#' + ele + '_id').val(data[ele].id);
234 else if (data[ele].type == 'AdvMulti-Select') {
235 var customFld = ele.replace('onbehalf_', '');
236 // remove empty value if any
237 cj('#onbehalf\\['+ customFld +'\\]-f option[value=""]').remove();
238 cj('#onbehalf\\['+ customFld +'\\]-t option[value=""]').remove();
240 for (var selectedOption in data[ele].value) {
241 // remove selected values from left and selected values to right
242 cj('#onbehalf\\['+ customFld +'\\]-f option[value="' + selectedOption + '"]').remove()
243 .appendTo('#onbehalf\\['+ customFld +'\\]-t');
247 cj('#' + ele ).val(data[ele].value);
251 error : function(XMLHttpRequest, textStatus, errorThrown) {
252 console.error("HTTP error status: ", textStatus);
258 cj("input:radio[name='org_option']").click( function( ) {
259 orgOption = cj("input:radio[name='org_option']:checked").val( );
260 selectCreateOrg(orgOption, true);
263 function selectCreateOrg( orgOption, reset ) {
264 if (orgOption == 0) {
265 cj("div#id-onbehalf-orgname-help").show( );
266 var dataUrl = {/literal}"{$employerDataURL}"{literal};
267 cj('#onbehalf_organization_name').autocomplete( dataUrl,
270 matchContains : true,
271 max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
272 }).result( function( event, data, formatted ) {
273 cj('#onbehalf_organization_name').val( data[0] );
274 cj('#onbehalfof_id').val( data[1] );
275 setLocationDetails( data[1] );
278 else if ( orgOption == 1 ) {
279 cj("input#onbehalf_organization_name").removeClass( 'ac_input' ).unautocomplete( );
280 cj("div#id-onbehalf-orgname-help").hide( );
284 resetValues( false );
289 {if ($relatedOrganizationFound or $onBehalfRequired) and $reset and $organizationName}
292 cj("#orgOptions").show( );
293 var orgOption = cj("input:radio[name=org_option]:checked").val( );
294 selectCreateOrg(orgOption, false);
297 {* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
298 {if $membershipContactID}
301 cj('#organization_id').val("{/literal}{$membershipContactName}{literal}");
302 cj('#organization_name').val("{/literal}{$membershipContactName}{literal}");
303 cj('#onbehalfof_id').val("{/literal}{$membershipContactID}{literal}");
304 setLocationDetails( "{/literal}{$membershipContactID}{literal}" );