From c7130c3e5ae8d5ca9c4af11906d27796f33caf02 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 9 Feb 2014 20:07:17 -0800 Subject: [PATCH] CRM-13966 - select2 improvements --- CRM/Contact/Form/Edit/Address.php | 2 +- CRM/Contact/Form/Search/Criteria.php | 6 +++--- CRM/Core/BAO/Address.php | 4 ++++ CRM/Core/Form.php | 6 +++--- api/v3/Address.php | 15 +++++++++++++++ css/civicrm.css | 3 +++ templates/CRM/common/stateCountry.tpl | 7 +++++-- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php index 8c2168c5ec..531afb43a5 100644 --- a/CRM/Contact/Form/Edit/Address.php +++ b/CRM/Contact/Form/Edit/Address.php @@ -172,7 +172,7 @@ class CRM_Contact_Form_Edit_Address { $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($form->getSubmitValue("address[{$blockId}][state_province_id]")); } elseif ($form->getSubmitValue("address[{$blockId}][county_id]")) { - $selectOptions = array('' => ts('- select a state -')) + CRM_Core_PseudoConstant::county(); + $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(); } else { $selectOptions = array('' => ts('- select a state -')); diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index d7a6c833d4..efef6fdb17 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -256,7 +256,7 @@ class CRM_Contact_Form_Search_Criteria { $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method')); //CRM-6138 Preferred Language - $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- any -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'), FALSE, array('class' => 'crm-select2')); + $form->addSelect('preferred_language', array('class' => 'twenty', 'option_url' => NULL)); // Phone search $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); @@ -377,8 +377,8 @@ class CRM_Contact_Form_Search_Criteria { // is there another form rule that does decimals besides money ? ... $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric'); - $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion(); - $form->add('select', 'world_region', ts('World Region'), $worldRegions, FALSE, array('class' => 'crm-select2')); + $worldRegions = array('' => '') + CRM_Core_PseudoConstant::worldRegion(); + $form->addSelect('world_region', array('data-api-entity' => 'address', 'placeholder' => ts('- any -'), 'option_url' => NULL)); // checkboxes for location type $location_type = array(); diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index e7d7abdda9..9f35cd2688 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -1195,6 +1195,10 @@ SELECT is_primary, $params['condition'] = 'state_province_id IN (' . implode(',', (array) $props['state_province_id']) . ')'; } break; + // Not a real field in this entity + case 'world_region': + return CRM_Core_PseudoConstant::worldRegion(); + break; } return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); } diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 67615c35b3..dc2fbd6a8a 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -939,7 +939,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { list(, $id) = explode('_', $name); $label = isset($props['label']) ? $props['label'] : CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'label', $id); $gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'option_group_id', $id); - $props['data-option-group-url'] = 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $gid); + $props['data-option-group-url'] = array_key_exists('option_url', $props) ? $props['option_url'] : 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $gid); } // Core field else { @@ -953,11 +953,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } } $label = isset($props['label']) ? $props['label'] : $fieldSpec['title']; - $props['data-option-group-url'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec); + $props['data-option-group-url'] = array_key_exists('option_url', $props) ? $props['option_url'] : $props['data-option-group-url'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec); } $props['class'] = isset($props['class']) ? $props['class'] . ' ' : ''; $props['class'] .= "crm-select2"; - CRM_Utils_Array::remove($props, 'label'); + CRM_Utils_Array::remove($props, 'label', 'option_url'); return $this->add('select', $name, $label, $options, $required, $props); } diff --git a/api/v3/Address.php b/api/v3/Address.php index 3ac7d56023..bff434e2cc 100644 --- a/api/v3/Address.php +++ b/api/v3/Address.php @@ -100,6 +100,21 @@ function _civicrm_api3_address_create_spec(&$params) { $params['contact_id']['api.required'] = 1; $params['country'] = array('title' => 'Name or 2-letter abbreviation of country. Looked up in civicrm_country table'); $params['street_parsing'] = array('title' => 'optional param to indicate you want the street_address field parsed into individual params'); + $params['world_region'] = array( + 'title' => ts('World Region'), + 'name' => 'world_region', + ); +} +/** + * Adjust Metadata for Get action + * + * @param array $params array or parameters determined by getfields + */ +function _civicrm_api3_address_get_spec(&$params) { + $params['world_region'] = array( + 'title' => ts('World Region'), + 'name' => 'world_region', + ); } /** diff --git a/css/civicrm.css b/css/civicrm.css index 71b9c279b9..85ce033c6d 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -3824,6 +3824,9 @@ div.m ul#civicrm-menu, .crm-container .select2-container .select2-choice abbr { top: 6px; } +.crm-container .select2-container .select2-choice > .select2-chosen { + font-size: 1.1em; +} /* Add search icon to ajax single-selects */ .crm-container .crm-ajax-select .select2-arrow b { background-position: -39px -22px; diff --git a/templates/CRM/common/stateCountry.tpl b/templates/CRM/common/stateCountry.tpl index 7bf621203a..162df6452a 100644 --- a/templates/CRM/common/stateCountry.tpl +++ b/templates/CRM/common/stateCountry.tpl @@ -30,13 +30,16 @@ function chainSelect(e) { var info = $(this).data('chainSelect'); var val = info.target.val(); + var multiple = info.target.attr('multiple'); var placeholder = $(this).val() ? "{/literal}{ts escape='js'}Loading{/ts}{literal}..." : info.placeholder; - info.target.html(''); + !multiple && info.target.html(''); if ($(this).val()) { $.getJSON(info.callback, {_value: $(this).val()}, function(data) { var options = ''; $.each(data, function() { - options += ''; + if (!multiple || this.value) { + options += ''; + } }); info.target.html(options).val(val).trigger('change'); }); -- 2.25.1