diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index a6b64ee..4cb86c4 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -162,9 +162,6 @@ module BoxesHelper # # +box+ is always needed def block_target(box, block = nil) - # FIXME hardcoded - return '' if box.position == 1 - id = if block.nil? "end-of-box-#{box.id}" @@ -172,14 +169,11 @@ module BoxesHelper "before-block-#{block.id}" end - content_tag('div', ' ', :id => id, :class => 'block-target' ) + drop_receiving_element(id, :url => { :action => 'move_block', :target => id }, :accept => 'block', :hoverclass => 'block-target-hover') + content_tag('div', ' ', :id => id, :class => 'block-target' ) + drop_receiving_element(id, :url => { :action => 'move_block', :target => id }, :accept => box.acceptable_blocks, :hoverclass => 'block-target-hover') end # makes the given block draggable so it can be moved away. def block_handle(block) - # FIXME hardcoded - return '' if block.box.position == 1 - draggable_element("block-#{block.id}", :revert => true) end diff --git a/app/models/box.rb b/app/models/box.rb index d293529..6590e40 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -2,4 +2,45 @@ class Box < ActiveRecord::Base belongs_to :owner, :polymorphic => true acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\'' has_many :blocks, :dependent => :destroy, :order => 'position' + + def acceptable_blocks + to_css_class_name (position == 1) ? acceptable_center_blocks : acceptable_side_blocks + end + + private + + def acceptable_center_blocks + %w{ MainBlock } + end + + def acceptable_side_blocks + %w{ + ArticleBlock + CategoriesBlock + CommunitiesBlock + EnterprisesBlock + EnvironmentStatisticsBlock + FeaturedProductsBlock + FeedReaderBlock + HighlightsBlock + LinkListBlock + LocationBlock + LoginBlock + MyNetworkBlock + PeopleBlock + ProfileImageBlock + ProfileInfoBlock + ProfileSearchBlock + RawHTMLBlock + RecentDocumentsBlock + SellersSearchBlock + SlideshowBlock + TagsBlock + } + end + + def to_css_class_name(blocks) + blocks.map{ |block| block.underscore.tr('_', '-') } + end + end diff --git a/test/unit/box_test.rb b/test/unit/box_test.rb new file mode 100644 index 0000000..ec94ce8 --- /dev/null +++ b/test/unit/box_test.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BoxTest < ActiveSupport::TestCase + + should 'list allowed blocks for center box' do + b = Box.new(:position => 1) + assert b.acceptable_blocks.include?('main-block') + end + + should 'list allowed blocks for box at position 2' do + b = Box.new(:position => 2) + assert !b.acceptable_blocks.include?('main-block') + end + +end -- libgit2 0.21.2