From f38a825d6e9abe5aa5a6e603cb76318975ec3f7a Mon Sep 17 00:00:00 2001 From: Keilla Menezes Date: Fri, 11 Feb 2011 19:29:42 -0300 Subject: [PATCH] Show title in select options --- app/helpers/forms_helper.rb | 12 ++++++++++++ app/views/box_organizer/_article_block.rhtml | 5 +++-- public/stylesheets/application.css | 9 +++++++++ test/functional/environment_design_controller_test.rb | 2 +- test/unit/forms_helper_test.rb | 6 ++++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index 6b3511f..d0f2c9e 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -111,6 +111,18 @@ module FormsHelper )) end + def options_for_select_with_title(container, selected = nil) + container = container.to_a if Hash === container + + options_for_select = container.inject([]) do |options, element| + text, value = option_text_and_value(element) + selected_attribute = ' selected="selected"' if option_value_selected?(value, selected) + options << %() + end + + options_for_select.join("\n") + end + protected def self.next_id_number if defined? @@id_num diff --git a/app/views/box_organizer/_article_block.rhtml b/app/views/box_organizer/_article_block.rhtml index cc26300..2740795 100644 --- a/app/views/box_organizer/_article_block.rhtml +++ b/app/views/box_organizer/_article_block.rhtml @@ -1,9 +1,10 @@ - +
<% if @block.box.owner.kind_of?(Environment) and @block.box.owner.portal_community.nil? %>

<%= _("You don't have an community defined as the portal community. Define it before use this block properly.") %>

<% else %> <% articles = @block.available_articles.select {|article| !article.folder? } %> - <%= select('block', 'article_id', articles.map {|item| [ item.path, item.id]}) %> + <%= select_tag('block[article_id]', options_for_select_with_title(articles.map {|item| [item.path, item.id]})) %> <% end %> +
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index bb0cb1b..d8468aa 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -3944,6 +3944,15 @@ h1#agenda-title { margin: 5px 0px 5px 160px; } +.controller-profile_design .article-block-edition select, +.controller-profile_design .article-block-edition option { + width: 300px; +} + +.controller-profile_design .article-block-edition option { + overflow-x: hidden; +} + /* ==> public/stylesheets/controller_profile_editor.css <== */ .controller-profile_editor .categorie_box .button { diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index fa0d901..bf0e83a 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -70,7 +70,7 @@ class EnvironmentDesignControllerTest < Test::Unit::TestCase article.expects(:path).returns('some_path') article.expects(:id).returns(1) get :edit, :id => l.id - assert_tag :tag => 'select', :attributes => { :id => 'block_article_id' } + assert_tag :tag => 'select', :attributes => { :id => 'block[article_id]' } end should 'be able to edit ArticleBlock without portal community' do diff --git a/test/unit/forms_helper_test.rb b/test/unit/forms_helper_test.rb index ee4c323..06dd8a6 100644 --- a/test/unit/forms_helper_test.rb +++ b/test/unit/forms_helper_test.rb @@ -4,6 +4,7 @@ class FormsHelperTest < Test::Unit::TestCase include FormsHelper include ActionView::Helpers::TagHelper + include ActionView::Helpers::FormOptionsHelper should 'wrapper required fields in ' do content = required('') @@ -20,6 +21,11 @@ class FormsHelperTest < Test::Unit::TestCase assert_tag_in_string content, :tag => 'label', :content => 'highlighted', :attributes => {:class => 'pseudoformlabel'} end + should 'show title for option in select' do + content = options_for_select_with_title({'option_value' => 'option_title'}) + assert_tag_in_string content, :tag => 'option', :attributes => {:title => 'option_value'} + end + protected def _(text) -- libgit2 0.21.2