CRM-13966 - Migrate event type to select2
authorColeman Watts <coleman@civicrm.org>
Sat, 22 Feb 2014 15:55:33 +0000 (10:55 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 25 Feb 2014 14:27:42 +0000 (09:27 -0500)
CRM/Event/BAO/Query.php
CRM/Event/Form/Search.php
CRM/Event/Page/AJAX.php
CRM/Event/xml/Menu/Event.xml
templates/CRM/Event/Form/Search/Common.tpl

index 92a137e1e8930639362b4905dfcaedfc19e75fd9..193776249e629c0033f733e577d0f87c10a3e7d4 100644 (file)
@@ -539,6 +539,9 @@ class CRM_Event_BAO_Query {
     return $properties;
   }
 
+  /**
+   * @param CRM_Core_Form $form
+   */
   static function buildSearchForm(&$form) {
     $dataURLEvent = CRM_Utils_System::url('civicrm/ajax/event',
       "reset=1",
@@ -558,12 +561,19 @@ class CRM_Event_BAO_Query {
     $form->assign('dataURLEventFee', $dataURLEventFee);
 
     $eventId        = &$form->add('text', 'event_name', ts('Event Name'));
-    $eventType      = &$form->add('text', 'event_type', ts('Event Type'));
+    $eventType = $form->addEntityRef('event_type_id', ts('Event Type'), array(
+        'entity' => 'option_value',
+        'placeholder' => ts('- any -'),
+        'select' => array('minimumInputLength' => 0),
+        'api' => array(
+          'params' => array('option_group_id' => 'event_type'),
+        ),
+      )
+    );
     $participantFee = &$form->add('text', 'participant_fee_level', ts('Fee Level'));
 
     //elements for assigning value operation
     $eventNameId      = &$form->add('hidden', 'event_id', '', array('id' => 'event_id'));
-    $eventTypeId      = &$form->add('hidden', 'event_type_id', '', array('id' => 'event_type_id'));
     $participantFeeId = &$form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id'));
 
     CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);
index 463cefdcc38c61dd00bde126a131a24dced848c2..eeffc5875df56f0d3061a397a651fe24099fe04e 100644 (file)
@@ -445,36 +445,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
    * @access public
    * @see valid_date
    */
-  function addRules() {
-    $this->addFormRule(array('CRM_Event_Form_Search', 'formRule'));
-  }
-
-  /**
-   * global validation rules for the form
-   *
-   * @param array $fields posted values of the form
-   * @param array $errors list of errors to be posted back to the form
-   *
-   * @return void
-   * @static
-   * @access public
-   */
-  static function formRule($fields) {
-    $errors = array();
-
-    if ($fields['event_name'] && !is_numeric($fields['event_id'])) {
-      $errors['event_id'] = ts('Please select valid event.');
-    }
-
-    if ($fields['event_type'] && !is_numeric($fields['event_type_id'])) {
-      $errors['event_type'] = ts('Please select valid event type.');
-    }
-    if (!empty($errors)) {
-      return $errors;
-    }
-
-    return TRUE;
-  }
+  function addRules() {}
 
   /**
    * Set the default form values
index 44addaac0d3566dac6479c9afb614828a88a7ddc..36a558a25b2c66a4421ad95aab85be7bb6b4ce71 100644 (file)
@@ -83,34 +83,6 @@ class CRM_Event_Page_AJAX {
     CRM_Core_Page_AJAX::autocompleteResults($results);
   }
 
-  /**
-   * Function for building Event Type combo box
-   */
-  function eventType() {
-    $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
-    if (!$name) {
-      $name = '%';
-    }
-    $whereClause = " v.label LIKE '$name%' ";
-
-    $query = "
-SELECT v.label ,v.value
-FROM   civicrm_option_value v,
-       civicrm_option_group g
-WHERE  v.option_group_id = g.id
-AND g.name = 'event_type'
-AND v.is_active = 1
-AND {$whereClause}
-ORDER by v.weight";
-
-    $dao = CRM_Core_DAO::executeQuery($query);
-    $results = array();
-    while ($dao->fetch()) {
-      $results[$dao->value] = $dao->label;
-    }
-    CRM_Core_Page_AJAX::autocompleteResults($results);
-  }
-
   /**
    * Function for building EventFee combo box
    */
index 82dbe7cf6b5153b429ce0ebbd39b3c61a92960c7..a9872879838c1fca23034291f898b6f6db009176 100644 (file)
      <page_callback>CRM_Event_Page_AJAX::event</page_callback>
      <access_arguments>access CiviCRM,access CiviEvent</access_arguments>
   </item>
-  <item>
-     <path>civicrm/ajax/eventType</path>
-     <page_callback>CRM_Event_Page_AJAX::eventType</page_callback>
-     <access_arguments>access CiviCRM,access CiviEvent</access_arguments>
-  </item>
   <item>
      <path>civicrm/ajax/eventFee</path>
      <page_callback>CRM_Event_Page_AJAX::eventFee</page_callback>
index d60220f30a4efa4d3dcbfa59f9435628d7603a27..7ddc0b6d074ce7e29cc9861b450140befe4a59da 100644 (file)
@@ -24,8 +24,8 @@
  +--------------------------------------------------------------------+
 *}
 <tr>
-  <td class="crm-event-form-block-event_type"> {$form.event_name.label}  <br />{$form.event_name.html|crmAddClass:huge} </td>
-  <td class="crm-event-form-block-event_type"> {$form.event_type.label}<br />{$form.event_type.html} </td>
+  <td class="crm-event-form-block-event_name"> {$form.event_name.label}  <br />{$form.event_name.html|crmAddClass:huge} </td>
+  <td class="crm-event-form-block-event_type_id"> {$form.event_type_id.label}<br />{$form.event_type_id.html} </td>
 </tr>
 <tr>
   <td colspan="2"><label>{ts}Event Dates{/ts}</label></td>
@@ -90,17 +90,12 @@ campaignTrClass='' campaignTdClass='crm-event-form-block-participant_campaign_id
 {literal}
 <script type="text/javascript">
 var eventUrl = "{/literal}{$dataURLEvent}{literal}";
-var typeUrl  = "{/literal}{$dataURLEventType}{literal}";
 var feeUrl   = "{/literal}{$dataURLEventFee}{literal}";
 
 cj('#event_name').autocomplete( eventUrl, { width : 280, selectFirst : false, matchContains: true
 }).result( function(event, data, formatted) { cj( "input#event_id" ).val( data[1] );
   }).bind( 'click', function( ) { cj( "input#event_id" ).val(''); });
 
-cj('#event_type').autocomplete( typeUrl, { width : 180, selectFirst : false, matchContains: true
-}).result(function(event, data, formatted) { cj( "input#event_type_id" ).val( data[1] );
-  }).bind( 'click', function( ) { cj( "input#event_type_id" ).val(''); });
-
 cj('#participant_fee_level').autocomplete( feeUrl, { width : 180, selectFirst : false, matchContains: true
 }).result(function(event, data, formatted) { cj( "input#participant_fee_id" ).val( data[1] );
   }).bind( 'click', function( ) { cj( "input#participant_fee_id" ).val(''); });