CRM-13966 - select2 for more forms
authorColeman Watts <coleman@civicrm.org>
Sun, 9 Feb 2014 01:25:11 +0000 (17:25 -0800)
committerColeman Watts <coleman@civicrm.org>
Sun, 9 Feb 2014 01:25:11 +0000 (17:25 -0800)
16 files changed:
CRM/Contact/Form/Edit/Address.php
CRM/Contact/Form/Edit/Email.php
CRM/Contact/Form/Edit/IM.php
CRM/Contact/Form/Edit/Phone.php
CRM/Contact/Form/Edit/Website.php
CRM/Contribute/BAO/ContributionPage.php
CRM/Contribute/Form/ContributionPage/Settings.php
CRM/Core/Form.php
CRM/Core/PseudoConstant.php
CRM/Event/BAO/Event.php
CRM/Event/Form/ManageEvent/EventInfo.php
CRM/Event/Form/ManageEvent/Fee.php
CRM/Event/Form/ManageEvent/ScheduleReminders.php
CRM/Utils/Api.php
templates/CRM/Event/Form/ManageEvent/EventInfo.tpl
templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl

index fa56341936146bc0e7c938d0e776d5d92e2d266c..8c2168c5ec7d60236d0ae63dc3af684727cbbfa8 100644 (file)
@@ -70,7 +70,7 @@ class CRM_Contact_Form_Edit_Address {
       $js = array('onChange' => 'checkLocation( this.id );');
     }
 
