2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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: Why are we not just using the dynamic form tpl to display this profile?
33 {if $buildOnBehalfForm or $onBehalfRequired}
34 {if $context eq 'front-end'}
35 <div class="crm-public-form-item crm-section">
37 <fieldset id="for_organization" class="for_organization-group">
38 <legend>{$fieldSetTitle}</legend>
39 {if ( $relatedOrganizationFound or $onBehalfRequired ) and !$organizationName}
40 <div id='orgOptions' class="section crm-section">
42 {$form.org_option.html}
47 <div id="select_org" class="crm-section">
48 {foreach from=$onBehalfOfFields item=onBehaldField key=fieldName}
49 {if $onBehalfOfFields.$fieldName.skipDisplay}
52 {if $onBehalfOfFields.$fieldName.field_type eq "Formatting"}
53 {$onBehalfOfFields.$fieldName.help_pre}
56 <div class="crm-section {$onBehalfOfFields.$fieldName.name}-section">
57 {if $onBehalfOfFields.$fieldName.help_pre}
58 <span class='description'>{$onBehalfOfFields.$fieldName.help_pre}</span>
61 {if ( $fieldName eq 'organization_name' ) and $organizationName}
62 <div id='org_name' class="label">{$form.onbehalf.$fieldName.label}</div>
64 {$form.onbehalf.$fieldName.html|crmAddClass:big}
66 ( <a id='createNewOrg' href="#" onclick="createNew( ); return false;">{ts}Enter a new organization{/ts}</a> )
68 <div id="id-onbehalf-orgname-enter-help" class="description">
69 {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}
71 {if $onBehalfOfFields.$fieldName.help_post}
72 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
76 {if $onBehalfOfFields.$fieldName.options_per_line}
77 <div class="label option-label">{$form.onbehalf.$fieldName.label}</div>
79 {assign var="count" value="1"}
81 <table class="form-layout-compressed">
83 {* sort by fails for option per line. Added a variable to iterate through the element array*}
84 {assign var="index" value="1"}
85 {foreach name=outer key=key item=item from=$form.onbehalf.$fieldName}
87 {assign var="index" value=`$index+1`}
89 <td class="labels font-light">{$form.onbehalf.$fieldName.$key.html}</td>
90 {if $count == $onBehalfOfFields.$fieldName.options_per_line}
93 {assign var="count" value="1"}
95 {assign var="count" value=`$count+1`}
102 {if $onBehalfOfFields.$fieldName.help_post}
103 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
107 <div class="label">{$form.onbehalf.$fieldName.label}</div>
108 <div class="content">
109 {if $fieldName eq 'organization_name' and !empty($form.onbehalfof_id)}
110 {$form.onbehalfof_id.html}
112 {$form.onbehalf.$fieldName.html}
113 {if !empty($onBehalfOfFields.$fieldName.html_type) && $onBehalfOfFields.$fieldName.html_type eq 'Autocomplete-Select'}
114 {assign var=elementName value=onbehalf[$fieldName]}
115 {if $onBehalfOfFields.$fieldName.data_type eq 'ContactReference'}
116 {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $elementName}
119 {if $onBehalfOfFields.$fieldName.name|substr:0:5 eq 'phone'}
120 {assign var="phone_ext_field" value=$onBehalfOfFields.$fieldName.name|replace:'phone':'phone_ext'}
121 {if $form.onbehalf.$phone_ext_field.html}
122 {$form.onbehalf.$phone_ext_field.html}
125 {if $onBehalfOfFields.$fieldName.data_type eq 'Date'}
126 {assign var=elementName value=onbehalf[$fieldName]}
127 {include file="CRM/common/jcalendar.tpl" elementName=$elementName elementId=onbehalf_$fieldName}
129 {if $onBehalfOfFields.$fieldName.help_post}
130 <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
135 <div class="clear"></div>
139 <div>{$form.mode.html}</div>
141 {if $context eq 'front-end'}
147 <script type="text/javascript">
149 showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
151 cj( "#mode" ).hide( );
152 cj( "#mode" ).prop('checked', true );
153 if ( cj( "#mode" ).prop('checked' ) && !{/literal}"{$reset}"{literal} ) {
154 $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
155 cj( "#createNewOrg" ).text( $text );
156 cj( "#mode" ).prop('checked', false );
159 function showOnBehalf(onBehalfRequired) {
160 if ( cj( "#is_for_organization" ).prop( 'checked' ) || onBehalfRequired ) {
161 var urlPath = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&onbehalf=1&id=$contributionPageID&qfKey=$qfKey"}";
163 urlPath += '&action=preview';
166 urlPath += '&reset={$reset}';
168 cj("#onBehalfOfOrg").show();
169 if (cj("fieldset", '#onBehalfOfOrg').length < 1) {
170 cj('#onBehalfOfOrg').load(urlPath);
174 cj("#onBehalfOfOrg").hide();
178 function resetValues() {
179 // Don't trip chain-select when clearing values
180 cj('.crm-chain-select-control', "#select_org div").select2('val', '');
181 cj('input[type=text], select, textarea', "#select_org div").not('.crm-chain-select-control, #onbehalfof_id').val('').change();
182 cj('input[type=radio], input[type=checkbox]', "#select_org div").prop('checked', false).change();
185 function createNew( ) {
186 if (cj("#mode").prop('checked')) {
187 var textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
188 cj("#onbehalf_organization_name").prop('readonly', false);
189 cj("#mode").prop('checked', false);
193 var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
194 cj("#mode").prop('checked', true);
197 cj("#createNewOrg").text(textMessage);
200 function setOrgName( ) {
201 var orgName = "{/literal}{$organizationName}{literal}";
202 var orgId = "{/literal}{$orgId}{literal}";
203 cj("#onbehalf_organization_name").val(orgName);
204 cj("#onbehalf_organization_name").attr('readonly', true);
205 setLocationDetails(orgId);
209 function setLocationDetails(contactID , reset) {
210 var submittedCID = {/literal}"{$submittedOnBehalf}"{literal};
211 var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
212 if (submittedOnBehalfInfo) {
213 submittedOnBehalfInfo = cj.parseJSON(submittedOnBehalfInfo);
215 if (submittedCID == contactID) {
216 cj.each(submittedOnBehalfInfo, function(key, value) {
217 cj('#onbehalf_' + key ).val(value);
224 var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
228 timeout : 5000, //Time in milliseconds
229 success : function(data, status) {
230 for (var ele in data) {
231 if (cj("#"+ ele).hasClass('crm-chain-select-target')) {
232 cj("#"+ ele).data('newVal', data[ele].value).off('.autofill').on('crmOptionsUpdated.autofill', function() {
233 cj(this).off('.autofill').val(cj(this).data('newVal')).change();
236 else if (cj('#' + ele).data('select2')) {
237 cj('#' + ele).select2('val', data[ele].value);
239 if (data[ele].type == 'Radio') {
240 if (data[ele].value) {
241 var fldName = ele.replace('onbehalf_', '');
242 cj("input[name='onbehalf["+ fldName +"]']").filter("[value='" + data[ele].value + "']").prop('checked', true);
245 else if (data[ele].type == 'CheckBox') {
246 for (var selectedOption in data[ele].value) {
247 var fldName = ele.replace('onbehalf_', '');
248 cj("input[name='onbehalf["+ fldName+"]["+ selectedOption +"]']").prop('checked','checked');
251 else if (data[ele].type == 'AdvMulti-Select') {
252 var customFld = ele.replace('onbehalf_', '');
253 // remove empty value if any
254 cj('#onbehalf\\['+ customFld +'\\]-f option[value=""]').remove();
255 cj('#onbehalf\\['+ customFld +'\\]-t option[value=""]').remove();
257 for (var selectedOption in data[ele].value) {
258 // remove selected values from left and selected values to right
259 cj('#onbehalf\\['+ customFld +'\\]-f option[value="' + selectedOption + '"]').remove()
260 .appendTo('#onbehalf\\['+ customFld +'\\]-t');
261 cj('#onbehalf_'+ customFld).val(selectedOption);
265 // do not set defaults to file type fields
266 if (cj('#' + ele).attr('type') != 'file') {
267 if (ele.split("_").pop() == 'display') {
268 cj("[id^='"+ele+"']").val(data[ele].value).change();
271 cj('#' + ele ).val(data[ele].value).change();
277 error : function(XMLHttpRequest, textStatus, errorThrown) {
278 CRM.console('error', "HTTP error status: ", textStatus);
283 cj("input:radio[name='org_option']").click( function( ) {
284 var orgOption = cj(this).val();
285 selectCreateOrg(orgOption, true);
288 cj('#onbehalfof_id').change(function() {
289 setLocationDetails(cj(this).val());
292 function selectCreateOrg( orgOption, reset ) {
293 if (orgOption == 0) {
294 cj("#onbehalfof_id").show().change();
295 cj("input#onbehalf_organization_name").hide();
297 else if ( orgOption == 1 ) {
298 cj("input#onbehalf_organization_name").show();
299 cj("#onbehalfof_id").hide();
308 {if ($relatedOrganizationFound or $onBehalfRequired) and $reset and $organizationName}
311 cj("#orgOptions").show( );
312 var orgOption = cj("input:radio[name=org_option]:checked").val( );
313 selectCreateOrg(orgOption, false);
316 {* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
317 {if $membershipContactID}
320 $('#organization_id').val("{/literal}{$membershipContactName}{literal}");
321 $('#organization_name').val("{/literal}{$membershipContactName}{literal}");
322 $('#onbehalfof_id').val("{/literal}{$membershipContactID}{literal}");
323 setLocationDetails( "{/literal}{$membershipContactID}{literal}" );