diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb index 4780917..081ebcb 100644 --- a/app/controllers/admin/admin_panel_controller.rb +++ b/app/controllers/admin/admin_panel_controller.rb @@ -32,16 +32,17 @@ class AdminPanelController < AdminController end def set_portal_folders - @portal_folders = environment.portal_community.folders + @selected = (environment.portal_folders || []) + @available_portal_folders = environment.portal_community.folders - @selected + if request.post? env = environment - folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})} + folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})} if params[:folders] env.portal_folders = folders if env.save flash[:notice] = _('Saved the portal folders') redirect_to :action => 'index' end end - @selected = (environment.portal_folders || []).map(&:id) end end diff --git a/app/models/environment.rb b/app/models/environment.rb index d06a955..53af908 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -622,7 +622,7 @@ class Environment < ActiveRecord::Base end def portal_folders=(folders) - settings[:portal_folders] = folders.map(&:id) + settings[:portal_folders] = folders ? folders.map(&:id) : nil end def help_message_to_add_enterprise diff --git a/app/views/admin_panel/set_portal_folders.rhtml b/app/views/admin_panel/set_portal_folders.rhtml index ab69986..f460c56 100644 --- a/app/views/admin_panel/set_portal_folders.rhtml +++ b/app/views/admin_panel/set_portal_folders.rhtml @@ -1,11 +1,37 @@

<%= _('Select folders') %>

-

<%= _('Select what folder will hold the news for witch area of the initial page of the environment') %>

+

<%= _('Select the folders that will hold the news of the initial page of the environment') %>

+ + + +
+ <%= labelled_form_field(_('Available folders'), select_tag( 'folders[]', options_from_collection_for_select(@available_portal_folders, :id, :name, nil), {:id => 'portal-folders-list', :multiple => true, :size => 6 }) ) %> +
+ +
+ <%= button :down, _('Add'), '#', { :id => 'add' } %> + <%= button :up, _('Remove'), '#', { :id => 'remove' } %> +
<% form_tag do %> - <% (1..4).each do |i| %> - <%= labelled_select _('Area %d: ') % i, 'folders[]', :id, :name, @selected[i-1], @portal_folders %>
- <% end %> +
+ <%= labelled_form_field(_('Portal folders'), select_tag( 'folders[]', options_from_collection_for_select(@selected, :id, :name, nil), {:id => 'selected-folders', :multiple => true, :size => 6 })) %> +
<% button_bar do %> <%= submit_button 'save', _('Save'), :cancel => {:action => 'index'} %> diff --git a/public/stylesheets/controller_admin_panel.css b/public/stylesheets/controller_admin_panel.css new file mode 100644 index 0000000..a033363 --- /dev/null +++ b/public/stylesheets/controller_admin_panel.css @@ -0,0 +1,11 @@ +#available-folders select { + width: 50%; +} + +#selection-buttons { + display: block; +} + +#portal-folders select { + width: 50%; +} diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index 5272182..b9da9a8 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -160,9 +160,43 @@ class AdminPanelControllerTest < Test::Unit::TestCase env.save! get :set_portal_folders - assert_tag :tag => 'option', :attributes => {:value => local.id}, :content => local.name - assert_tag :tag => 'option', :attributes => {:value => tech.id}, :content => tech.name - assert_tag :tag => 'option', :attributes => {:value => politics.id}, :content => politics.name + [local, tech, politics].each do |folder| + assert_tag :tag => 'div', :attributes => {:id => 'available-folders'}, :descendant => {:tag => 'option', :attributes => {:value => folder.id}, :content => folder.name} + end + end + + should 'not display not portal folders on portal-folders' do + env = Environment.default + c = Community.create!(:name => 'portal') + env.portal_community = c + local = Folder.create!(:profile => c, :name => 'local news') + tech = Folder.create!(:profile => c, :name => 'tech news') + politics = Folder.create!(:profile => c, :name => 'politics news') + env.save! + + get :set_portal_folders + [local, tech, politics].each do |folder| + assert_no_tag :tag => 'div', :attributes => {:id => 'portal-folders'}, :descendant => {:tag => 'option', :attributes => {:value => folder.id}, :content => folder.name} + end + end + + should 'list portal folders for removal' do + env = Environment.default + c = Community.create!(:name => 'portal') + env.portal_community = c + local = Folder.create!(:profile => c, :name => 'local news') + tech = Folder.create!(:profile => c, :name => 'tech news') + politics = Folder.create!(:profile => c, :name => 'politics news') + env.save! + env.portal_folders = [local, tech] + env.save! + + get :set_portal_folders + [local, tech].each do |folder| + assert_tag :tag => 'div', :attributes => {:id => 'portal-folders'}, :descendant => {:tag => 'option', :attributes => {:value => folder.id}, :content => folder.name} + end + + assert_no_tag :tag => 'div', :attributes => {:id => 'portal-folders'}, :descendant => {:tag => 'option', :attributes => {:value => politics.id}, :content => politics.name} end should 'save a list of folders as portal folders for the environment' do @@ -180,4 +214,16 @@ class AdminPanelControllerTest < Test::Unit::TestCase assert_equal [local, politics, tech].map(&:id), env.portal_folders.map(&:id) end + + should 'remove all folders as portal folders for the environment' do + env = Environment.default + @controller.stubs(:environment).returns(env) + c = Community.create!(:name => 'portal') + env.portal_community = c + env.save! + + post :set_portal_folders + + assert_equal [], env.portal_folders + end end diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index d0ffbae..d74e37e 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -741,6 +741,15 @@ class EnvironmentTest < Test::Unit::TestCase assert_equal [], e.portal_folders end + should 'remove all portal folders' do + e = Environment.default + + e.portal_folders = nil + e.save!; e.reload + + assert_equal [], e.portal_folders + end + should 'have roles with names independent of other environments' do e1 = Environment.create!(:name => 'a test environment') role1 = Role.create!(:name => 'test_role', :environment => e1) -- libgit2 0.21.2