| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.7 | |
| 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 | <div class="crm-block crm-form-block crm-uf-field-form-block"> |
| 27 | {if $action eq 8} |
| 28 | <div class="messages status no-popup"> |
| 29 | <div class="icon inform-icon"></div> |
| 30 | {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} |
| 31 | </div> |
| 32 | {else} |
| 33 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div> |
| 34 | <table class="form-layout-compressed"> |
| 35 | <tr class="crm-uf-field-form-block-field_name"> |
| 36 | <td class="label">{$form.field_name.label} {help id='field_name_0'}</td> |
| 37 | <td>{$form.field_name.html}<br /> |
| 38 | <span class="description"> {ts}Select the type of CiviCRM record and the field you want to include in this Profile.{/ts}</span></td> |
| 39 | </tr> |
| 40 | <tr class="crm-uf-field-form-block-label"> |
| 41 | <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> |
| 42 | <td>{$form.label.html}</td> |
| 43 | </tr> |
| 44 | <tr class="crm-uf-field-form-block-is_multi"> |
| 45 | <td class="label">{$form.is_multi_summary.label}{help id='is_multi_summary'}</td> |
| 46 | <td>{$form.is_multi_summary.html}<br /> |
| 47 | </tr> |
| 48 | <tr class="crm-uf-field-form-block-is_required"> |
| 49 | <td class="label">{$form.is_required.label} {help id='is_required'}</td> |
| 50 | <td>{$form.is_required.html}</td> |
| 51 | </tr> |
| 52 | <tr class="crm-uf-field-form-block-is_view"> |
| 53 | <td class="label">{$form.is_view.label} {help id='is_view'}</td> |
| 54 | <td>{$form.is_view.html}</td> |
| 55 | </tr> |
| 56 | <tr id="profile_visibility" class="crm-uf-field-form-block-visibility"> |
| 57 | <td class="label">{$form.visibility.label} {help id='visibility'}</td> |
| 58 | <td>{$form.visibility.html}</td> |
| 59 | </tr> |
| 60 | <tr class="crm-uf-field-form-block-is_searchable"> |
| 61 | <td class="label"><div id="is_search_label">{$form.is_searchable.label} {help id='is_searchable'}</div></td> |
| 62 | <td><div id="is_search_html">{$form.is_searchable.html}</td> |
| 63 | </tr> |
| 64 | <tr class="crm-uf-field-form-block-in_selector"> |
| 65 | <td class="label"><div id="in_selector_label">{$form.in_selector.label}{help id='in_selector'}</div></td> |
| 66 | <td><div id="in_selector_html">{$form.in_selector.html}</div></td> |
| 67 | </tr> |
| 68 | <tr class="crm-uf-field-form-block-help_pre"> |
| 69 | <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> |
| 70 | <td>{$form.help_pre.html}</td> |
| 71 | </tr> |
| 72 | <tr class="crm-uf-field-form-block-help_post"> |
| 73 | <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> |
| 74 | <td>{$form.help_post.html}</td> |
| 75 | </tr> |
| 76 | <tr class="crm-uf-field-form-block-weight"> |
| 77 | <td class="label">{$form.weight.label} {help id='weight'}</td> |
| 78 | <td> {$form.weight.html}</td> |
| 79 | </tr> |
| 80 | <tr class="crm-uf-field-form-block-is_active"> |
| 81 | <td class="label">{$form.is_active.label} {help id='is_active'}</td> |
| 82 | <td>{$form.is_active.html}</td> |
| 83 | </tr> |
| 84 | </table> |
| 85 | {/if} |
| 86 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div> |
| 87 | </div> |
| 88 | |
| 89 | {$initHideBoxes} |
| 90 | |
| 91 | {literal} |
| 92 | <script type="text/javascript"> |
| 93 | |
| 94 | CRM.$(function($) { |
| 95 | var otherModule = {/literal}{$otherModules|@json_encode}{literal}; |
| 96 | if ( $.inArray( "Profile", otherModule ) > -1 && $.inArray( "Search Profile", otherModule ) == -1 ){ |
| 97 | $('#profile_visibility').show(); |
| 98 | } |
| 99 | else if( $.inArray( "Search Profile", otherModule ) > -1 ){ |
| 100 | $('#profile_visibility').show(); |
| 101 | $("#in_selector").prop('checked',true); |
| 102 | } |
| 103 | else if( $.inArray( "Profile", otherModule ) == -1 && $.inArray( "Search Profile", otherModule ) == -1 ){ |
| 104 | $('#profile_visibility').hide(); |
| 105 | } |
| 106 | $('[id^=field_name]').change(function() { |
| 107 | showLabel(); |
| 108 | mixProfile(); |
| 109 | }); |
| 110 | }); |
| 111 | |
| 112 | var preHelpLabel = ""; |
| 113 | function showLabel( ) { |
| 114 | if (preHelpLabel) { |
| 115 | cj(".crm-uf-field-form-block-help_pre .label").html(preHelpLabel); |
| 116 | } |
| 117 | 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"); |
| 118 | |
| 119 | $elements.show(); |
| 120 | |
| 121 | if (cj('[name="field_name[0]"]').val() == "Formatting") { |
| 122 | if (!preHelpLabel) { |
| 123 | preHelpLabel = cj(".crm-uf-field-form-block-help_post .label").html(); |
| 124 | } |
| 125 | cj(".crm-uf-field-form-block-help_pre .label").html('<label for="help_pre">HTML Code</label>'); |
| 126 | $elements.hide(); |
| 127 | } |
| 128 | |
| 129 | // Set the Field Label |
| 130 | var labelValue = ''; |
| 131 | if (cj('[name="field_name[0]"]').val()) { |
| 132 | var fieldId = cj('[name="field_name[1]"]').val(); |
| 133 | if (fieldId) { |
| 134 | labelValue = cj('[name="field_name[1]"] :selected').text().split(' :: ', 2)[0]; |
| 135 | if (cj('[name="field_name[3]"]').val()) { |
| 136 | labelValue += '-' + cj('[name="field_name[3]"] :selected').text(); |
| 137 | } |
| 138 | if (cj('[name="field_name[2]"]').val()) { |
| 139 | labelValue += ' (' + cj('[name="field_name[2]"] :selected').text() + ')'; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | cj('#label').val(labelValue); |
| 145 | |
| 146 | /* Code to hide searchable attribute for no searchable fields */ |
| 147 | if (document.getElementsByName("field_name[1]")[0].selectedIndex == -1) { |
| 148 | return; |
| 149 | } |
| 150 | var field2 = document.getElementsByName("field_name[1]")[0][document.getElementsByName("field_name[1]")[0].selectedIndex].text; |
| 151 | {/literal} |
| 152 | {foreach from=$noSearchable key=dnc item=val} |
| 153 | {literal} |
| 154 | if (field2 == "{/literal}{$val}{literal}") { |
| 155 | cj('#is_search_label, #is_search_html').hide(); |
| 156 | } |
| 157 | {/literal} |
| 158 | {/foreach} |
| 159 | {literal} |
| 160 | |
| 161 | // Code to set Profile Field help, from custom data field help |
| 162 | if (fieldId.substring(0, 7) == 'custom_') { |
| 163 | fieldId = fieldId.substring( fieldId.length, 7); |
| 164 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/custom' h=0 }"{literal}; |
| 165 | cj.post( dataUrl, { id: fieldId }, function(data) { |
| 166 | cj('#help_post').val(data.help_post); |
| 167 | cj('#help_pre').val(data.help_pre); |
| 168 | }, 'json'); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | {/literal}{if $action neq 8}{literal} |
| 173 | showHideSeletorSearch(); |
| 174 | |
| 175 | function showHideSeletorSearch() { |
| 176 | var is_search = cj('#is_search_label, #is_search_html'); |
| 177 | var in_selector = cj('#in_selector_label, #in_selector_html'); |
| 178 | if (cj("#visibility").val() == "User and User Admin Only") { |
| 179 | is_search.hide(); |
| 180 | in_selector.hide(); |
| 181 | cj("#is_searchable").prop('checked',false); |
| 182 | } |
| 183 | else { |
| 184 | if (!cj("#is_view").prop('checked')) { |
| 185 | is_search.show(); |
| 186 | } |
| 187 | var fldName = cj("#field_name_1").val(); |
| 188 | if (fldName == 'group' || fldName == 'tag') { |
| 189 | in_selector.hide(); |
| 190 | } |
| 191 | else { |
| 192 | in_selector.show(); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | cj("#field_name_1").bind( 'change blur', function( ) { |
| 198 | showHideSeletorSearch( ); |
| 199 | }); |
| 200 | |
| 201 | CRM.$(function($) { |
| 202 | cj("#field_name_1").addClass( 'huge' ); |
| 203 | viewOnlyShowHide( ); |
| 204 | cj("#is_view").click( function(){ |
| 205 | viewOnlyShowHide(); |
| 206 | }); |
| 207 | }); |
| 208 | {/literal}{/if}{literal} |
| 209 | |
| 210 | cj("#field_name_1").change( |
| 211 | function() { |
| 212 | multiSummaryToggle(cj(this).val()); |
| 213 | }); |
| 214 | |
| 215 | CRM.$(function($) { |
| 216 | var fieldId = cj("#field_name_1").val(); |
| 217 | multiSummaryToggle(fieldId); |
| 218 | }); |
| 219 | |
| 220 | function multiSummaryToggle(customId) { |
| 221 | if (customId && customId.match(/custom_[\d]/)) { |
| 222 | |
| 223 | var dataUrl = "{/literal}{crmURL p='civicrm/ajax/rest' q='className=CRM_UF_Page_AJAX&fnName=checkIsMultiRecord&json=1' h=0 }"{literal}; |
| 224 | dataUrl = dataUrl + '&customId=' + customId; |
| 225 | cj.ajax({ url: dataUrl, |
| 226 | async: false, |
| 227 | global: false, |
| 228 | dataType : 'json', |
| 229 | success : function(response) { |
| 230 | if (response.is_multi != 0 ) { |
| 231 | cj('.crm-uf-field-form-block-is_multi').show(); |
| 232 | } |
| 233 | else { |
| 234 | if (cj('#is_multi_summary').is(':checked')) { |
| 235 | cj('#is_multi_summary').prop('checked', false); |
| 236 | } |
| 237 | cj('.crm-uf-field-form-block-is_multi').hide(); |
| 238 | } |
| 239 | } |
| 240 | }); |
| 241 | } |
| 242 | else { |
| 243 | if (cj('#is_multi_summary').is(':checked')) { |
| 244 | cj('#is_multi_summary').prop('checked', false); |
| 245 | } |
| 246 | cj('.crm-uf-field-form-block-is_multi').hide(); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | function viewOnlyShowHide() { |
| 251 | var is_search = cj('#is_search_label, #is_search_html'); |
| 252 | if (cj("#is_view").prop('checked')) { |
| 253 | is_search.hide(); |
| 254 | cj("#is_searchable").prop('checked', false); |
| 255 | } |
| 256 | else if (cj("#visibility").val() != "User and User Admin Only") { |
| 257 | is_search.show(); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | //CRM-4363 |
| 262 | function mixProfile( ) { |
| 263 | var allMixTypes = ["Participant", "Membership", "Contribution"]; |
| 264 | var type = document.forms.Field['field_name[0]'].value; |
| 265 | var alreadyMixProfile = {/literal}{if $alreadyMixProfile}true{else}false{/if}{literal}; |
| 266 | if (allMixTypes.indexOf( type ) != -1 || alreadyMixProfile) { |
| 267 | if (document.getElementById("is_searchable").checked) { |
| 268 | document.getElementById("is_searchable").checked = false; |
| 269 | if ( alreadyMixProfile ) { |
| 270 | 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}; |
| 271 | } |
| 272 | else { |
| 273 | var message = type + {/literal}'{ts escape="js"} fields can not be marked as Searchable in a profile.{/ts}'{literal}; |
| 274 | } |
| 275 | cj().crmError(message, {/literal}'{ts escape="js"}Error{/ts}'{literal}); |
| 276 | } |
| 277 | if ( document.getElementById("in_selector").checked ) { |
| 278 | document.getElementById("in_selector").checked = false; |
| 279 | if ( alreadyMixProfile ) { |
| 280 | 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}; |
| 281 | } |
| 282 | else { |
| 283 | var message = type + {/literal}'{ts escape="js"} can not be used as a Result Column for profile searches.{/ts}'{literal}; |
| 284 | } |
| 285 | cj().crmError(message, {/literal}'{ts escape="js"}Error{/ts}'{literal}); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | function verify( ) { |
| 291 | var allMixTypes = ["Participant", "Membership", "Contribution"]; |
| 292 | var type = document.forms.Field['field_name[0]'].value; |
| 293 | if ( allMixTypes.indexOf( type ) != -1 ) { |
| 294 | 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}' |
| 295 | + 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}; |
| 296 | var ok = confirm( message ); |
| 297 | if ( !ok ) { |
| 298 | return false; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | </script> |
| 304 | {/literal} |