From a2015e412a9ac053420f3eea78ab6ad8bf05fec7 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 8 Feb 2014 18:02:58 -0800 Subject: [PATCH] CRM-13966 - select2 for survey/campaign forms --- CRM/Campaign/BAO/Survey.php | 24 ++++++++++++++++++++++++ CRM/Campaign/Form/Campaign.php | 15 ++------------- CRM/Campaign/Form/Survey/Main.php | 2 +- CRM/Event/Form/ManageEvent/EventInfo.php | 2 +- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CRM/Campaign/BAO/Survey.php b/CRM/Campaign/BAO/Survey.php index 19088c53ef..318df3dbe2 100644 --- a/CRM/Campaign/BAO/Survey.php +++ b/CRM/Campaign/BAO/Survey.php @@ -1078,5 +1078,29 @@ UPDATE civicrm_activity return $rtnMsg; } + + /** + * 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 'activity_type_id': + $campaignCompId = CRM_Core_Component::getComponentID('CiviCampaign'); + if ($campaignCompId) { + $params['condition'] = array("component_id={$campaignCompId}", "v.name != 'Petition'"); + } + break; + } + return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); + } } diff --git a/CRM/Campaign/Form/Campaign.php b/CRM/Campaign/Form/Campaign.php index 903f02bcac..0ef20c3490 100644 --- a/CRM/Campaign/Form/Campaign.php +++ b/CRM/Campaign/Form/Campaign.php @@ -215,9 +215,6 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form { return CRM_Custom_Form_CustomData::buildQuickForm($this); } - //campaign types. - $campaignTypes = CRM_Campaign_PseudoConstant::campaignType(); - //lets assign custom data type and subtype. $this->assign('customDataType', 'Campaign'); $this->assign('entityID', $this->_campaignId); @@ -238,18 +235,10 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form { $this->addDateTime('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDateTime')); // add campaign type - $this->add('select', 'campaign_type_id', ts('Campaign Type'), - array( - '' => ts('- select -')) + $campaignTypes, TRUE, - array('onChange' => "CRM.buildCustomData( 'Campaign', this.value );") - ); + $this->addSelect('campaign_type_id', array('onChange' => "CRM.buildCustomData( 'Campaign', this.value );"), TRUE); // add campaign status - $campaignStatus = CRM_Campaign_PseudoConstant::campaignStatus(); - $this->addElement('select', 'status_id', ts('Campaign Status'), - array( - '' => ts('- select -')) + $campaignStatus - ); + $this->addSelect('status_id'); // add External Identifire Element $this->add('text', 'external_identifier', ts('External Id'), diff --git a/CRM/Campaign/Form/Survey/Main.php b/CRM/Campaign/Form/Survey/Main.php index 552df9686c..fffcbc2672 100644 --- a/CRM/Campaign/Form/Survey/Main.php +++ b/CRM/Campaign/Form/Survey/Main.php @@ -157,7 +157,7 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey { $surveyActivityTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType(); // Activity Type id - $this->add('select', 'activity_type_id', ts('Activity Type'), array('' => ts('- select -')) + $surveyActivityTypes, TRUE); + $this->addSelect('activity_type_id', array(), TRUE); // Campaign id $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value('campaign_id', $this->_values)); diff --git a/CRM/Event/Form/ManageEvent/EventInfo.php b/CRM/Event/Form/ManageEvent/EventInfo.php index 5e3dcbe550..e6d7cddcf4 100644 --- a/CRM/Event/Form/ManageEvent/EventInfo.php +++ b/CRM/Event/Form/ManageEvent/EventInfo.php @@ -181,7 +181,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { CRM_Core_Session::setStatus(ts('If you find that you are creating multiple events with similar settings, you may want to use the Event Templates feature to streamline your workflow.', array(1 => $url)), ts('Tip'), 'info'); } if (!CRM_Utils_System::isNull($eventTemplates)) { - $this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) + $eventTemplates); + $this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) + $eventTemplates, FALSE, array('class' => 'crm-select2 huge')); } } -- 2.25.1