diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index de82113..3320c8f 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -1,12 +1,16 @@ class EnvironmentDesignController < BoxOrganizerController - + protect 'edit_environment_design', :environment def available_blocks # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from # the Noosfero core soon, see ActionItem3045 - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] - @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) + @blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + @blocks += plugins.dispatch(:extra_blocks, :type => Environment) + end + + def index + available_blocks end end diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index eb13d5d..5772ec8 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -5,10 +5,7 @@ class BoxOrganizerController < ApplicationController def index end - def move_block - @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) - - @source_box = @block.box + def add_or_move_block target_position = nil @@ -23,17 +20,26 @@ class BoxOrganizerController < ApplicationController @target_box = boxes_holder.boxes.find($1) end - if (@source_box != @target_box) - @block.remove_from_list + type = params[:id].gsub(/^block-/,'') + + if available_blocks.map(&:name).include?(type) + @block = type.constantize.new @block.box = @target_box + @block.position = target_position + else + @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) + @source_box = @block.box + + if (@source_box != @target_box) + @block.remove_from_list + @block.box = @target_box + end end if target_position.nil? - # insert in the end of the box @block.insert_at(@target_box.blocks.size + 1) @block.move_to_bottom else - # insert the block in the given position @block.insert_at(@block.position && @block.position < target_position ? target_position - 1 : target_position) end @@ -41,9 +47,12 @@ class BoxOrganizerController < ApplicationController @target_box.reload - unless request.xhr? - redirect_to :action => 'index' + if available_blocks.map(&:name).include?(type) + render :action => 'add_block' + else + render :action => 'move_block' end + end def move_block_down @@ -58,20 +67,17 @@ class BoxOrganizerController < ApplicationController redirect_to :action => 'index' end - def add_block + def show_block_type_info type = params[:type] if ! type.blank? if available_blocks.map(&:name).include?(type) - boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new - redirect_to :action => 'index' + @block = type.constantize else - raise ArgumentError.new("Type %s is not allowed. Go away." % type) + raise ArgumentError.new("Type %s is not allowed. Go away." % type) end + render :action => 'show_block_type_info', :layout => false else - @center_block_types = (Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1) - @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3]) - @boxes = boxes_holder.boxes.with_position - render :action => 'add_block', :layout => false + redirect_to :action => 'index' end end diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 97a4953..2f21d50 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -3,50 +3,54 @@ class ProfileDesignController < BoxOrganizerController needs_profile protect 'edit_profile_design', :profile - - def available_blocks - blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] - blocks += plugins.dispatch(:extra_blocks) + def available_blocks + @blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] + @blocks += plugins.dispatch(:extra_blocks) # blocks exclusive to people if profile.person? - blocks << FavoriteEnterprisesBlock - blocks << CommunitiesBlock - blocks << EnterprisesBlock - blocks += plugins.dispatch(:extra_blocks, :type => Person) + @blocks << FavoriteEnterprisesBlock + @blocks << CommunitiesBlock + @blocks << EnterprisesBlock + @blocks += plugins.dispatch(:extra_blocks, :type => Person) end # blocks exclusive to communities if profile.community? - blocks += plugins.dispatch(:extra_blocks, :type => Community) + @blocks += plugins.dispatch(:extra_blocks, :type => Community) end # blocks exclusive for enterprises if profile.enterprise? - blocks << DisabledEnterpriseMessageBlock - blocks << HighlightsBlock - blocks << ProductCategoriesBlock - blocks << FeaturedProductsBlock - blocks << FansBlock - blocks += plugins.dispatch(:extra_blocks, :type => Enterprise) + @blocks << DisabledEnterpriseMessageBlock + @blocks << HighlightsBlock + @blocks << ProductCategoriesBlock + @blocks << FeaturedProductsBlock + @blocks << FansBlock + @blocks += plugins.dispatch(:extra_blocks, :type => Enterprise) end # product block exclusive for enterprises in environments that permits it if profile.enterprise? && profile.environment.enabled?('products_for_enterprises') - blocks << ProductsBlock + @blocks << ProductsBlock end # block exclusive to profiles that have blog if profile.has_blog? - blocks << BlogArchivesBlock + @blocks << BlogArchivesBlock end if user.is_admin?(profile.environment) - blocks << RawHTMLBlock + @blocks << RawHTMLBlock end - blocks + @blocks + + end + + def index + available_blocks end end diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 02863be..6739525 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -171,7 +171,8 @@ 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 => box.acceptable_blocks, :hoverclass => 'block-target-hover') + content_tag('div', ' ', :id => id, :class => 'block-target', :style => "border: 1px solid red;" ) + + drop_receiving_element(id, :url => { :action => 'add_or_move_block', :target => id }, :accept => box.acceptable_blocks, :hoverclass => 'block-target-hover') end # makes the given block draggable so it can be moved away. diff --git a/app/models/block.rb b/app/models/block.rb index 1567781..4ce625a 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -110,11 +110,35 @@ class Block < ActiveRecord::Base # blocks to choose one to include in the design. # # Must be redefined in subclasses to match the description of each block - # type. + # type. def self.description '(dummy)' end + def self.short_description + '(dummy)' + end + + def self.release_notes + '(dummy)' + end + + def self.default_preview + "/images/block_preview.png" + end + + def self.previews + [] + end + + def self.icon + "/images/icon_block.png" + end + + def self.position + [1,2,3] + end + # Returns the content to be used for this block. # # This method can return several types of objects: diff --git a/app/views/box_organizer/add_block.html.erb b/app/views/box_organizer/add_block.html.erb deleted file mode 100644 index f086512..0000000 --- a/app/views/box_organizer/add_block.html.erb +++ /dev/null @@ -1,49 +0,0 @@ -
<%= _('In what area do you want to put your new block?') %>
- -<%= _('Select the type of block you want to add to your page.') %>
- -<%= @block.short_description %>
+<%= @block.description %>
+<%= @block.release_notes %>
+