CRM-12865 - Define regions and CSS classes for profile forms
[civicrm-core.git] / templates / CRM / Profile / Form / Dynamic.tpl
CommitLineData
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*}
46312a4d
TO
26<div class="crm-profile-name-{$ufGroupName}">
27{crmRegion name=profile-form-`$ufGroupName`}
28
6a488035
TO
29{* Profile forms when embedded in CMS account create (mode=1) or
30 cms account edit (mode=8) or civicrm/profile (mode=4) pages *}
31{if ($context eq 'multiProfileDialog')}
32{literal}
33<script type="text/javascript">
591e7c66
RN
34cj(function($) {
35 $('#profile-dialog .crm-container-snippet #Edit').validate(CRM.validate.params);
6a488035
TO
36 var formOptions = {
37 beforeSubmit: proccessMultiRecordForm //pre-submit callback
38 };
39
40 //binding the callback to snippet profile form
591e7c66 41 $('.crm-container-snippet #Edit').ajaxForm(formOptions);
6a488035
TO
42});
43
44// pre-submit callback
45function proccessMultiRecordForm(formData, jqForm, options) {
46 var queryString = cj.param(formData);
47 queryString = queryString + '{/literal}{$urlParams}{literal}' + '&snippet=1';
48
49 if (cj('#profile-dialog')) {
50 var postUrl = {/literal}"{crmURL p='civicrm/profile/edit' h=0 }"{literal};
51 var response = cj.ajax({
52 type: "POST",
53 url: postUrl,
54 async: false,
55 data: queryString,
56 dataType: "json",
57
58 }).responseText;
59
60 //if there is any form error show the dialog
61 //else redirect to post url
591e7c66 62 if (!cj(response).find('.crm-error').html()) {
6a488035
TO
63 window.location = '{/literal}{$postUrl}{literal}';
64 }
65
66 // here we could return false to prevent the form from being submitted;
67 // returning anything other than false will allow the form submit to continue
68 return false;
69 }
70}
71</script>
72{/literal}
591e7c66 73{include file="CRM/Form/validate.tpl"}
6a488035
TO
74{/if}
75{if $deleteRecord}
76<div class="messages status no-popup">
77 <div class="icon inform-icon"></div>&nbsp;
78 {ts}Are you sure you want to delete this record?{/ts}
79 </div>
80 <span class="crm-button">{$form._qf_Edit_upload_delete.html}</span>
81 <div class="crm-submit-buttons" style='display:inline'>{include file="CRM/common/formButtons.tpl"}</div>
82{else}
83{if ! empty( $fields )}
84{* Wrap in crm-container div so crm styles are used.*}
85{* Replace div id "crm-container" only when profile is not loaded in civicrm container, i.e for profile shown in my account and in profile standalone mode otherwise id should be "crm-profile-block" *}
86
87 {if $action eq 1 or $action eq 2 or $action eq 4 }
a17a96df 88 <div id="crm-profile-block" class="crm-container-snippet crm-public">
6a488035 89 {else}
a17a96df 90 <div id="crm-container" class="crm-container crm-public" lang="{$config->lcMessages|truncate:2:"":true}" xml:lang="{$config->lcMessages|truncate:2:"":true}">
6a488035
TO
91 {/if}
92
93 {if $isDuplicate and ( ($action eq 1 and $mode eq 4 ) or ($action eq 2) or ($action eq 8192) ) }
94 <div class="crm-submit-buttons">
95 <span class="crm-button">{$form._qf_Edit_upload_duplicate.html}</span>
96 </div>
97 {/if}
98 {if $mode eq 1 || $activeComponent neq "CiviCRM"}
99 {include file="CRM/Form/body.tpl"}
100 {/if}
101 {strip}
102 {if $help_pre && $action neq 4}
103 <div class="messages help">{$help_pre}</div>
104 {/if}
105
106 {include file="CRM/common/CMSUser.tpl"}
107
108 {if $action eq 2 and $multiRecordFieldListing}
109 <h1>{ts}Edit Details{/ts}</h1>
110 <div class="crm-submit-buttons" style='float:right'>
111 {include file="CRM/common/formButtons.tpl"}{if $isDuplicate}<span class="crm-button">{$form._qf_Edit_upload_duplicate.html}</span>{/if}
112 </div>
113 {/if}
114
115 {assign var=zeroField value="Initial Non Existent Fieldset"}
116 {assign var=fieldset value=$zeroField}
117 {foreach from=$fields item=field key=fieldName}
118 {if $field.skipDisplay}
119 {continue}
120 {/if}
121 {assign var="profileID" value=$field.group_id}
122 {assign var=n value=$field.name}
b5c36756
KJ
123 {if $field.groupTitle != $fieldset}
124 {if $mode neq 8 && $mode neq 4}
125 <div {if $context neq 'dialog'}id="profilewrap{$field.group_id}"{/if}>
126 <fieldset><legend>{$field.groupTitle}</legend>
127 {/if}
128 {assign var=fieldset value=`$field.groupTitle`}
129 {assign var=groupHelpPost value=`$field.groupHelpPost`}
130 {if $field.groupHelpPre}
131 <div class="messages help">{$field.groupHelpPre}</div>
132 {/if}
133 {/if}
6a488035
TO
134 {if $field.field_type eq "Formatting"}
135 {$field.help_pre}
136 {elseif $n}
137 {if $field.groupTitle != $fieldset}
138 {if $fieldset != $zeroField}
139 {if $groupHelpPost}
140 <div class="messages help">{$groupHelpPost}</div>
141 {/if}
142 {if $mode neq 8 && $mode neq 4}
143 </div><!-- end form-layout-compressed-div -->
144 </fieldset>
145 </div>
146 {/if}
147 {/if}
6a488035
TO
148 <div class="form-layout-compressed">
149 {/if}
150 {if $field.help_pre && $action neq 4 && $form.$n.html}
151 <div class="crm-section helprow-{$n}-section" id="helprow-{$n}">
152 <div class="content description">{$field.help_pre}</div>
153 </div>
154 {/if}
155 {if $field.options_per_line}
156 <div class="crm-section editrow_{$n}-section form-item" id="editrow-{$n}">
157 <div class="label">{$form.$n.label}</div>
158 <div class="content edit-value">
159 {assign var="count" value="1"}
160 {strip}
161 <table class="form-layout-compressed">
162 <tr>
163 {* sort by fails for option per line. Added a variable to iterate through the element array*}
164 {assign var="index" value="1"}
165 {foreach name=outer key=key item=item from=$form.$n}
166 {if $index < 10}
167 {assign var="index" value=`$index+1`}
168 {else}
169 <td class="labels font-light">{$form.$n.$key.html}</td>
170 {if $count == $field.options_per_line}
171 </tr>
172 <tr>
173 {assign var="count" value="1"}
174 {else}
175 {assign var="count" value=`$count+1`}
176 {/if}
177 {/if}
178 {/foreach}
179 </tr>
180 </table>
181 {if $field.html_type eq 'Radio' and $form.formName eq 'Edit' and $field.is_view neq 1 }
182 &nbsp;<span class="crm-clear-link">(<a href="#" title="unselect" onclick="unselectRadio('{$n}', '{$form.formName}'); return false;">{ts}clear{/ts}</a>)</span>
183 {/if}
184 {/strip}
185 </div>
186 <div class="clear"></div>
187 </div>{* end of main edit section div*}
188 {else}
189 <div id="editrow-{$n}" class="crm-section editrow_{$n}-section form-item">
190 <div class="label">
191 {$form.$n.label}
192 </div>
193 <div class="edit-value content">
194 {if $n|substr:0:3 eq 'im-'}
195 {assign var="provider" value=$n|cat:"-provider_id"}
196 {$form.$provider.html}&nbsp;
197 {elseif $n|substr:0:4 eq 'url-'}
198 {assign var="websiteType" value=$n|cat:"-website_type_id"}
199 {$form.$websiteType.html}&nbsp;
200 {/if}
201 {if $n eq 'email_greeting' or $n eq 'postal_greeting' or $n eq 'addressee'}
202 {include file="CRM/Profile/Form/GreetingType.tpl"}
203 {elseif ( $n eq 'group' && $form.group ) || ( $n eq 'tag' && $form.tag )}
204 {include file="CRM/Contact/Form/Edit/TagsAndGroups.tpl" type=$n context="profile"}
205 {elseif ( $form.$n.name eq 'image_URL' )}
206 {$form.$n.html}
207 {if !empty($imageURL)}
208 <div class="crm-section contact_image-section">
209 <div class="content">
210 {include file="CRM/Contact/Page/ContactImage.tpl"}
211 </div>
212 </div>
213 {/if}
214 {elseif $n|substr:0:5 eq 'phone'}
215 {assign var="phone_ext_field" value=$n|replace:'phone':'phone_ext'}
216 {$form.$n.html}
217 {if $form.$phone_ext_field.html}
218 &nbsp;{$form.$phone_ext_field.html}
219 {/if}
220 {else}
221 {if ( $field.data_type eq 'Date' or
222 ( ( ( $n eq 'birth_date' ) or ( $n eq 'deceased_date' ) or ( $n eq 'activity_date_time' ) ) ) ) and $field.is_view neq 1 }
223 {include file="CRM/common/jcalendar.tpl" elementName=$n}
224 {else}
225 {$form.$n.html}
226 {/if}
227 {if (($n eq 'gender') or ($field.html_type eq 'Radio' and $form.formName eq 'Edit' and $field.is_required neq 1)) and
228 ($field.is_view neq 1)}
229 &nbsp;<span class="crm-clear-link">(<a href="#" title="unselect" onclick="unselectRadio('{$n}', '{$form.formName}'); return false;">{ts}clear{/ts}</a>)</span>
230 {elseif $field.html_type eq 'Autocomplete-Select'}
231 {if $field.data_type eq 'ContactReference'}
232 {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n}
233 {else}
234 {include file="CRM/Custom/Form/AutoComplete.tpl" element_name = $n}
235 {/if}
236 {/if}
237 {/if}
238 </div>
239 <div class="clear"></div>
240 </div>
241
242 {if $form.$n.type eq 'file'}
243 <div class="crm-section file_displayURL-section file_displayURL{$n}-section"><div class="content">{$customFiles.$n.displayURL}</div></div>
244 <div class="crm-section file_deleteURL-section file_deleteURL{$n}-section"><div class="content">{$customFiles.$n.deleteURL}</div></div>
245 {/if}
246 {/if}
247
248 {* Show explanatory text for field if not in 'view' mode *}
249 {if $field.help_post && $action neq 4 && $form.$n.html}
250 <div class="crm-section helprow-{$n}-section" id="helprow-{$n}">
251 <div class="content description">{$field.help_post}</div>
252 </div>
253 {/if}
254 {/if}{* end of main if field name if *}
255 {/foreach}
256 </div><!-- end form-layout-compressed for last profile --> {* closing main form layout div when all the fields are built*}
257
258
259 {if $isCaptcha && ( $mode eq 8 || $mode eq 4 || $mode eq 1 ) }
260 {include file='CRM/common/ReCAPTCHA.tpl'}
261 <script type="text/javascript">cj('.recaptcha_label').attr('width', '140px');</script>
262 {/if}
263
264 {if $field.groupHelpPost}
265 <div class="messages help">{$field.groupHelpPost}</div>
266 {/if}
267
268 {if $mode neq 8 && $mode neq 4}
269 </fieldset>
270 </div>
271 {/if}
272
273 {if ($action eq 1 and $mode eq 4 ) or ($action eq 2) or ($action eq 8192)}
274 {if $action eq 2 and $multiRecordFieldListing}
152ff8b9 275 {include file="CRM/Profile/Page/MultipleRecordFieldsListing.tpl" showListing=true}
6a488035
TO
276 {assign var=floatStyle value='float:right'}
277 {/if}
278 <div class="crm-submit-buttons" style='{$floatStyle}'>
279 {include file="CRM/common/formButtons.tpl"}{if $isDuplicate}<span class="crm-button">{$form._qf_Edit_upload_duplicate.html}</span>{/if}
280 </div>
281 {/if}
282 {if $help_post && $action neq 4}<br /><div class="messages help">{$help_post}</div>{/if}
283 {/strip}
284
285</div> {* end crm-container div *}
286
287<script type="text/javascript">
288 {if $drupalCms}
289 {literal}
290 if ( document.getElementsByName("cms_create_account")[0].checked ) {
291 cj('#details').show();
292 }
293 else {
294 cj('#details').hide();
295 }
296 {/literal}
297 {/if}
298</script>
299{/if} {* fields array is not empty *}
300{if $multiRecordFieldListing and empty($fields)}
301 {include file="CRM/Profile/Page/MultipleRecordFieldsListing.tpl" showListing=true}
302{/if}
303{if $drupalCms}
304{include file="CRM/common/showHideByFieldValue.tpl"
305trigger_field_id ="create_account"
306trigger_value =""
307target_element_id ="details"
308target_element_type ="block"
309field_type ="radio"
310invert = 0
311}
312{elseif $statusMessage}
313<div class="messages status no-popup">
314 <div class="icon inform-icon"></div>
315 {$statusMessage}
316</div>
317{/if}
318{/if} {*end of if for $deleteRecord*}
319{literal}
320<script type="text/javascript">
321
322cj(document).ready(function(){
323 cj('#selector tr:even').addClass('odd-row ');
324 cj('#selector tr:odd ').addClass('even-row');
325});
326{/literal}
327{if $context eq 'dialog'}
328{literal}
329 var options = {
330 beforeSubmit: showRequest
331 };
332
333 // bind form using 'ajaxForm'
334 cj('#Edit').ajaxForm( options );
335
336 // FIXME - this is improper use of jquery.form
337 // Do not use this code as an example
338 function showRequest(formData, jqForm, options) {
339 // formData is an array; here we use $.param to convert it to a string to display it
340 // but the form plugin does this for you automatically when it submits the data
341 var queryString = cj.param(formData);
342 queryString = queryString + '&snippet=5&gid=' + {/literal}"{$profileID}"{literal};
343 var postUrl = {/literal}"{crmURL p='civicrm/profile/create' h=0 }"{literal};
344 var blockNo = {/literal}{$blockNo}{literal};
345 var prefix = {/literal}"{$prefix}"{literal};
346 var response = cj.ajax({
347 type: "POST",
348 url: postUrl,
349 async: false, // FIXME
350 data: queryString,
351 dataType: "json",
352 success: function( response ) {
353 if ( response.newContactSuccess ) {
354 cj('#' + prefix + 'contact_' + blockNo ).val( response.sortName ).focus( );
355 if ( typeof(allowMultiClient) != "undefined" ) {
356 if ( allowMultiClient ) {
357 cj('#' + prefix + 'contact_' + blockNo).tokenInput("add", {id: response.contactID, name: response.sortName });
358 }
359 }
360 cj('input[name="' + prefix + 'contact_select_id[' + blockNo +']"]').val( response.contactID );
abc8b55b 361 CRM.alert(response.displayName + {/literal}'{ts escape="js"} has been created.{/ts}', '{ts escape="js"}Contact Saved{/ts}'{literal}, 'success');
6a488035
TO
362 cj('#contact-dialog-' + prefix + blockNo ).dialog('close');
363 }
364 }
365 }).responseText;
366
367 cj('#contact-dialog-' + prefix + blockNo).html( response );
368
369 // FIXME - we have used jquery.form very incorrectly
370 // and are now preventing it from doing what it's supposed to do
371 return false;
372 }
373
374{/literal}
375{/if}
376{literal}
377</script>
378{/literal}
379
46312a4d
TO
380{/crmRegion}
381</div> {* end crm-profile-NAME *}