diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 133a2ca..a87994b 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -2,9 +2,9 @@ class ProfileDesignController < BoxOrganizerController needs_profile - BLOCKS = [ - Block - ] + def available_blocks + @available_blocks ||= [ Block, ArticleBlock ] + end def index render :action => 'index' @@ -13,14 +13,14 @@ class ProfileDesignController < BoxOrganizerController def add_block type = params[:type] if ! type.blank? - if BLOCKS.map(&:name).include?(type) + if available_blocks.map(&:name).include?(type) boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new redirect_to :action => 'index' else raise ArgumentError.new("Type %s is not allowed. Go away." % type) end else - @block_types = BLOCKS + @block_types = available_blocks @boxes = boxes_holder.boxes render :action => 'add_block', :layout => false end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dce60f9..85553c7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -261,7 +261,7 @@ module ApplicationHelper end def button(type, label, url, html_options = {}) - the_class = "button #{type}" + the_class = "button with_text #{type}" if html_options.has_key?(:class) the_class << ' ' << html_options[:class] end @@ -297,6 +297,15 @@ module ApplicationHelper content_tag('div', '', html_options.merge(:class => the_class)) end + def icon_button(type, text, url, html_options = {}) + the_class = "button #{type}" + if html_options.has_key?(:class) + the_class << ' ' << html_options[:class] + end + + link_to(content_tag('span', text), url, html_options.merge(:class => the_class, :title => text)) + end + def button_bar(options = {}, &block) concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), { :class => 'button-bar' }.merge(options)), block.binding) end diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 8ffd08b..ed86bf6 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -55,7 +55,7 @@ module BoxesHelper classes = 'block' # ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ') - box_decorator.block_target(block.box, block) + content_tag('div', result + box_decorator.block_move_buttons(block), :class => classes, :id => "block-#{block.id}") + box_decorator.block_handle(block) + box_decorator.block_target(block.box, block) + content_tag('div', result + box_decorator.block_edit_buttons(block), :class => classes, :id => "block-#{block.id}") + box_decorator.block_handle(block) end module DontMoveBlocks @@ -67,7 +67,7 @@ module BoxesHelper def self.block_handle(block) '' end - def self.block_move_buttons(block) + def self.block_edit_buttons(block) '' end end @@ -96,14 +96,17 @@ module BoxesHelper draggable_element("block-#{block.id}", :revert => true) end - def block_move_buttons(block) + def block_edit_buttons(block) buttons = [] - # FIXME hardcoded paths !!! - buttons << link_to(image_tag('/designs/icons/default/gtk-go-up.png', :alt => _('Move block up')), { :action => 'move_block_up', :id => block.id }, { :method => 'post' }) unless block.first? - buttons << link_to(image_tag('/designs/icons/default/gtk-go-down.png', :alt => _('Move block down')), { :action => 'move_block_down' ,:id => block.id }, { :method => 'post'}) unless block.last? + buttons << icon_button(:up, _('Move block up'), { :action => 'move_block_up', :id => block.id }, { :method => 'post' }) unless block.first? + buttons << icon_button(:down, _('Move block down'), { :action => 'move_block_down' ,:id => block.id }, { :method => 'post'}) unless block.last? - content_tag('div', buttons.join("\n"), :class => 'block-move-buttons') + if block.editor + buttons << lightbox_button(:edit, _('Edit'), block.editor) + end + + content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar') end end diff --git a/app/models/article_block.rb b/app/models/article_block.rb index 2286a0b..ef7d27d 100644 --- a/app/models/article_block.rb +++ b/app/models/article_block.rb @@ -4,8 +4,8 @@ class ArticleBlock < Block _('Display one of your contents.') end - def content - article.to_html + def content(main = nil) + article ? article.to_html : _('Article not selected yet.') end def article_id @@ -29,4 +29,8 @@ class ArticleBlock < Block @article = obj end + def editor + { :controller => 'profile_design', :action => 'edit', :id => self.id } + end + end diff --git a/app/models/block.rb b/app/models/block.rb index 5f64868..189fab6 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -15,4 +15,8 @@ class Block < ActiveRecord::Base "This is block number %d" % self.id end + def editor + nil + end + end -- libgit2 0.21.2