Commit f16b74e2b8b540437ffce4543ce6a2f6233c78a4
1 parent
ee41e5ff
Exists in
master
and in
29 other branches
ActionItem19: adding blocks configuration and fixing fixtures of design_blocks
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@832 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
7 changed files
with
217 additions
and
30 deletions
Show diff stats
app/design_blocks/favorite_links/controllers/favorite_links_controller.rb
0 → 100644
@@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
1 | +class FavoriteLinksController < ApplicationController | ||
2 | + | ||
3 | + | ||
4 | + # The methods above are specific for noosfero application. I think | ||
5 | + # this it not the correct way to get this method. | ||
6 | + # | ||
7 | + # We can create a method in the app/controllers/profile_admin folder | ||
8 | + # the inherit this method and adds only the two lines above. | ||
9 | + # | ||
10 | + # With this way we can reuse this block on many others case and each case | ||
11 | + # we follow the same way. | ||
12 | + # | ||
13 | + # Specific for app | ||
14 | + needs_profile | ||
15 | + design :holder => 'profile' | ||
16 | + # End specific for app | ||
17 | + | ||
18 | + | ||
19 | + acts_as_design_block | ||
20 | + | ||
21 | + CONTROL_ACTION_OPTIONS = { | ||
22 | + 'manage_links' => _('Manage Links'), | ||
23 | + 'edit' => _('Edit'), | ||
24 | + } | ||
25 | + | ||
26 | + def index | ||
27 | + get_favorite_links | ||
28 | + design_render | ||
29 | + end | ||
30 | + | ||
31 | + def edit | ||
32 | + design_render_on_edit | ||
33 | + end | ||
34 | + | ||
35 | + def save | ||
36 | + if @design_block.update_attributes(params[:design_block]) | ||
37 | + get_favorite_links | ||
38 | + design_render_on_edit :action => 'manage_links' | ||
39 | + else | ||
40 | + design_render_on_edit :nothing => true | ||
41 | + end | ||
42 | + end | ||
43 | + | ||
44 | + def manage_links | ||
45 | + get_favorite_links | ||
46 | + design_render_on_edit | ||
47 | + end | ||
48 | + | ||
49 | + def add_link | ||
50 | + design_render_on_edit | ||
51 | + end | ||
52 | + | ||
53 | + def remove_link | ||
54 | + @design_block.delete_link(params[:link]) | ||
55 | + get_favorite_links | ||
56 | + design_render_on_edit :action => 'manage_links' | ||
57 | + end | ||
58 | + | ||
59 | + def get_favorite_links | ||
60 | + favorite_links = @design_block.favorite_links | ||
61 | + @favorite_links_pages, @favorite_links = paginate_by_collection favorite_links | ||
62 | + end | ||
63 | + | ||
64 | + def paginate_by_collection(collection, options = {}) | ||
65 | + page = ( 1).to_i | ||
66 | + items_per_page = @design_block.limit_number | ||
67 | + offset = (page - 1) * items_per_page | ||
68 | + link_pages = Paginator.new(self, collection.size, items_per_page, page) | ||
69 | + collection = collection[offset..(offset + items_per_page - 1)] | ||
70 | + return link_pages, collection | ||
71 | + end | ||
72 | + | ||
73 | +end |
app/design_blocks/favorite_links/models/favorite_links.rb
0 → 100644
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +class FavoriteLinks < Design::Block | ||
2 | + | ||
3 | + def self.description | ||
4 | + _('Favorite Links') | ||
5 | + end | ||
6 | + | ||
7 | + def limit_number= value | ||
8 | + self.settings[:limit_number] = value.to_i | ||
9 | + end | ||
10 | + | ||
11 | + def limit_number | ||
12 | + self.settings[:limit_number] || 5 | ||
13 | + end | ||
14 | + | ||
15 | + def favorite_links_limited | ||
16 | + self.favorite_links.first(self.limit_number) | ||
17 | + end | ||
18 | + | ||
19 | + def favorite_links | ||
20 | + self.settings[:favorite_links] ||= [] | ||
21 | + end | ||
22 | + | ||
23 | + def delete_link link | ||
24 | + self.settings[:favorite_links].reject!{ |item| item == link } | ||
25 | + self.save | ||
26 | + end | ||
27 | + | ||
28 | + def favorite_link | ||
29 | + nil | ||
30 | + end | ||
31 | + | ||
32 | + def favorite_link= link | ||
33 | + self.favorite_links.push(link) | ||
34 | + self.favorite_links.uniq! | ||
35 | + end | ||
36 | + | ||
37 | +end |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +<h2> <%= _('Editing Favorite Links') %> </h2> | ||
2 | + | ||
3 | +<% design_form_remote_tag( :url => {:action => 'save'}) do %> | ||
4 | + | ||
5 | + <p> | ||
6 | + <label for="design_block_title"> <%= _("Title") %> </label> | ||
7 | + <%= text_field 'design_block', 'favorite_link'%> | ||
8 | + </p> | ||
9 | + | ||
10 | + <%= submit_tag _('Save') %> | ||
11 | + | ||
12 | +<% end %> | ||
13 | + |
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | + | ||
2 | +<h2> <%= _('Editing Favorite Links') %> </h2> | ||
3 | + | ||
4 | + <% design_form_remote_tag( :url => {:action => 'save'}) do %> | ||
5 | + | ||
6 | + <p> | ||
7 | + <label for="design_block_title"> <%= _("Title") %> </label> | ||
8 | + <%= text_field 'design_block', 'title'%> | ||
9 | + </p> | ||
10 | + | ||
11 | + <p> | ||
12 | + <label for="design_block_display_header"> <%= _("Display header?") %> </label> | ||
13 | + <%= check_box 'design_block', 'display_header', {}, 'true', 'false' %> | ||
14 | + </p> | ||
15 | + | ||
16 | + <p> | ||
17 | + <label for="design_block_display_title"> <%= _("Display title?") %> </label> | ||
18 | + <%= check_box 'design_block', 'display_title', {}, 'true', 'false' %> | ||
19 | + </p> | ||
20 | + | ||
21 | + <p> | ||
22 | + <label for="design_block_limit_number"> <%= _("Max number of links") %> </label> | ||
23 | + <%= text_field 'design_block', 'limit_number'%> | ||
24 | + </p> | ||
25 | + | ||
26 | + <%= submit_tag _('Save') %> | ||
27 | + | ||
28 | +<% end %> | ||
29 | + |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | + | ||
2 | +<% if @favorite_links_pages.current.previous%> | ||
3 | + <%= design_link_to_remote(_('Previous'), :url => {:action => 'index', :page => @favorite_links_pages.current.previous}) %> | ||
4 | +<% end %> | ||
5 | +<% if @favorite_links_pages.current.next %> | ||
6 | + <%= design_link_to_remote(_('Next'), :url => {:action => 'index', :page => @favorite_links_pages.current.next}) %> | ||
7 | +<% end %> | ||
8 | + | ||
9 | +<% @favorite_links.each do |link| %> | ||
10 | + <ul> | ||
11 | + <li> | ||
12 | + <%= link_to link, link, :popup => true %> | ||
13 | + </li> | ||
14 | + </ul> | ||
15 | +<% end %> | ||
16 | + |
app/design_blocks/favorite_links/views/manage_links.rhtml
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | + | ||
2 | +<h2> | ||
3 | + <%= _('Favorite Links') %> | ||
4 | + <%= design_link_to_remote(_('Add Link'), :url => {:action => 'add_link'} )%> | ||
5 | + | ||
6 | +</h2> | ||
7 | +<% if @favorite_links_pages.current.previous%> | ||
8 | + <%= design_link_to_remote(_('Previous'), :url => {:action => 'manage_links', :page => @favorite_links_pages.current.previous}) %> | ||
9 | +<% end %> | ||
10 | +<% if @favorite_links_pages.current.next %> | ||
11 | + <%= design_link_to_remote(_('Next'), :url => {:action => 'manage_links', :page => @favorite_links_pages.current.next}) %> | ||
12 | +<% end %> | ||
13 | + | ||
14 | +<% @favorite_links.each do |link| %> | ||
15 | + <ul> | ||
16 | + <li> | ||
17 | + <%= link_to link, link, :popup => true %> | ||
18 | + <%= design_link_to_remote content_tag(:span,_('Remove')), :url => {:action => 'remove_link', :link => link } %> | ||
19 | + </li> | ||
20 | + </ul> | ||
21 | +<% end %> |
test/fixtures/design_blocks.yml
@@ -5,42 +5,40 @@ one: | @@ -5,42 +5,40 @@ one: | ||
5 | box_id: 2 | 5 | box_id: 2 |
6 | position: 1 | 6 | position: 1 |
7 | type: 'MainBlock' | 7 | type: 'MainBlock' |
8 | - helper: 'plain_content' | ||
9 | - name: 'Main Content' | ||
10 | -# Link Blocks | 8 | + title: 'Main Content' |
9 | +# FavoriteLinks Blocks | ||
11 | two: | 10 | two: |
12 | id: 2 | 11 | id: 2 |
13 | box_id: 1 | 12 | box_id: 1 |
14 | position: 2 | 13 | position: 2 |
15 | - type: 'LinkBlock' | ||
16 | - helper: 'list_content' | ||
17 | - name: 'List of Links 1' | 14 | + type: 'FavoriteLinks' |
15 | + title: 'List of Links 1' | ||
18 | three: | 16 | three: |
19 | id: 3 | 17 | id: 3 |
20 | box_id: 1 | 18 | box_id: 1 |
21 | position: 3 | 19 | position: 3 |
22 | - type: 'LinkBlock' | ||
23 | - helper: 'plain_content' | ||
24 | - name: 'List of Link 2' | 20 | + type: 'FavoriteLinks' |
21 | + title: 'List of Link 2' | ||
25 | #List Blocks | 22 | #List Blocks |
26 | -four: | ||
27 | - id: 4 | ||
28 | - box_id: 1 | ||
29 | - position: 1 | ||
30 | - type: 'ListBlock' | ||
31 | - helper: 'list_content' | ||
32 | - name: 'List of Names 1' | ||
33 | -five: | ||
34 | - id: 5 | ||
35 | - box_id: 3 | ||
36 | - position: 1 | ||
37 | - type: 'ListBlock' | ||
38 | - helper: 'list_content' | ||
39 | - name: 'List of Names 2' | ||
40 | -six: | ||
41 | - id: 6 | ||
42 | - box_id: 3 | ||
43 | - position: 2 | ||
44 | - type: 'ListBlock' | ||
45 | - helper: 'list_content' | ||
46 | - name: 'List of Names 3' | 23 | +#FIXME Put other blocks to works |
24 | +#four: | ||
25 | +# id: 4 | ||
26 | +# box_id: 1 | ||
27 | +# position: 1 | ||
28 | +# type: 'ListBlock' | ||
29 | +# helper: 'list_content' | ||
30 | +# title: 'List of titles 1' | ||
31 | +#five: | ||
32 | +# id: 5 | ||
33 | +# box_id: 3 | ||
34 | +# position: 1 | ||
35 | +# type: 'ListBlock' | ||
36 | +# helper: 'list_content' | ||
37 | +# title: 'List of titles 2' | ||
38 | +#six: | ||
39 | +# id: 6 | ||
40 | +# box_id: 3 | ||
41 | +# position: 2 | ||
42 | +# type: 'ListBlock' | ||
43 | +# helper: 'list_content' | ||
44 | +# title: 'List of titles 3' |