Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
1188c7a8 | 3 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 4 | | | |
1188c7a8 TO |
5 | | This work is published under the GNU AGPLv3 license with some | |
6 | | permitted exceptions and without any warranty. For full license | | |
7 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 TO |
8 | +--------------------------------------------------------------------+ |
9 | *} | |
6a488035 TO |
10 | <div class="crm-block crm-form-block crm-uf-field-form-block"> |
11 | {if $action eq 8} | |
12 | <div class="messages status no-popup"> | |
13 | <div class="icon inform-icon"></div> | |
14 | {ts}WARNING: Deleting this profile field will remove it from Profile forms and listings. If this field is used in any 'stand-alone' Profile forms, you will need to update those forms to remove this field.{/ts} {ts}Do you want to continue?{/ts} | |
15 | </div> | |
16 | {else} | |
17 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div> | |
18 | <table class="form-layout-compressed"> | |
19 | <tr class="crm-uf-field-form-block-field_name"> | |
b29a9e66 | 20 | <td class="label">{$form.field_name.label} {help id='field_name_0'}</td> |
6a488035 TO |
21 | <td>{$form.field_name.html}<br /> |
22 | <span class="description"> {ts}Select the type of CiviCRM record and the field you want to include in this Profile.{/ts}</span></td> | |
23 | </tr> | |
24 | <tr class="crm-uf-field-form-block-label"> | |
25 | <td class="label">{$form.label.label} {help id='label'}{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_uf_field' field='label' id=$fieldId}{/if}</td> | |
26 | <td>{$form.label.html}</td> | |
27 | </tr> | |
28 | <tr class="crm-uf-field-form-block-is_multi"> | |
29 | <td class="label">{$form.is_multi_summary.label}{help id='is_multi_summary'}</td> | |
30 | <td>{$form.is_multi_summary.html}<br /> | |
31 | </tr> | |
32 | <tr class="crm-uf-field-form-block-is_required"> | |
33 | <td class="label">{$form.is_required.label} {help id='is_required'}</td> | |
34 | <td>{$form.is_required.html}</td> | |
35 | </tr> | |
36 | <tr class="crm-uf-field-form-block-is_view"> | |
37 | <td class="label">{$form.is_view.label} {help id='is_view'}</td> | |
38 | <td>{$form.is_view.html}</td> | |
39 | </tr> | |
40 | <tr id="profile_visibility" class="crm-uf-field-form-block-visibility"> | |
41 | <td class="label">{$form.visibility.label} {help id='visibility'}</td> | |
42 | <td>{$form.visibility.html}</td> | |
43 | </tr> | |
44 | <tr class="crm-uf-field-form-block-is_searchable"> | |
45 | <td class="label"><div id="is_search_label">{$form.is_searchable.label} {help id='is_searchable'}</div></td> | |
46 | <td><div id="is_search_html">{$form.is_searchable.html}</td> | |
47 | </tr> | |
48 | <tr class="crm-uf-field-form-block-in_selector"> | |
49 | <td class="label"><div id="in_selector_label">{$form.in_selector.label}{help id='in_selector'}</div></td> | |
50 | <td><div id="in_selector_html">{$form.in_selector.html}</div></td> | |
51 | </tr> | |
52 | <tr class="crm-uf-field-form-block-help_pre"> | |
53 | <td class="label">{$form.help_pre.label}{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_uf_field' field='help_pre' id=$fieldId}{/if} {help id='help'}</td> | |
54 | <td>{$form.help_pre.html}</td> | |
55 | </tr> | |
56 | <tr class="crm-uf-field-form-block-help_post"> | |
57 | <td class="label">{$form.help_post.label}{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_uf_field' field='help_post' id=$fieldId}{/if} {help id='help'}</td> | |
58 | <td>{$form.help_post.html}</td> | |
59 | </tr> | |
60 | <tr class="crm-uf-field-form-block-weight"> | |
61 | <td class="label">{$form.weight.label} {help id='weight'}</td> | |
62 | <td> {$form.weight.html}</td> | |
63 | </tr> | |
64 | <tr class="crm-uf-field-form-block-is_active"> | |
65 | <td class="label">{$form.is_active.label} {help id='is_active'}</td> | |
66 | <td>{$form.is_active.html}</td> | |
67 | </tr> | |
68 | </table> | |
69 | {/if} | |
70 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div> | |
71 | </div> | |
72 | ||
73 | {$initHideBoxes} | |
74 | ||
75 | {literal} | |
76 | <script type="text/javascript"> | |
6a488035 | 77 | |
3cc60a06 | 78 | CRM.$(function($) { |
ae8f569f | 79 | var otherModule = {/literal}{$otherModules|@json_encode}{literal}; |
6a488035 TO |
80 | if ( $.inArray( "Profile", otherModule ) > -1 && $.inArray( "Search Profile", otherModule ) == -1 ){ |
81 | $('#profile_visibility').show(); | |
82 | } | |
83 | else if( $.inArray( "Search Profile", otherModule ) > -1 ){ | |
84 | $('#profile_visibility').show(); | |
8539f25d | 85 | $("#in_selector").prop('checked',true); |
6a488035 TO |
86 | } |
87 | else if( $.inArray( "Profile", otherModule ) == -1 && $.inArray( "Search Profile", otherModule ) == -1 ){ | |
88 | $('#profile_visibility').hide(); | |
89 | } | |
90 | $('[id^=field_name]').change(function() { | |
91 | showLabel(); | |
92 | mixProfile(); | |
93 | }); | |
94 | }); | |
95 | ||
96 | var preHelpLabel = ""; | |
97 | function showLabel( ) { | |
98 | if (preHelpLabel) { | |
99 | cj(".crm-uf-field-form-block-help_pre .label").html(preHelpLabel); | |
100 | } | |
101 | var $elements = cj(".crm-uf-field-form-block-is_view, .crm-uf-field-form-block-is_required, .crm-uf-field-form-block-visibility, .crm-uf-field-form-block-is_searchable, .crm-uf-field-form-block-in_selector, .crm-uf-field-form-block-help_post"); | |
102 | ||
103 | $elements.show(); | |
104 | ||
105 | if (cj('[name="field_name[0]"]').val() == "Formatting") { | |
106 | if (!preHelpLabel) { | |
107 | preHelpLabel = cj(".crm-uf-field-form-block-help_post .label").html(); | |
108 | } | |
109 | cj(".crm-uf-field-form-block-help_pre .label").html('<label for="help_pre">HTML Code</label>'); | |
110 | $elements.hide(); | |
111 | } | |
112 | ||
113 | // Set the Field Label | |
114 | var labelValue = ''; | |
115 | if (cj('[name="field_name[0]"]').val()) { | |
116 | var fieldId = cj('[name="field_name[1]"]').val(); | |
117 | if (fieldId) { | |
118 | labelValue = cj('[name="field_name[1]"] :selected').text().split(' :: ', 2)[0]; | |
119 | if (cj('[name="field_name[3]"]').val()) { | |
120 | labelValue += '-' + cj('[name="field_name[3]"] :selected').text(); | |
121 | } | |
122 | if (cj('[name="field_name[2]"]').val()) { | |
123 | labelValue += ' (' + cj('[name="field_name[2]"] :selected').text() + ')'; | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
128 | cj('#label').val(labelValue); | |
129 | ||
130 | /* Code to hide searchable attribute for no searchable fields */ | |
131 | if (document.getElementsByName("field_name[1]")[0].selectedIndex == -1) { | |
132 | return; | |
133 | } | |
134 | var field2 = document.getElementsByName("field_name[1]")[0][document.getElementsByName("field_name[1]")[0].selectedIndex].text; | |
135 | {/literal} | |
136 | {foreach from=$noSearchable key=dnc item=val} | |
137 | {literal} | |
138 | if (field2 == "{/literal}{$val}{literal}") { | |
139 | cj('#is_search_label, #is_search_html').hide(); | |
140 | } | |
141 | {/literal} | |
142 | {/foreach} | |
143 | {literal} | |
144 | ||
145 | // Code to set Profile Field help, from custom data field help | |
146 | if (fieldId.substring(0, 7) == 'custom_') { | |
147 | fieldId = fieldId.substring( fieldId.length, 7); | |
148 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/custom' h=0 }"{literal}; | |
149 | cj.post( dataUrl, { id: fieldId }, function(data) { | |
150 | cj('#help_post').val(data.help_post); | |
151 | cj('#help_pre').val(data.help_pre); | |
152 | }, 'json'); | |
153 | } | |
154 | } | |
155 | ||
156 | {/literal}{if $action neq 8}{literal} | |
157 | showHideSeletorSearch(); | |
158 | ||
159 | function showHideSeletorSearch() { | |
160 | var is_search = cj('#is_search_label, #is_search_html'); | |
161 | var in_selector = cj('#in_selector_label, #in_selector_html'); | |
162 | if (cj("#visibility").val() == "User and User Admin Only") { | |
163 | is_search.hide(); | |
164 | in_selector.hide(); | |
8539f25d | 165 | cj("#is_searchable").prop('checked',false); |
6a488035 TO |
166 | } |
167 | else { | |
8539f25d | 168 | if (!cj("#is_view").prop('checked')) { |
6a488035 TO |
169 | is_search.show(); |
170 | } | |
171 | var fldName = cj("#field_name_1").val(); | |
172 | if (fldName == 'group' || fldName == 'tag') { | |
173 | in_selector.hide(); | |
174 | } | |
175 | else { | |
176 | in_selector.show(); | |
177 | } | |
178 | } | |
179 | } | |
180 | ||
181 | cj("#field_name_1").bind( 'change blur', function( ) { | |
182 | showHideSeletorSearch( ); | |
183 | }); | |
184 | ||
3cc60a06 | 185 | CRM.$(function($) { |
6a488035 TO |
186 | cj("#field_name_1").addClass( 'huge' ); |
187 | viewOnlyShowHide( ); | |
188 | cj("#is_view").click( function(){ | |
189 | viewOnlyShowHide(); | |
190 | }); | |
191 | }); | |
192 | {/literal}{/if}{literal} | |
193 | ||
194 | cj("#field_name_1").change( | |
195 | function() { | |
196 | multiSummaryToggle(cj(this).val()); | |
197 | }); | |
198 | ||
3cc60a06 | 199 | CRM.$(function($) { |
6a488035 TO |
200 | var fieldId = cj("#field_name_1").val(); |
201 | multiSummaryToggle(fieldId); | |
202 | }); | |
203 | ||
204 | function multiSummaryToggle(customId) { | |
205 | if (customId && customId.match(/custom_[\d]/)) { | |
206 | ||
207 | var dataUrl = "{/literal}{crmURL p='civicrm/ajax/rest' q='className=CRM_UF_Page_AJAX&fnName=checkIsMultiRecord&json=1' h=0 }"{literal}; | |
208 | dataUrl = dataUrl + '&customId=' + customId; | |
209 | cj.ajax({ url: dataUrl, | |
210 | async: false, | |
211 | global: false, | |
212 | dataType : 'json', | |
213 | success : function(response) { | |
214 | if (response.is_multi != 0 ) { | |
215 | cj('.crm-uf-field-form-block-is_multi').show(); | |
216 | } | |
217 | else { | |
218 | if (cj('#is_multi_summary').is(':checked')) { | |
8539f25d | 219 | cj('#is_multi_summary').prop('checked', false); |
6a488035 TO |
220 | } |
221 | cj('.crm-uf-field-form-block-is_multi').hide(); | |
222 | } | |
223 | } | |
224 | }); | |
225 | } | |
226 | else { | |
227 | if (cj('#is_multi_summary').is(':checked')) { | |
8539f25d | 228 | cj('#is_multi_summary').prop('checked', false); |
6a488035 TO |
229 | } |
230 | cj('.crm-uf-field-form-block-is_multi').hide(); | |
231 | } | |
232 | } | |
233 | ||
234 | function viewOnlyShowHide() { | |
235 | var is_search = cj('#is_search_label, #is_search_html'); | |
8539f25d | 236 | if (cj("#is_view").prop('checked')) { |
6a488035 | 237 | is_search.hide(); |
8539f25d | 238 | cj("#is_searchable").prop('checked', false); |
6a488035 TO |
239 | } |
240 | else if (cj("#visibility").val() != "User and User Admin Only") { | |
241 | is_search.show(); | |
242 | } | |
243 | } | |
244 | ||
245 | //CRM-4363 | |
246 | function mixProfile( ) { | |
247 | var allMixTypes = ["Participant", "Membership", "Contribution"]; | |
248 | var type = document.forms.Field['field_name[0]'].value; | |
249 | var alreadyMixProfile = {/literal}{if $alreadyMixProfile}true{else}false{/if}{literal}; | |
250 | if (allMixTypes.indexOf( type ) != -1 || alreadyMixProfile) { | |
251 | if (document.getElementById("is_searchable").checked) { | |
252 | document.getElementById("is_searchable").checked = false; | |
253 | if ( alreadyMixProfile ) { | |
254 | var message = {/literal}'{ts escape="js"}You can not mark fields as Searchable in a profile that contains fields for multiple record types.{/ts}'{literal}; | |
255 | } | |
256 | else { | |
257 | var message = type + {/literal}'{ts escape="js"} fields can not be marked as Searchable in a profile.{/ts}'{literal}; | |
258 | } | |
259 | cj().crmError(message, {/literal}'{ts escape="js"}Error{/ts}'{literal}); | |
260 | } | |
261 | if ( document.getElementById("in_selector").checked ) { | |
262 | document.getElementById("in_selector").checked = false; | |
263 | if ( alreadyMixProfile ) { | |
264 | var message = {/literal}'{ts escape="js"}You can not mark a field as a Result Column in a profile that contains fields from multiple record types.{/ts}'{literal}; | |
265 | } | |
266 | else { | |
267 | var message = type + {/literal}'{ts escape="js"} can not be used as a Result Column for profile searches.{/ts}'{literal}; | |
268 | } | |
269 | cj().crmError(message, {/literal}'{ts escape="js"}Error{/ts}'{literal}); | |
270 | } | |
271 | } | |
272 | } | |
273 | ||
274 | function verify( ) { | |
275 | var allMixTypes = ["Participant", "Membership", "Contribution"]; | |
276 | var type = document.forms.Field['field_name[0]'].value; | |
277 | if ( allMixTypes.indexOf( type ) != -1 ) { | |
278 | var message = {/literal}'{ts escape='js'}Oops. One or more fields in this profile are configured to be Searchable and / or shown in a Results Column, AND you are trying to add a {/ts}' | |
279 | + type + '{ts} field. Profiles with a mixture of field types can not include Searchable or Results Column fields. If you save this field now, the Seachable and Results Column settings will be removed for all fields in this profile. Do you want to continue?{/ts}'{literal}; | |
280 | var ok = confirm( message ); | |
281 | if ( !ok ) { | |
282 | return false; | |
283 | } | |
284 | } | |
285 | } | |
286 | ||
287 | </script> | |
288 | {/literal} |