Commit 48468ffadefaebd9a12267fdf54800352afd25d8
1 parent
913d398a
Exists in
master
and in
29 other branches
ActionItem114: using correct English: s/favorite/favourite/
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@844 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
13 changed files
with
191 additions
and
191 deletions
Show diff stats
app/controllers/profile_admin/profile_editor_controller.rb
app/design_blocks/favorite_links/controllers/favorite_links_controller.rb
| ... | ... | @@ -1,73 +0,0 @@ |
| 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 = params[:page].blank? ? 1 : params[:page].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
| ... | ... | @@ -1,37 +0,0 @@ |
| 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 |
app/design_blocks/favorite_links/views/add_link.rhtml
| ... | ... | @@ -1,13 +0,0 @@ |
| 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 | - |
app/design_blocks/favorite_links/views/edit.rhtml
| ... | ... | @@ -1,29 +0,0 @@ |
| 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 | - |
app/design_blocks/favorite_links/views/index.rhtml
| ... | ... | @@ -1,16 +0,0 @@ |
| 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
| ... | ... | @@ -1,21 +0,0 @@ |
| 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 %> |
app/design_blocks/favourite_links/controllers/favorite_links_controller.rb
0 → 100644
| ... | ... | @@ -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 = params[:page].blank? ? 1 : params[:page].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/favourite_links/models/favorite_links.rb
0 → 100644
| ... | ... | @@ -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 @@ |
| 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 @@ |
| 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 @@ |
| 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/favourite_links/views/manage_links.rhtml
0 → 100644
| ... | ... | @@ -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 %> | ... | ... |