Commit 9ce6f648f649c2714b17f7a72be136184f0b1268

Authored by AntonioTerceiro
1 parent ab197b95

ActionItem152: adding a new block type and playing with block editor


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1238 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/profile_design_controller.rb
@@ -2,9 +2,9 @@ class ProfileDesignController < BoxOrganizerController @@ -2,9 +2,9 @@ class ProfileDesignController < BoxOrganizerController
2 2
3 needs_profile 3 needs_profile
4 4
5 - BLOCKS = [  
6 - Block  
7 - ] 5 + def available_blocks
  6 + @available_blocks ||= [ Block, ArticleBlock ]
  7 + end
8 8
9 def index 9 def index
10 render :action => 'index' 10 render :action => 'index'
@@ -13,14 +13,14 @@ class ProfileDesignController < BoxOrganizerController @@ -13,14 +13,14 @@ class ProfileDesignController < BoxOrganizerController
13 def add_block 13 def add_block
14 type = params[:type] 14 type = params[:type]
15 if ! type.blank? 15 if ! type.blank?
16 - if BLOCKS.map(&:name).include?(type) 16 + if available_blocks.map(&:name).include?(type)
17 boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new 17 boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new
18 redirect_to :action => 'index' 18 redirect_to :action => 'index'
19 else 19 else
20 raise ArgumentError.new("Type %s is not allowed. Go away." % type) 20 raise ArgumentError.new("Type %s is not allowed. Go away." % type)
21 end 21 end
22 else 22 else
23 - @block_types = BLOCKS 23 + @block_types = available_blocks
24 @boxes = boxes_holder.boxes 24 @boxes = boxes_holder.boxes
25 render :action => 'add_block', :layout => false 25 render :action => 'add_block', :layout => false
26 end 26 end
app/helpers/application_helper.rb
@@ -261,7 +261,7 @@ module ApplicationHelper @@ -261,7 +261,7 @@ module ApplicationHelper
261 end 261 end
262 262
263 def button(type, label, url, html_options = {}) 263 def button(type, label, url, html_options = {})
264 - the_class = "button #{type}" 264 + the_class = "button with_text #{type}"
265 if html_options.has_key?(:class) 265 if html_options.has_key?(:class)
266 the_class << ' ' << html_options[:class] 266 the_class << ' ' << html_options[:class]
267 end 267 end
@@ -297,6 +297,15 @@ module ApplicationHelper @@ -297,6 +297,15 @@ module ApplicationHelper
297 content_tag('div', '', html_options.merge(:class => the_class)) 297 content_tag('div', '', html_options.merge(:class => the_class))
298 end 298 end
299 299
  300 + def icon_button(type, text, url, html_options = {})
  301 + the_class = "button #{type}"
  302 + if html_options.has_key?(:class)
  303 + the_class << ' ' << html_options[:class]
  304 + end
  305 +
  306 + link_to(content_tag('span', text), url, html_options.merge(:class => the_class, :title => text))
  307 + end
  308 +
300 def button_bar(options = {}, &block) 309 def button_bar(options = {}, &block)
301 concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), { :class => 'button-bar' }.merge(options)), block.binding) 310 concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), { :class => 'button-bar' }.merge(options)), block.binding)
302 end 311 end
app/helpers/boxes_helper.rb
@@ -55,7 +55,7 @@ module BoxesHelper @@ -55,7 +55,7 @@ module BoxesHelper
55 55
56 classes = 'block' # ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ') 56 classes = 'block' # ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ')
57 57
58 - 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) 58 + 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)
59 end 59 end
60 60
61 module DontMoveBlocks 61 module DontMoveBlocks
@@ -67,7 +67,7 @@ module BoxesHelper @@ -67,7 +67,7 @@ module BoxesHelper
67 def self.block_handle(block) 67 def self.block_handle(block)
68 '' 68 ''
69 end 69 end
70 - def self.block_move_buttons(block) 70 + def self.block_edit_buttons(block)
71 '' 71 ''
72 end 72 end
73 end 73 end
@@ -96,14 +96,17 @@ module BoxesHelper @@ -96,14 +96,17 @@ module BoxesHelper
96 draggable_element("block-#{block.id}", :revert => true) 96 draggable_element("block-#{block.id}", :revert => true)
97 end 97 end
98 98
99 - def block_move_buttons(block) 99 + def block_edit_buttons(block)
100 buttons = [] 100 buttons = []
101 101
102 - # FIXME hardcoded paths !!!  
103 - 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?  
104 - 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? 102 + buttons << icon_button(:up, _('Move block up'), { :action => 'move_block_up', :id => block.id }, { :method => 'post' }) unless block.first?
  103 + buttons << icon_button(:down, _('Move block down'), { :action => 'move_block_down' ,:id => block.id }, { :method => 'post'}) unless block.last?
105 104
106 - content_tag('div', buttons.join("\n"), :class => 'block-move-buttons') 105 + if block.editor
  106 + buttons << lightbox_button(:edit, _('Edit'), block.editor)
  107 + end
  108 +
  109 + content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar')
107 end 110 end
108 111
109 end 112 end
app/models/article_block.rb
@@ -4,8 +4,8 @@ class ArticleBlock &lt; Block @@ -4,8 +4,8 @@ class ArticleBlock &lt; Block
4 _('Display one of your contents.') 4 _('Display one of your contents.')
5 end 5 end
6 6
7 - def content  
8 - article.to_html 7 + def content(main = nil)
  8 + article ? article.to_html : _('Article not selected yet.')
9 end 9 end
10 10
11 def article_id 11 def article_id
@@ -29,4 +29,8 @@ class ArticleBlock &lt; Block @@ -29,4 +29,8 @@ class ArticleBlock &lt; Block
29 @article = obj 29 @article = obj
30 end 30 end
31 31
  32 + def editor
  33 + { :controller => 'profile_design', :action => 'edit', :id => self.id }
  34 + end
  35 +
32 end 36 end
app/models/block.rb
@@ -15,4 +15,8 @@ class Block &lt; ActiveRecord::Base @@ -15,4 +15,8 @@ class Block &lt; ActiveRecord::Base
15 "This is block number %d" % self.id 15 "This is block number %d" % self.id
16 end 16 end
17 17
  18 + def editor
  19 + nil
  20 + end
  21 +
18 end 22 end