Commit 02ddf039 authored by colemanw's avatar colemanw

CRM-13966 - Convert adv search crmasmselect to select2

parent f7b92fcd
......@@ -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')
);
}
}
......
......@@ -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);
......
......@@ -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 */
}
......
......@@ -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';
......
......@@ -113,12 +113,6 @@
<td id="activityResult">
<label>{$form.activity_result.label}</label><br />
{$form.activity_result.html}
<script type="text/javascript">
{literal}
cj("select#activity_result").crmasmSelect({
});
{/literal}
</script>
</td>
<td colspan="2">{include file="CRM/common/Tag.tpl" tagsetType='activity'}</td>
</tr>
......
......@@ -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('<div class="crm-loading-element"><span class="loading-text">{/literal}{ts escape='js'}Loading{/ts}{literal}...</span></div>');
header.append('{/literal}<a href="#" class="crm-close-accordion" title="{ts escape='js'}Remove from search criteria{/ts}"><span>{ts escape='js'}Reset{/ts}</span> &nbsp;<img src="{$config->resourceBase}i/close.png" /></a>{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});
}
}
});
......
......@@ -60,15 +60,6 @@
{if $form.contact_type}
<td><label>{ts}Contact Type(s){/ts}</label><br />
{$form.contact_type.html}
{literal}
<script type="text/javascript">
cj("select#contact_type").crmasmSelect({
respectParents: true
});
</script>
{/literal}
</td>
{else}
<td>&nbsp;</td>
......@@ -77,41 +68,23 @@
<td>
<div id='groupselect'><label>{ts}Group(s){/ts}<span class="crm-clear-link">(<a id='searchbygrouptype'>{ts}search by group type{/ts}</a>)</span></label>
{$form.group.html}
{literal}
<script type="text/javascript">
cj("select#group").crmasmSelect({
respectParents: true
});
</script>
{/literal}
</div>
<div id='grouptypeselect'>
<label>{ts}Group Type(s){/ts}<span class="crm-clear-link"> ( <a id='searchbygroup'>{ts}search by group{/ts}</a>)</span></label>
{$form.group_type.html}
{literal}
<script type="text/javascript">
cj("select#group_type").crmasmSelect({
respectParents: true
});
function showGroupSearch(){
cj(function(){
function showGroupSearch(){
cj('#grouptypeselect').hide();
cj('#groupselect').show();
cj('#group_type').val('') ;
cj('#crmasmList2 li').remove();
cj('#crmasmSelect2').children().removeClass('asmOptionDisabled').prop('disabled', false);
}
function showGroupTypeSearch(){
cj('#group_type').select2('val', '');
}
function showGroupTypeSearch(){
cj('#groupselect').hide();
cj('#grouptypeselect').show();
cj('#group').val('') ;
cj('#crmasmList1 li').remove();
cj('#crmasmSelect1').children().removeClass('asmOptionDisabled').prop('disabled', false);
}
cj(function(){
cj('#group').select2('val', '');
}
cj('#searchbygrouptype').click(function() {
showGroupTypeSearch();
});
......@@ -143,15 +116,6 @@
{if $form.contact_tags}
<td><label>{ts}Select Tag(s){/ts}</label>
{$form.contact_tags.html}
{literal}
<script type="text/javascript">
cj("select#contact_tags").crmasmSelect({
respectParents: true
});
</script>
{/literal}
</td>
{else}
<td>&nbsp;</td>
......@@ -203,10 +167,8 @@
</table>
{literal}
<script type="text/javascript">
cj("select#privacy_options").crmasmSelect();
cj("select#privacy_options").change(function() {
var items = cj(this).siblings('ul.crmasmList').find('li').length;
if (items > 1) {
if (cj(this).val() && cj(this).val().length > 1) {
cj('#privacy-operator-wrapper').show();
} else {
cj('#privacy-operator-wrapper').hide();
......
......@@ -73,15 +73,4 @@
</tr>
{/if}
</table>
{literal}
<script type="text/javascript">
cj("#relation_target_group").crmasmSelect({
addItemTarget: 'bottom',
animate: false,
highlight: true,
sortable: true,
respectParents: true
});
</script>
{/literal}
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment