CRM-13966 - Convert adv search crmasmselect to select2
authorColeman Watts <coleman@civicrm.org>
Fri, 31 Jan 2014 03:31:30 +0000 (19:31 -0800)
committerColeman Watts <coleman@civicrm.org>
Fri, 31 Jan 2014 03:31:30 +0000 (19:31 -0800)
CRM/Activity/BAO/Query.php
CRM/Contact/Form/Search/Criteria.php
css/civicrm.css
i/magnify.gif [deleted file]
js/Common.js
templates/CRM/Activity/Form/Search/Common.tpl
templates/CRM/Contact/Form/Search/AdvancedCriteria.tpl
templates/CRM/Contact/Form/Search/Criteria/Basic.tpl
templates/CRM/Contact/Form/Search/Criteria/Relationship.tpl

index 75ba22c180887e63b6d42cca18ff208a57328aaa..0550a372ab4deb84c9e4f32673cc4c4db5455356 100644 (file)
@@ -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')
         );
       }
     }
index 06433f915d334cee03d0881af6a78971a4bd6eb3..e485e728f6f0f05317cd58f4ab8bfb4dcecea73f 100644 (file)
@@ -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, '&nbsp;&nbsp;', 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);
index 351b5aa6cf664107ccc3f948d9b414dae81671d8..47b8bb0010cef0ed1b6314153633576dd4971a73 100644 (file)
@@ -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 (file)
index d0ea522..0000000
Binary files a/i/magnify.gif and /dev/null differ
index c36dc94220cc21a78cb47286db70cb42676aad54..d6111c79d13b42ba0e459f73ab0d9923e87b7f0e 100644 (file)
@@ -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';
 
index 236d72082cc24409322a5b3d3772f6b51d997f9b..15d3e605503f2658b4e5a4d800a85959600bfbf3 100644 (file)
          <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>
index 8782a520c86aa829f80b9d27daefecd9641bfbdc..a989d150f4a6989670a1e07566aa93d1f684fd5e 100644 (file)
@@ -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});
     }
   }
 });
index f4ef9274d5efad4d9846a61e2fa8fe88a923e58b..40b25281a038fcd1fa4b6c4796953bc724c75bad 100644 (file)
   {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>
     <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();
           });
     {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>
       </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();
index 5fae8341f1f9ecaa889dc937099b2569ba0acf1d..c14aebedeaf72e6496c4a21e46059b7c8faf3912 100644 (file)
       </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>