Commit c61d178e9519d3909ea71cc10d79a921422be9c5

Authored by Moises Machado
Committed by Antonio Terceiro
1 parent 02283b78

ActionItem1041: block options now better

* links in link list block can have icons
 * added name to profile image block
 * added ProfileImageBlock to all profile to choose
app/models/link_list_block.rb
1 1 class LinkListBlock < Block
2 2  
  3 + ICONS = [
  4 + ['edit', N_('Edit')],
  5 + ['new', N_('New')],
  6 + ['save', N_('Save')],
  7 + ['send', N_('Send')],
  8 + ['cancel', N_('Cancel')],
  9 + ['add', N_('Add')],
  10 + ['up', N_('Up')],
  11 + ['down', N_('Down')],
  12 + ['left', N_('Left')],
  13 + ['right', N_('Right')],
  14 + ['up-disabled', N_('Gray Up')],
  15 + ['down-disabled', N_('Gray Down')],
  16 + ['left-disabled', N_('Gray Left')],
  17 + ['right-disabled', N_('Gray Right')],
  18 + ['up-red', N_('Red Up')],
  19 + ['search', N_('Search')],
  20 + ['ok', N_('Ok')],
  21 + ['login', N_('Login')],
  22 + ['help', N_('Help')],
  23 + ['spread', N_('Spread')],
  24 + ['eyes', N_('Eyes')]
  25 + ]
  26 +
3 27 settings_items :links, Array, :default => []
4 28  
5 29 before_save do |block|
... ... @@ -13,14 +37,19 @@ class LinkListBlock &lt; Block
13 37 def help
14 38 _('This block can be used to create a menu of links. You can add, remove and update the links as you wish.')
15 39 end
16   -
  40 +
17 41 def content
18 42 block_title(title) +
19 43 content_tag('ul',
20   - links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_to(i[:name], expand_address(i[:address])))}
  44 + links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_html(i))}
21 45 )
22 46 end
23 47  
  48 + def link_html(link)
  49 + klass = 'icon-' + link[:icon] if link[:icon]
  50 + link_to(link[:name], expand_address(link[:address]), :class => klass)
  51 + end
  52 +
24 53 def expand_address(address)
25 54 if owner.respond_to?(:identifier)
26 55 address.gsub('{profile}', owner.identifier)
... ... @@ -33,4 +62,11 @@ class LinkListBlock &lt; Block
33 62 true
34 63 end
35 64  
  65 + def icons_options(selected = nil)
  66 + ICONS.map do |i|
  67 + select = "selected='1'" if i[0] == selected
  68 + "<option class='icon-#{i[0]}' value='#{i[0]}' #{select}>#{i[1]}</option>"
  69 + end
  70 + end
  71 +
36 72 end
... ...
app/models/profile_image_block.rb
1 1 class ProfileImageBlock < Block
2 2  
  3 + settings_items :show_name, :type => :boolean, :default => false
  4 +
3 5 def self.description
4 6 _('A block that displays only image of profiles')
5 7 end
... ... @@ -8,15 +10,20 @@ class ProfileImageBlock &lt; Block
8 10 _('This block presents the profile image.')
9 11 end
10 12  
  13 + def default_title
  14 + owner.name
  15 + end
  16 +
11 17 def content
12 18 block = self
  19 + s = show_name
13 20 lambda do
14   - render :file => 'blocks/profile_image', :locals => { :block => block }
  21 + render :file => 'blocks/profile_image', :locals => { :block => block, :show_name => s}
15 22 end
16 23 end
17 24  
18 25 def editable?
19   - false
  26 + true
20 27 end
21 28  
22 29 def cacheable?
... ...
app/views/blocks/profile_image.rhtml
... ... @@ -10,6 +10,10 @@
10 10 </div>
11 11 </div>
12 12  
  13 +<% if show_name %>
  14 + <p><%= block.title %></p>
  15 +<% end %>
  16 +
