1(function (D, $, drupalSettings, once) { 2 D.behaviors.webform_civicrm_contact = { 3 attach: function (context) { 4 $(once('webform_civicrm_contact', '[data-civicrm-contact]', context)).each(function (i, el) { 5 var field = $(el); 6 var toHide = []; 7 if (field.data('hide-fields')) { 8 toHide = field.data('hide-fields').split(', '); 9 } 10 var autocompleteUrl = D.url('webform-civicrm/js/' + field.data('form-id') + '/' + field.data('civicrm-field-key')); 11 var isSelect = field.data('is-select'); 12 if (!isSelect) { 13 var tokenValues = field.data('is-contactid') ? false : { 14 hintText: field.data('search-prompt'), 15 noResultsText: field.data('none-prompt'), 16 resultsFormatter: formatChoices, 17 searchingText: "Searching...", 18 enableHTML: true 19 }; 20 } 21 else { 22 var tokenValues = false; 23 } 24 25 wfCivi.existingInit( 26 field, 27 field.data('civicrm-contact'), 28 field.data('form-id'), 29 autocompleteUrl, 30 toHide, 31 tokenValues 32 ); 33 34 field.change(function () { 35 wfCivi.existingSelect( 36 field.data('civicrm-contact'), 37 field.data('form-id'), 38 autocompleteUrl, 39 toHide, 40 field.data('hide-method'), 41 field.data('no-hide-blank'), 42 $(this).val(), 43 true, 44 field.data('form-defaults'), 45 ); 46 }); 47 48 //In case of error, highlight the token-input field. 49 if (field.hasClass('error')) { 50 field.parent('div.form-item').addClass('has-error'); 51 } 52 }); 53 54 /** 55 * Format the choices in the "Existing Contact widget", with a special format for the "No Results" item. 56 */ 57 function formatChoices(item){ 58 var string = item[this.propertyToSearch]; 59 if (string == this.noResultsText) { 60 return "<li><em><i>" + string + "</i></em></li>"; 61 } 62 return "<li>" + string + "</li>"; 63 } 64 65 /** 66 * TODO: Remove this function and use states api instead once 67 * https://www.drupal.org/project/drupal/issues/1149078 is fixed in core webform module. 68 */ 69 function changeDefault() { 70 var val = $(this).val().replace(/_/g, '-'); 71 72 $('[data-drupal-selector=edit-contact-defaults] > div > .form-item', context).not('[class$=properties-default], [class*=properties-allow-url-autofill]').each(function() { 73 if (val.length && $(this).is('[class*=form-item-properties-default-'+val+']')) { 74 $(this).removeAttr('style'); 75 } 76 else { 77 $(this).css('display', 'none'); 78 $(':checkbox', this).prop('disabled', true); 79 } 80 }); 81 if (val === 'auto' || val === 'relationship') { 82 $('.form-item-properties-randomize, .form-item-properties-dupes-allowed') 83 .removeAttr('style') 84 .find(':checkbox') 85 .removeAttr('disabled'); 86 } 87 $('[data-drupal-selector=edit-properties-default-relationship-to]', context).each(changeDefaultRelationTo); 88 } 89 90 function changeDefaultRelationTo() { 91 var c = $(this).val(), 92 types = $('[data-drupal-selector=edit-properties-default-relationship]').data('reltypes')[c], 93 placeholder = types.length ? false : '- ' + Drupal.ts('No relationship types available for these contact types') + ' -'; 94 95 CRM.utils.setOptions('[data-drupal-selector=edit-properties-default-relationship]', types, placeholder); 96 // Provide default to circumvent "required" validation error 97 if ($('[data-drupal-selector=edit-properties-default]').val() !== 'relationship' && !types.length && types[0].key === '') { 98 CRM.utils.setOptions('[data-drupal-selector=edit-properties-default-relationship]', {key: '-', value: '-'}); 99 $('[data-drupal-selector=edit-properties-default-relationship]').val('-'); 100 } 101 } 102 103 function changeFiltersRelationTo() { 104 var c = $(this).val(), 105 types = $('[data-drupal-selector=edit-properties-filter-relationship-types]').data('reltypes')[c]; 106 $('.form-item-properties-filter-relationship-types', context).toggle(!!c); 107 if (c) { 108 CRM.utils.setOptions('[data-drupal-selector=edit-properties-filter-relationship-types]', types); 109 } 110 } 111 112 $('[data-drupal-selector=edit-properties-default]', context).change(changeDefault).each(changeDefault); 113 $('[data-drupal-selector=edit-properties-default-relationship-to]', context).change(changeDefaultRelationTo); 114 $('[data-drupal-selector=edit-properties-filter-relationship-contact]', context).change(changeFiltersRelationTo).each(changeFiltersRelationTo); 115 $('[data-drupal-selector=edit-properties-widget]', context).change(function() { 116 if ($(this).val() == 'hidden') { 117 $('.form-item-properties-search-prompt', context).css('display', 'none'); 118 $('.form-item-properties-show-hidden-contact', context).removeAttr('style'); 119 } 120 else { 121 $('.form-item-properties-search-prompt', context).removeAttr('style'); 122 $('.form-item-properties-show-hidden-contact', context).css('display', 'none'); 123 } 124 }).change(); 125 126 } 127 } 128})(Drupal, jQuery, drupalSettings, once)
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.