From: Coleman Watts Date: Sun, 9 Feb 2014 01:25:11 +0000 (-0800) Subject: CRM-13966 - select2 for more forms X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e1462487648c958ab66b33dace8a1ec5ce22ecc2;p=civicrm-core.git CRM-13966 - select2 for more forms --- diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php index fa56341936..8c2168c5ec 100644 --- a/CRM/Contact/Form/Edit/Address.php +++ b/CRM/Contact/Form/Edit/Address.php @@ -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 );'); diff --git a/CRM/Contact/Form/Edit/Email.php b/CRM/Contact/Form/Edit/Email.php index 75d48ad858..36694b6533 100644 --- a/CRM/Contact/Form/Edit/Email.php +++ b/CRM/Contact/Form/Edit/Email.php @@ -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(); diff --git a/CRM/Contact/Form/Edit/IM.php b/CRM/Contact/Form/Edit/IM.php index 89be43eeea..27ee664484 100644 --- a/CRM/Contact/Form/Edit/IM.php +++ b/CRM/Contact/Form/Edit/IM.php @@ -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'), diff --git a/CRM/Contact/Form/Edit/Phone.php b/CRM/Contact/Form/Edit/Phone.php index 3fb2d97cd4..c3eaac9af5 100644 --- a/CRM/Contact/Form/Edit/Phone.php +++ b/CRM/Contact/Form/Edit/Phone.php @@ -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 );'); diff --git a/CRM/Contact/Form/Edit/Website.php b/CRM/Contact/Form/Edit/Website.php index 354e0ae925..835d7b9d27 100644 --- a/CRM/Contact/Form/Edit/Website.php +++ b/CRM/Contact/Form/Edit/Website.php @@ -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'), diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index 7b3651c3f3..3e954e3437 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -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); + } } diff --git a/CRM/Contribute/Form/ContributionPage/Settings.php b/CRM/Contribute/Form/ContributionPage/Settings.php index be06c45e17..2624cd10a9 100644 --- a/CRM/Contribute/Form/ContributionPage/Settings.php +++ b/CRM/Contribute/Form/ContributionPage/Settings.php @@ -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); diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index b3f6f1552d..67615c35b3 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -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(); } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index f13a8d9038..344cba8072 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -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); } diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 3ac4dc31f5..f27608f0a5 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -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); + } } diff --git a/CRM/Event/Form/ManageEvent/EventInfo.php b/CRM/Event/Form/ManageEvent/EventInfo.php index f48295cb19..5e3dcbe550 100644 --- a/CRM/Event/Form/ManageEvent/EventInfo.php +++ b/CRM/Event/Form/ManageEvent/EventInfo.php @@ -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']); diff --git a/CRM/Event/Form/ManageEvent/Fee.php b/CRM/Event/Form/ManageEvent/Fee.php index 2c693ee268..708566178f 100644 --- a/CRM/Event/Form/ManageEvent/Fee.php +++ b/CRM/Event/Form/ManageEvent/Fee.php @@ -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);") diff --git a/CRM/Event/Form/ManageEvent/ScheduleReminders.php b/CRM/Event/Form/ManageEvent/ScheduleReminders.php index e9f26ae8d7..099477456a 100755 --- a/CRM/Event/Form/ManageEvent/ScheduleReminders.php +++ b/CRM/Event/Form/ManageEvent/ScheduleReminders.php @@ -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); diff --git a/CRM/Utils/Api.php b/CRM/Utils/Api.php index 4d700e5e1d..4c1a04d18f 100644 --- a/CRM/Utils/Api.php +++ b/CRM/Utils/Api.php @@ -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) { diff --git a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl index a94b6c9280..d1f68434dd 100644 --- a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl +++ b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl @@ -36,14 +36,14 @@ {if $form.template_id} - - + + {/if} {if $form.template_title} - - + + {/if} @@ -56,13 +56,13 @@ campaignTrClass="crm-event-manage-eventinfo-form-block-campaign_id"} - - + - - + + @@ -89,8 +89,8 @@ {/if} - - + + {if $waitlist} diff --git a/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl b/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl index 4224711518..131bd77d57 100755 --- a/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl +++ b/templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl @@ -50,6 +50,7 @@ {* added onload javascript for source contact*} {literal}
{$form.template_id.label}{$form.template_id.html} {help id="id-select-template" isTemplate=$isTemplate}{$form.template_id.label} {help id="id-select-template" isTemplate=$isTemplate}{$form.template_id.html}
{$form.template_title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_event' field='template_title' id=$eventID}{/if}{$form.template_title.html} {help id="id-template-title"}{$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}{$form.template_title.html}
{$form.default_role_id.label}{$form.default_role_id.html} {help id="id-participant-role"} + {$form.default_role_id.label} {help id="id-participant-role"}{$form.default_role_id.html}
{$form.participant_listing_id.label}{$form.participant_listing_id.html} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$entityId}{$form.participant_listing_id.label} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$entityId}{$form.participant_listing_id.html}
{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_event' field='title' id=$eventID}{/if}
{$form.max_participants.label}{$form.max_participants.html|crmAddClass:four} {help id="id-max_participants" waitlist=$waitlist}{$form.max_participants.label} {help id="id-max_participants" waitlist=$waitlist}{$form.max_participants.html|crmAddClass:four}