13 17 <% if !user.nil? and user.has_permission?('edit_profile', profile) %>
14 18 <div style='text-align: center; font-size: 75%; clear: both'>
15 19 <%= link_to _('Control panel'), :controller => 'profile_editor' %>
... ...
app/views/box_organizer/_link_list_block.rhtml
1 1 <strong><%= _('Links') %></strong>
2 2 <div id='edit-link-list-block'>
3 3 <table id='links' class='noborder'>
4   - <tr><th><%= _('Name') %></th><th><%= _('Address') %></th></tr>
  4 + <tr><th><%= _('Icon') %></th><th><%= _('Name') %></th><th><%= _('Address') %></th></tr>
5 5 <% for link in @block.links do %>
6 6 <tr>
  7 + <td><%= select_tag 'block[links][][icon]', @block.icons_options(link['icon']) %></td>
7 8 <td><%= text_field_tag 'block[links][][name]', link[:name] %></td>
8 9 <td class='cel-address'><%= text_field_tag 'block[links][][address]', link[:address] %></td>
9 10 </tr>
... ... @@ -12,6 +13,6 @@
12 13 </div>
13 14  
14 15 <%= link_to_function(_('New link'), nil, :class => 'button icon-add with-text') do |page|
15   - page.insert_html :bottom, 'links', content_tag('tr', content_tag('td',text_field_tag('block[links][][name]')) + content_tag('td',text_field_tag('block[links][][address]', nil, :class => 'cel-address'))) +
  16 + page.insert_html :bottom, 'links', content_tag('tr', content_tag('td', select_tag('block[links][][icon]', @block.icons_options)) + content_tag('td',text_field_tag('block[links][][name]')) + content_tag('td',text_field_tag('block[links][][address]', nil, :class => 'cel-address'))) +
16 17 javascript_tag("$('edit-link-list-block').scrollTop = $('edit-link-list-block').scrollHeight")
17 18 end %>
... ...
app/views/box_organizer/_profile_image_block.rhtml 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +<%= check_box(:block, :show_name) %>
  2 +<label for="block_show_name"><%= _('Show name on block')%></label>
... ...
public/stylesheets/blocks/link-list-block.css
... ... @@ -9,7 +9,7 @@
9 9 }
10 10  
11 11 #edit-link-list-block table .cel-address {
12   - width: 300px;
  12 + width: 180px;
13 13 }
14 14  
15 15 #edit-link-list-block table .cel-address input {
... ... @@ -33,6 +33,19 @@
33 33 }
34 34  
35 35 .link-list-block a {
36   - text-decoration: none;
37 36 display: block;
  37 + text-decoration: none;
  38 + background-repeat: no-repeat;
  39 + padding-left: 23px;
  40 +}
  41 +
  42 +#edit-link-list-block select {
  43 + width: 80px;
  44 +}
  45 +
  46 +#edit-link-list-block option {
  47 + background-repeat: no-repeat;
  48 + padding-left: 23px;
  49 + margin: 2px;
  50 + height: 16px;
38 51 }
... ...
test/unit/link_list_block_test.rb
... ... @@ -40,4 +40,21 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
40 40 assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/test_profile/address'}
41 41 end
42 42  
  43 + should 'display options for icons' do
  44 + l = LinkListBlock.new
  45 + l.icons_options.each do |option|
  46 + assert_match(/<option class='icon-.+' value='.+' (selected='1')?>[^<>]+<\/option>/, option)
  47 + end
  48 + end
  49 +
  50 + should 'link with icon' do
  51 + l = LinkListBlock.new
  52 + assert_match /class="icon-save"/, l.link_html({:icon => 'save', :name => 'test', :address => 'test.com'})
  53 + end
  54 +
  55 + should 'no class without icon' do
  56 + l = LinkListBlock.new
  57 + assert_no_match /class="/, l.link_html({:icon => nil, :name => 'test', :address => 'test.com'})
  58 + end
  59 +
43 60 end
... ...