Commit ad63089b7bdcb1b746b33f7598e1add5a60f6343

Authored by AntonioTerceiro
1 parent 2b7b639f

ActionItem114: still moving favorite to favourite

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@846 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/design_blocks/favourite_links/controllers/favorite_links_controller.rb
... ... @@ -1,73 +0,0 @@
1   -class FavouriteLinksController < 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_favourite_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_favourite_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_favourite_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_favourite_links
56   - design_render_on_edit :action => 'manage_links'
57   - end
58   -
59   - def get_favourite_links
60   - favourite_links = @design_block.favourite_links
61   - @favourite_links_pages, @favourite_links = paginate_by_collection favourite_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/controllers/favourite_links_controller.rb 0 → 100644
... ... @@ -0,0 +1,73 @@
  1 +class FavouriteLinksController < 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_favourite_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_favourite_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_favourite_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_favourite_links
  56 + design_render_on_edit :action => 'manage_links'
  57 + end
  58 +
  59 + def get_favourite_links
  60 + favourite_links = @design_block.favourite_links
  61 + @favourite_links_pages, @favourite_links = paginate_by_collection favourite_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
... ... @@ -1,37 +0,0 @@
1   -class FavouriteLinks < Design::Block
2   -
3   - def self.description
4   - _('Favourite 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 favourite_links_limited
16   - self.favourite_links.first(self.limit_number)
17   - end
18   -
19   - def favourite_links
20   - self.settings[:favourite_links] ||= []
21   - end
22   -
23   - def delete_link link
24   - self.settings[:favourite_links].reject!{ |item| item == link }
25   - self.save
26   - end
27   -
28   - def favourite_link
29   - nil
30   - end
31   -
32   - def favourite_link= link
33   - self.favourite_links.push(link)
34   - self.favourite_links.uniq!
35   - end
36   -
37   -end
app/design_blocks/favourite_links/models/favourite_links.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +class FavouriteLinks < Design::Block
  2 +
  3 + def self.description
  4 + _('Favourite 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 favourite_links_limited
  16 + self.favourite_links.first(self.limit_number)
  17 + end
  18 +
  19 + def favourite_links
  20 + self.settings[:favourite_links] ||= []
  21 + end
  22 +
  23 + def delete_link link
  24 + self.settings[:favourite_links].reject!{ |item| item == link }
  25 + self.save
  26 + end
  27 +
  28 + def favourite_link
  29 + nil
  30 + end
  31 +
  32 + def favourite_link= link
  33 + self.favourite_links.push(link)
  34 + self.favourite_links.uniq!
  35 + end
  36 +
  37 +end
... ...