From: Coleman Watts Date: Fri, 31 Jan 2014 03:31:30 +0000 (-0800) Subject: CRM-13966 - Convert adv search crmasmselect to select2 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=02ddf03912f770586aa38b51532652c6f82a08bb;p=civicrm-core.git CRM-13966 - Convert adv search crmasmselect to select2 --- diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 75ba22c180..0550a372ab 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -493,8 +493,8 @@ class CRM_Activity_BAO_Query { $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); if ($surveys) $form->add('select', 'activity_survey_id', ts('Survey / Petition'), - array( - '' => ts('- none -')) + $surveys, FALSE + array('' => ts('- none -')) + $surveys, FALSE, + array('class' => 'crm-select2') ); $extends = array('Activity'); @@ -521,7 +521,9 @@ class CRM_Activity_BAO_Query { $buildEngagementLevel = TRUE; $form->add('select', 'activity_engagement_level', ts('Engagement Index'), - array('' => ts('- any -')) + CRM_Campaign_PseudoConstant::engagementLevel() + array('' => ts('- any -')) + CRM_Campaign_PseudoConstant::engagementLevel(), + FALSE, + array('class' => 'crm-select2') ); // Add survey result field. @@ -545,7 +547,7 @@ class CRM_Activity_BAO_Query { asort($resultOptions); $form->add('select', 'activity_result', ts("Survey Result"), $resultOptions, FALSE, - array('id' => 'activity_result', 'multiple' => 'multiple', 'title' => ts('- select -')) + array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2') ); } } diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 06433f915d..e485e728f6 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -39,12 +39,11 @@ class CRM_Contact_Form_Search_Criteria { if ($form->_searchOptions['contactType']) { // add checkboxes for contact type - $contact_type = array(); $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); if ($contactTypes) { $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, - array('id' => 'contact_type', 'multiple' => 'multiple', 'title' => ts('- select -')) + array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;') ); } } @@ -56,11 +55,11 @@ class CRM_Contact_Form_Search_Criteria { $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '  ', TRUE); $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, - array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')) + array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2') ); $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type'); $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, - array('id' => 'group_type', 'multiple' => 'multiple', 'title' => ts('- select -')) + array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2') ); $form->add('hidden','group_search_selected','group'); } @@ -72,7 +71,7 @@ class CRM_Contact_Form_Search_Criteria { if ($contactTags) { $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, - array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -')) + array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;') ); } @@ -223,7 +222,7 @@ class CRM_Contact_Form_Search_Criteria { array( 'id' => 'privacy_options', 'multiple' => 'multiple', - 'title' => ts('- select -'), + 'class' => 'crm-select2', ) ); @@ -255,7 +254,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')); + $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- any -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'), FALSE, array('class' => 'crm-select2')); // Phone search $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); @@ -328,13 +327,13 @@ class CRM_Contact_Form_Search_Criteria { } else { //if not setdefault any country - $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); + $selectElements = CRM_Core_PseudoConstant::$select(); } - $element = $form->addElement('select', $name, $title, $selectElements); + $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2')); } elseif ($select == 'country') { $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); - $element = $form->addElement('select', $name, $title, $selectElements); + $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2')); } elseif ($select == 'county') { if ( array_key_exists('state_province', $formValues) && !CRM_Utils_System::isNull($formValues['state_province'])) { @@ -343,11 +342,11 @@ class CRM_Contact_Form_Search_Criteria { else { $selectElements = array('' => ts('- any -')); } - $element = $form->addElement('select', $name, $title, $selectElements); + $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2')); } else { $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); - $element = $form->addElement('select', $name, $title, $selectElements); + $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2')); } if ($multiSelect) { $element->setMultiple(TRUE); @@ -377,7 +376,7 @@ class CRM_Contact_Form_Search_Criteria { $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric'); $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion(); - $form->addElement('select', 'world_region', ts('World Region'), $worldRegions); + $form->add('select', 'world_region', ts('World Region'), $worldRegions, FALSE, array('class' => 'crm-select2')); // checkboxes for location type $location_type = array(); @@ -431,7 +430,7 @@ class CRM_Contact_Form_Search_Criteria { $allRelationshipType = array(); $allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); - $form->addElement('select', 'relation_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $allRelationshipType); + $form->add('select', 'relation_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $allRelationshipType, FALSE, array('class' => 'crm-select2')); $form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); // relation status $relStatusOption = array(ts('Active '), ts('Inactive '), ts('All')); @@ -445,7 +444,7 @@ class CRM_Contact_Form_Search_Criteria { //add the target group if ($form->_group) { $form->add('select', 'relation_target_group', ts('Target Contact(s) in Group'), $form->_group, FALSE, - array('id' => 'relation_target_group', 'multiple' => 'multiple', 'title' => ts('- select -')) + array('id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2') ); } CRM_Core_Form_Date::buildDateRange($form, 'relation_start_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); diff --git a/css/civicrm.css b/css/civicrm.css index 351b5aa6cf..47b8bb0010 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -2811,7 +2811,7 @@ div.grippie { #civicrm-menu .ui-autocomplete-input, .crm-container .ui-autocomplete-input, .crm-container .ac_input { - background: white url("../i/magnify.gif") no-repeat scroll right center; + background: url("../packages/jquery/plugins/select2/select2.png") no-repeat scroll right -23px; padding-right: 16px; /* so that text doesn't flow on top of icon */ } diff --git a/i/magnify.gif b/i/magnify.gif deleted file mode 100644 index d0ea522bd8..0000000000 Binary files a/i/magnify.gif and /dev/null differ diff --git a/js/Common.js b/js/Common.js index c36dc94220..d6111c79d1 100644 --- a/js/Common.js +++ b/js/Common.js @@ -253,6 +253,8 @@ CRM.validate = CRM.validate || { functions: [] }; +// Set select2 defaults +$.fn.select2.defaults.minimumResultsForSearch = 10; // https://github.com/ivaynberg/select2/pull/2090 $.fn.select2.defaults.width = 'resolve'; diff --git a/templates/CRM/Activity/Form/Search/Common.tpl b/templates/CRM/Activity/Form/Search/Common.tpl index 236d72082c..15d3e60550 100644 --- a/templates/CRM/Activity/Form/Search/Common.tpl +++ b/templates/CRM/Activity/Form/Search/Common.tpl @@ -113,12 +113,6 @@
{$form.activity_result.html} - {include file="CRM/common/Tag.tpl" tagsetType='activity'} diff --git a/templates/CRM/Contact/Form/Search/AdvancedCriteria.tpl b/templates/CRM/Contact/Form/Search/AdvancedCriteria.tpl index 8782a520c8..a989d150f4 100644 --- a/templates/CRM/Contact/Form/Search/AdvancedCriteria.tpl +++ b/templates/CRM/Contact/Form/Search/AdvancedCriteria.tpl @@ -86,23 +86,14 @@ cj(function($) { * Loads snippet based on id of crm-accordion-header */ function loadPanes(id) { - var url = "{/literal}{crmURL p='civicrm/contact/search/advanced' q="snippet=1&qfKey=`$qfKey`&searchPane=" h=0}{literal}" + id; + var url = "{/literal}{crmURL p='civicrm/contact/search/advanced' q="qfKey=`$qfKey`&searchPane=" h=0}{literal}" + id; var header = $('#' + id); var body = $('.crm-accordion-body.' + id); if (header.length > 0 && body.length > 0 && !body.html()) { body.html('
{/literal}{ts escape='js'}Loading{/ts}{literal}...
'); header.append('{/literal}{ts escape='js'}Reset{/ts}  {literal}'); header.addClass('active'); - $.ajax({ - url : url, - success: function(data) { - body.html(data); - }, - error: function() { - CRM.alert({/literal}'{ts escape="js"}Sorry, could not load the requested information from the server.{/ts}', '{ts escape="js"}Network Error{/ts}'{literal}); - $('.crm-close-accordion', header).click(); - } - }); + CRM.loadPage(url, {target: body, block: false}); } } }); diff --git a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl index f4ef9274d5..40b25281a0 100644 --- a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl +++ b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl @@ -60,15 +60,6 @@ {if $form.contact_type}
{$form.contact_type.html} - {literal} - - {/literal} {else}   @@ -77,41 +68,23 @@
{$form.group.html} - {literal} - - {/literal}
{$form.group_type.html} {literal} - {/literal} {else}   @@ -203,10 +167,8 @@ {literal} - {/literal}