-    $form->addSelect("address[$blockId][location_type_id]", array('data-api-entity' => 'address', 'class' => 'six') + $js);
+    $form->addSelect("address[$blockId][location_type_id]", array('data-api-entity' => 'address', 'class' => 'eight') + $js);
 
     if (!$inlineEdit) {
       $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
index 75d48ad8584f9567cd4be4008fc6cd1a37d3979b..36694b653326dffd15550459f717c5cc1c8616a9 100644 (file)
@@ -65,7 +65,7 @@ class CRM_Contact_Form_Edit_Email {
     $form->addRule("email[$blockId][email]", ts('Email is not valid.'), 'email');
     if (isset($form->_contactType) || $blockEdit) {
       //Block type
-      $form->addSelect("email[$blockId][location_type_id]", array('data-api-entity' => 'email', 'class' => 'six'));
+      $form->addSelect("email[$blockId][location_type_id]", array('data-api-entity' => 'email', 'class' => 'eight'));
 
       $multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
 
index 89be43eeeab8b56b17a0f585741b7f5959a76ffe..27ee66448449fbcacbb0eda60cd3986691d6b74d 100644 (file)
@@ -59,10 +59,10 @@ class CRM_Contact_Form_Edit_IM {
     $form->applyFilter('__ALL__', 'trim');
 
     //IM provider select
-    $form->addSelect("im[$blockId][provider_id]", array('data-api-entity' => 'im', 'class' => 'six'));
+    $form->addSelect("im[$blockId][provider_id]", array('data-api-entity' => 'im', 'class' => 'eight'));
 
     //Block type select
-    $form->addSelect("im[$blockId][location_type_id]", array('data-api-entity' => 'im', 'class' => 'six'));
+    $form->addSelect("im[$blockId][location_type_id]", array('data-api-entity' => 'im', 'class' => 'eight'));
 
     //IM box
     $form->addElement('text', "im[$blockId][name]", ts('Instant Messenger'),
index 3fb2d97cd4bc4981ff29e6b0e0ac4eddcf68239d..c3eaac9af513490cb341b45ab00f504288a390f1 100644 (file)
@@ -61,7 +61,7 @@ class CRM_Contact_Form_Edit_Phone {
     $form->applyFilter('__ALL__', 'trim');
 
     //phone type select
-    $form->addSelect("phone[$blockId][phone_type_id]", array('data-api-entity' => 'phone', 'class' => 'six'));
+    $form->addSelect("phone[$blockId][phone_type_id]", array('data-api-entity' => 'phone', 'class' => 'eight'));
 
     //main phone number with crm_phone class
     $form->add('text', "phone[$blockId][phone]", ts('Phone'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'), array('class' => 'crm_phone twelve')));
@@ -70,7 +70,7 @@ class CRM_Contact_Form_Edit_Phone {
 
     if (isset($form->_contactType) || $blockEdit) {
       //Block type select
-      $form->addSelect("phone[$blockId][location_type_id]", array('data-api-entity' => 'phone', 'class' => 'six'));
+      $form->addSelect("phone[$blockId][location_type_id]", array('data-api-entity' => 'phone', 'class' => 'eight'));
 
       //is_Primary radio
       $js = array('id' => 'Phone_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
index 354e0ae9252c3f29a1050f38748bd75930defb3c..835d7b9d273d49ac9cb5b759ea6d5953b81ef802 100644 (file)
@@ -59,7 +59,7 @@ class CRM_Contact_Form_Edit_Website {
     $form->applyFilter('__ALL__', 'trim');
 
     //Website type select
-    $form->addSelect("website[$blockId][website_type_id]", array('data-api-entity' => 'website', 'class' => 'six'));
+    $form->addSelect("website[$blockId][website_type_id]", array('data-api-entity' => 'website', 'class' => 'eight'));
 
     //Website box
     $form->addElement('text', "website[$blockId][url]", ts('Website'),
index 7b3651c3f36ac1b9d72629d19d13f0ead98512f2..3e954e343706a4485dc12e5ef19a1e74b26346a5 100644 (file)
@@ -772,5 +772,27 @@ LEFT JOIN  civicrm_premiums            ON ( civicrm_premiums.entity_id = civicrm
 
     return $info;
   }
+
+  /**
+   * Get options for a given field.
+   * @see CRM_Core_DAO::buildOptions
+   *
+   * @param String $fieldName
+   * @param String $context: @see CRM_Core_DAO::buildOptionsContext
+   * @param Array  $props: whatever is known about this dao object
+   *
+   * @return array|bool
+   */
+  public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+    $params = array();
+    // Special logic for fields whose options depend on context or properties
+    switch ($fieldName) {
+      case 'financial_type_id':
+        // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
+        return CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
+        break;
+    }
+    return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+  }
 }
 
index be06c45e17a15473b83e16c49e8922070993185f..2624cd10a9c86af348dbdaa011dba51d52b9f25c 100644 (file)
@@ -129,12 +129,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
 
     // financial Type
-    $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
-    $this->add('select', 'financial_type_id',
-      ts('Financial Type'),
-      $financialType,
-      TRUE
-    );
+    $this->addSelect('financial_type_id', array(), TRUE);
 
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
index b3f6f1552dc7fcdb911ce2b7baff0ef26cd47968..67615c35b39f169ddbbeff5349ab6698afae1c55 100644 (file)
@@ -1230,11 +1230,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $freezeCurrency  = FALSE
   ) {
     $currencies = CRM_Core_OptionGroup::values('currencies_enabled');
+    $options = array('class' => 'crm-select2 eight');
     if (!$required) {
-      $currencies = array(
-        '' => ts('- select -')) + $currencies;
+      $currencies = array('' => '') + $currencies;
+      $options['placeholder'] = ts('- none -');
     }
-    $ele = $this->add('select', $name, $label, $currencies, $required);
+    $ele = $this->add('select', $name, $label, $currencies, $required, $options);
     if ($freezeCurrency) {
       $ele->freeze();
     }
index f13a8d903868cce7c1d89aacd98767e7c0e29e80..344cba8072ec3b44c3c9858ea061a41dcbd5455d 100644 (file)
@@ -511,9 +511,10 @@ class CRM_Core_PseudoConstant {
         return NULL;
       }
       // We don't have good mapping so have to do a bit of guesswork from the menu
-      list(, , , $ent) = explode('_', $daoName);
+      list(, $parent, , $child) = explode('_', $daoName);
       $sql = "SELECT path FROM civicrm_menu
-        WHERE page_callback LIKE '%CRM_Admin_Page_$ent%'
+        WHERE page_callback LIKE '%CRM_Admin_Page_$child%' OR page_callback LIKE '%CRM_{$parent}_Page_$child%'
+        ORDER BY page_callback
         LIMIT 1";
       return CRM_Core_Dao::singleValueQuery($sql);
     }
index 3ac4dc31f59e6347520cb48d4e1bb87731f97e8e..f27608f0a5004bc16531a0778c96236da01a1600 100644 (file)
@@ -2055,5 +2055,27 @@ LEFT  JOIN  civicrm_price_field_value value ON ( value.id = lineItem.price_field
     }
     CRM_Core_DAO::executeQuery($query, $params);
   }
+
+  /**
+   * Get options for a given field.
+   * @see CRM_Core_DAO::buildOptions
+   *
+   * @param String $fieldName
+   * @param String $context: @see CRM_Core_DAO::buildOptionsContext
+   * @param Array  $props: whatever is known about this dao object
+   *
+   * @return array|bool
+   */
+  public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+    $params = array();
+    // Special logic for fields whose options depend on context or properties
+    switch ($fieldName) {
+      case 'financial_type_id':
+        // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
+        return CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
+        break;
+    }
+    return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+  }
 }
 
index f48295cb19018b9574ae88217d7bdbe15cc8001c..5e3dcbe550b521ea1c4eaec4c3f97d300de30f02 100644 (file)
@@ -188,15 +188,9 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent {
     // add event title, make required if this is not a template
     $this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate);
 
-    $event = CRM_Core_OptionGroup::values('event_type');
-
-    $this->add('select',
-      'event_type_id',
-      ts('Event Type'),
-      array(
-        '' => ts('- select -')) + $event,
-      TRUE,
-      array('onChange' => "CRM.buildCustomData( 'Event', this.value );")
+    $this->addSelect('event_type_id',
+      array('onChange' => "CRM.buildCustomData( 'Event', this.value );"),
+      TRUE
     );
 
     //CRM-7362 --add campaigns.
@@ -206,22 +200,9 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent {
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
 
-    $participantRole = CRM_Core_OptionGroup::values('participant_role');
-    $this->add('select',
-      'default_role_id',
-      ts('Participant Role'),
-      $participantRole,
-      TRUE
-    );
+    $this->addSelect('default_role_id', array(), TRUE);
 
-    $participantListing = CRM_Core_OptionGroup::values('participant_listing');
-    $this->add('select',
-      'participant_listing_id',
-      ts('Participant Listing'),
-      array(
-        '' => ts('Disabled')) + $participantListing,
-      FALSE
-    );
+    $this->addSelect('participant_listing_id', array('placeholder' => ts('Disabled')));
 
     $this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']);
     $this->addWysiwyg('description', ts('Complete Description'), $attributes['event_description']);
index 2c693ee268678c15ba8bc078eda4fffec0dc5128..708566178fa45dbeb847b7e27e575a627aca15fb 100644 (file)
@@ -277,10 +277,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
     );
 
     // financial type
-    $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
-    $this->add('select', 'financial_type_id', ts('Financial Type'),
-      array('' => ts('- select -')) + $financialType
-    );
+    $this->addSelect('financial_type_id');
     // add pay later options
     $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), NULL,
       array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);")
index e9f26ae8d7e09eb307d01bf0d1213a3d614da3a3..099477456a3303e7a62f945ee649c496a0f7fb2e 100755 (executable)
@@ -137,8 +137,12 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
 
     $this->assign('recipientMapping', json_encode($recipientMapping));
 
-    $entity = $this->add('select', 'entity', ts('Recipient(s)'), $sel3[$this->_mappingID][0], TRUE);
-    $entity->setMultiple(TRUE);
+    // Fixme: hack to adjust the output of CRM_Core_BAO_ActionSchedule::getSelection so it looks nice with the jQuery.select2 plugin
+    // TODO: fix this upstream
+    $options = $sel3[$this->_mappingID][0];
+    $attributes = array('multiple' => 'multiple', 'class' => 'crm-select2 huge', 'placeholder' => $options[0]);
+    unset($options[0]);
+    $entity = $this->add('select', 'entity', ts('Recipient(s)'), $options, TRUE, $attributes);
 
     //get the frequency units.
     $this->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units');
@@ -185,10 +189,10 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
     $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions);
 
     $this->add('select', 'recipient', ts('Recipients'), $sel5[$recipient],
-      FALSE, array('onClick' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
+      FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
     );
     $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'),
-      $sel3[$this->_mappingID][0]
+      $sel3[$this->_mappingID][0], FALSE, array('class' => 'crm-select2 huge')
     );
     $recipientListing->setMultiple(TRUE);
 
@@ -207,8 +211,8 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
     $this->assign('tokenUrl', $tokenUrl);
     $this->add('text', 'recipient_manual_id', ts('Manual Recipients'));
 
-    $this->addElement('select', 'group_id', ts('Group'),
-      CRM_Core_PseudoConstant::staticGroup()
+    $this->add('select', 'group_id', ts('Group'),
+      CRM_Core_PseudoConstant::staticGroup(), FALSE, array('class' => 'crm-select2 huge')
     );
 
     CRM_Mailing_BAO_Mailing::commonCompose($this);
index 4d700e5e1da6b81c0695e443448784ce08e8d96e..4c1a04d18fb8d47ffadb6f15e46f06151dfbbec6 100644 (file)
@@ -41,15 +41,20 @@ class CRM_Utils_Api {
 
     // If that didn't work, try a different pattern
     if (!$shortName) {
-      list(, $entity) = explode('_', $className);
-      $daoName = "CRM_{$entity}_DAO_$entity";
+      list(, $parent, , $child) = explode('_', $className);
+      $daoName = "CRM_{$parent}_DAO_$child";
       $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
 
     // If that didn't work, try a different pattern
     if (!$shortName) {
-      list(, , , $entity) = explode('_', $className);
-      $daoName = "CRM_Core_DAO_$entity";
+      $daoName = "CRM_{$parent}_DAO_$parent";
+      $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
+    }
+
+    // If that didn't work, try a different pattern
+    if (!$shortName) {
+      $daoName = "CRM_Core_DAO_$child";
       $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     if (!$shortName) {
index a94b6c9280be29998befca90310be8658ed3168b..d1f68434dddf51ae47806535a60c286f8adc548c 100644 (file)
   <table class="form-layout-compressed">
              {if $form.template_id}
       <tr class="crm-event-manage-eventinfo-form-block-template_id">
-        <td class="label">{$form.template_id.label}</td>
-            <td>{$form.template_id.html} {help id="id-select-template" isTemplate=$isTemplate}</td>
+        <td class="label">{$form.template_id.label} {help id="id-select-template" isTemplate=$isTemplate}</td>
+            <td>{$form.template_id.html}</td>
           </tr>
         {/if}
     {if $form.template_title}
       <tr class="crm-event-manage-eventinfo-form-block-template_title">
-        <td class="label">{$form.template_title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_event' field='template_title' id=$eventID}{/if}</td>
-        <td>{$form.template_title.html} {help id="id-template-title"}</td>
+        <td class="label">{$form.template_title.label} {help id="id-template-title"}{if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_event' field='template_title' id=$eventID}{/if}</td>
+        <td>{$form.template_title.html}</td>
       </tr>
     {/if}
     <tr class="crm-event-manage-eventinfo-form-block-event_type_id">
           campaignTrClass="crm-event-manage-eventinfo-form-block-campaign_id"}
 
     <tr class="crm-event-manage-eventinfo-form-block-default_role_id">
-      <td class="label">{$form.default_role_id.label}</td>
-      <td>{$form.default_role_id.html} {help id="id-participant-role"}
+      <td class="label">{$form.default_role_id.label} {help id="id-participant-role"}</td>
+      <td>{$form.default_role_id.html}
       </td>
     </tr>
     <tr class="crm-event-manage-eventinfo-form-block-participant_listing_id">
-      <td class="label">{$form.participant_listing_id.label}</td>
-      <td>{$form.participant_listing_id.html} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$entityId}</td>
+      <td class="label">{$form.participant_listing_id.label} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$entityId}</td>
+      <td>{$form.participant_listing_id.html}</td>
     </tr>
     <tr class="crm-event-manage-eventinfo-form-block-title">
       <td class="label">{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_event' field='title' id=$eventID}{/if}</td>
@@ -89,8 +89,8 @@
       </tr>
     {/if}
     <tr class="crm-event-manage-eventinfo-form-block-max_participants">
-      <td class="label">{$form.max_participants.label}</td>
-      <td>{$form.max_participants.html|crmAddClass:four} {help id="id-max_participants" waitlist=$waitlist}</td>
+      <td class="label">{$form.max_participants.label} {help id="id-max_participants" waitlist=$waitlist}</td>
+      <td>{$form.max_participants.html|crmAddClass:four}</td>
     </tr>
     <tr id="id-waitlist" class="crm-event-manage-eventinfo-form-block-has_waitlist">
       {if $waitlist}
index 422471151837d2f0c32e1fb9e75d0e492759b084..131bd77d57bd8f4bab1ec443b779415285127a30 100755 (executable)
@@ -50,6 +50,7 @@
     {* added onload javascript for source contact*}
     {literal}
       <script type="text/javascript">
+        cj().crmAccordions();
       var recipient_manual = '';
       var recipient_manual_id = null;
       var toDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }{literal}"; {/literal}