commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / templates / CRM / Contribute / Form / Contribution / OnBehalfOf.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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 {**
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?
31 *}
32
33 {if $buildOnBehalfForm or $onBehalfRequired}
34 {if $context eq 'front-end'}
35 <div class="crm-public-form-item crm-section">
36 {/if}
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">
41 <div class="content">
42 {$form.org_option.html}
43 </div>
44 </div>
45 {/if}
46
47 <div id="select_org" class="crm-section">
48 {foreach from=$onBehalfOfFields item=onBehaldField key=fieldName}
49 {if $onBehalfOfFields.$fieldName.skipDisplay}
50 {continue}
51 {/if}
52 {if $onBehalfOfFields.$fieldName.field_type eq "Formatting"}
53 {$onBehalfOfFields.$fieldName.help_pre}
54 {continue}
55 {/if}
56 <div class="crm-section {$onBehalfOfFields.$fieldName.name}-section">
57 {if $onBehalfOfFields.$fieldName.help_pre}
58 &nbsp;&nbsp;<span class='description'>{$onBehalfOfFields.$fieldName.help_pre}</span>
59 {/if}
60
61 {if ( $fieldName eq 'organization_name' ) and $organizationName}
62 <div id='org_name' class="label">{$form.onbehalf.$fieldName.label}</div>
63 <div class="content">
64 {$form.onbehalf.$fieldName.html|crmAddClass:big}
65 <span>
66 ( <a id='createNewOrg' href="#" onclick="createNew( ); return false;">{ts}Enter a new organization{/ts}</a> )
67 </span>
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}
70 </div>
71 {if $onBehalfOfFields.$fieldName.help_post}
72 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
73 {/if}
74 </div>
75 {else}
76 {if $onBehalfOfFields.$fieldName.options_per_line}
77 <div class="label option-label">{$form.onbehalf.$fieldName.label}</div>
78 <div class="content">
79 {assign var="count" value="1"}
80 {strip}
81 <table class="form-layout-compressed">
82 <tr>
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}
86 {if $index < 10}
87 {assign var="index" value=`$index+1`}
88 {else}
89 <td class="labels font-light">{$form.onbehalf.$fieldName.$key.html}</td>
90 {if $count == $onBehalfOfFields.$fieldName.options_per_line}
91 </tr>
92 <tr>
93 {assign var="count" value="1"}
94 {else}
95 {assign var="count" value=`$count+1`}
96 {/if}
97 {/if}
98 {/foreach}
99 </tr>
100 </table>
101 {/strip}
102 {if $onBehalfOfFields.$fieldName.help_post}
103 <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
104 {/if}
105 </div>
106 {else}
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}
111 {/if}
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}
117 {/if}
118 {/if}
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 &nbsp;{$form.onbehalf.$phone_ext_field.html}
123 {/if}
124 {/if}
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}
128 {/if}
129 {if $onBehalfOfFields.$fieldName.help_post}
130 <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
131 {/if}
132 </div>
133 {/if}
134 {/if}
135 <div class="clear"></div>
136 </div>
137 {/foreach}
138 </div>
139 <div>{$form.mode.html}</div>
140 </fieldset>
141 {if $context eq 'front-end'}
142 </div>
143 {/if}
144 {/if}
145 {if empty($snippet)}
146 {literal}
147 <script type="text/javascript">
148
149 showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
150
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 );
157 }
158
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"}";
162 {if $mode eq 'test'}
163 urlPath += '&action=preview';
164 {/if}
165 {if $reset}
166 urlPath += '&reset={$reset}';
167 {/if}{literal}
168 cj("#onBehalfOfOrg").show();
169 if (cj("fieldset", '#onBehalfOfOrg').length < 1) {
170 cj('#onBehalfOfOrg').load(urlPath);
171 }
172 }
173 else {
174 cj("#onBehalfOfOrg").hide();
175 }
176 }
177
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();
183 }
184
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);
190 resetValues();
191 }
192 else {
193 var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
194 cj("#mode").prop('checked', true);
195 setOrgName( );
196 }
197 cj("#createNewOrg").text(textMessage);
198 }
199
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);
206 }
207
208
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);
214
215 if (submittedCID == contactID) {
216 cj.each(submittedOnBehalfInfo, function(key, value) {
217 cj('#onbehalf_' + key ).val(value);
218 });
219 return;
220 }
221 }
222
223 resetValues();
224 var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
225 cj.ajax({
226 url : locationUrl,
227 dataType : "json",
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();
234 });
235 }
236 else if (cj('#' + ele).data('select2')) {
237 cj('#' + ele).select2('val', data[ele].value);
238 }
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);
243 }
244 }
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');
249 }
250 }
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();
256
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);
262 }
263 }
264 else {
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();
269 }
270 else {
271 cj('#' + ele ).val(data[ele].value).change();
272 }
273 }
274 }
275 }
276 },
277 error : function(XMLHttpRequest, textStatus, errorThrown) {
278 CRM.console('error', "HTTP error status: ", textStatus);
279 }
280 });
281 }
282
283 cj("input:radio[name='org_option']").click( function( ) {
284 var orgOption = cj(this).val();
285 selectCreateOrg(orgOption, true);
286 });
287
288 cj('#onbehalfof_id').change(function() {
289 setLocationDetails(cj(this).val());
290 }).change();
291
292 function selectCreateOrg( orgOption, reset ) {
293 if (orgOption == 0) {
294 cj("#onbehalfof_id").show().change();
295 cj("input#onbehalf_organization_name").hide();
296 }
297 else if ( orgOption == 1 ) {
298 cj("input#onbehalf_organization_name").show();
299 cj("#onbehalfof_id").hide();
300 }
301
302 if ( reset ) {
303 resetValues();
304 }
305 }
306
307 {/literal}
308 {if ($relatedOrganizationFound or $onBehalfRequired) and $reset and $organizationName}
309 setOrgName( );
310 {else}
311 cj("#orgOptions").show( );
312 var orgOption = cj("input:radio[name=org_option]:checked").val( );
313 selectCreateOrg(orgOption, false);
314 {/if}
315
316 {* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
317 {if $membershipContactID}
318 {literal}
319 CRM.$(function($) {
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}" );
324 });
325 {/literal}
326 {/if}
327
328 </script>
329 {/if}