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