Commit ac098d9329a10a0d16c42c26979bb8de9802186f
Committed by
Daniela Feitosa
1 parent
c23f40da
Exists in
master
and in
28 other branches
Adding blocks whitelist for receive dropped draggable elements
Showing
3 changed files
with
57 additions
and
7 deletions
Show diff stats
app/helpers/boxes_helper.rb
... | ... | @@ -162,9 +162,6 @@ module BoxesHelper |
162 | 162 | # |
163 | 163 | # +box+ is always needed |
164 | 164 | def block_target(box, block = nil) |
165 | - # FIXME hardcoded | |
166 | - return '' if box.position == 1 | |
167 | - | |
168 | 165 | id = |
169 | 166 | if block.nil? |
170 | 167 | "end-of-box-#{box.id}" |
... | ... | @@ -172,14 +169,11 @@ module BoxesHelper |
172 | 169 | "before-block-#{block.id}" |
173 | 170 | end |
174 | 171 | |
175 | - content_tag('div', ' ', :id => id, :class => 'block-target' ) + drop_receiving_element(id, :url => { :action => 'move_block', :target => id }, :accept => 'block', :hoverclass => 'block-target-hover') | |
172 | + 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') | |
176 | 173 | end |
177 | 174 | |
178 | 175 | # makes the given block draggable so it can be moved away. |
179 | 176 | def block_handle(block) |
180 | - # FIXME hardcoded | |
181 | - return '' if block.box.position == 1 | |
182 | - | |
183 | 177 | draggable_element("block-#{block.id}", :revert => true) |
184 | 178 | end |
185 | 179 | ... | ... |
app/models/box.rb
... | ... | @@ -2,4 +2,45 @@ class Box < ActiveRecord::Base |
2 | 2 | belongs_to :owner, :polymorphic => true |
3 | 3 | acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\'' |
4 | 4 | has_many :blocks, :dependent => :destroy, :order => 'position' |
5 | + | |
6 | + def acceptable_blocks | |
7 | + to_css_class_name (position == 1) ? acceptable_center_blocks : acceptable_side_blocks | |
8 | + end | |
9 | + | |
10 | + private | |
11 | + | |
12 | + def acceptable_center_blocks | |
13 | + %w{ MainBlock } | |
14 | + end | |
15 | + | |
16 | + def acceptable_side_blocks | |
17 | + %w{ | |
18 | + ArticleBlock | |
19 | + CategoriesBlock | |
20 | + CommunitiesBlock | |
21 | + EnterprisesBlock | |
22 | + EnvironmentStatisticsBlock | |
23 | + FeaturedProductsBlock | |
24 | + FeedReaderBlock | |
25 | + HighlightsBlock | |
26 | + LinkListBlock | |
27 | + LocationBlock | |
28 | + LoginBlock | |
29 | + MyNetworkBlock | |
30 | + PeopleBlock | |
31 | + ProfileImageBlock | |
32 | + ProfileInfoBlock | |
33 | + ProfileSearchBlock | |
34 | + RawHTMLBlock | |
35 | + RecentDocumentsBlock | |
36 | + SellersSearchBlock | |
37 | + SlideshowBlock | |
38 | + TagsBlock | |
39 | + } | |
40 | + end | |
41 | + | |
42 | + def to_css_class_name(blocks) | |
43 | + blocks.map{ |block| block.underscore.tr('_', '-') } | |
44 | + end | |
45 | + | |
5 | 46 | end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class BoxTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'list allowed blocks for center box' do | |
6 | + b = Box.new(:position => 1) | |
7 | + assert b.acceptable_blocks.include?('main-block') | |
8 | + end | |
9 | + | |
10 | + should 'list allowed blocks for box at position 2' do | |
11 | + b = Box.new(:position => 2) | |
12 | + assert !b.acceptable_blocks.include?('main-block') | |
13 | + end | |
14 | + | |
15 | +end | ... | ... |