Commit cf5172f0f099b484efc6564801c77b454052fb1f
1 parent
bb5df40e
Exists in
master
and in
29 other branches
ActionItem0: loading boxes correctly
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@89 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
1 changed file
with
35 additions
and
11 deletions
Show diff stats
app/controllers/application.rb
@@ -2,22 +2,14 @@ | @@ -2,22 +2,14 @@ | ||
2 | # available in all controllers. | 2 | # available in all controllers. |
3 | class ApplicationController < ActionController::Base | 3 | class ApplicationController < ActionController::Base |
4 | 4 | ||
5 | + TEMPLATE_DIR_PATH = 'public/templates' | ||
6 | + ICON_DIR_PATH = 'public/icons' | ||
7 | + | ||
5 | before_filter :detect_stuff_by_domain | 8 | before_filter :detect_stuff_by_domain |
6 | attr_reader :virtual_community | 9 | attr_reader :virtual_community |
7 | 10 | ||
8 | uses_manage_template :edit => false | 11 | uses_manage_template :edit => false |
9 | 12 | ||
10 | - before_filter :load_boxes | ||
11 | - #TODO To diplay the content we need a variable called '@boxes'. | ||
12 | - #This variable is a set of boxes belongs to a owner | ||
13 | - #We have to see a better way to do that | ||
14 | - def load_boxes | ||
15 | - if Profile.exists?(1) | ||
16 | - owner = Profile.find(1) | ||
17 | - @boxes = owner.boxes | ||
18 | - end | ||
19 | - end | ||
20 | - | ||
21 | before_filter :load_template | 13 | before_filter :load_template |
22 | # Load the template belongs to a Profile and set it at @chosen_template variable. | 14 | # Load the template belongs to a Profile and set it at @chosen_template variable. |
23 | # If no profile exist the @chosen_template variable is set to 'default' | 15 | # If no profile exist the @chosen_template variable is set to 'default' |
@@ -28,6 +20,38 @@ class ApplicationController < ActionController::Base | @@ -28,6 +20,38 @@ class ApplicationController < ActionController::Base | ||
28 | @chosen_template = @owner.nil? ? "default" : @owner.template | 20 | @chosen_template = @owner.nil? ? "default" : @owner.template |
29 | end | 21 | end |
30 | 22 | ||
23 | + before_filter :load_boxes | ||
24 | + #Load a set of boxes belongs to a owner. We have to situations. | ||
25 | + # 1 - The owner has equal or more boxes that boxes defined in template. | ||
26 | + # The system limit the max number of boxes to the number permited in template | ||
27 | + # 2 - The owner there isn't enough box that defined in template | ||
28 | + # The system create the boxes needed to use the current template | ||
29 | + def load_boxes | ||
30 | + raise _('Template not found') if @chosen_template.nil? | ||
31 | + n = boxes_by_template(@chosen_template) | ||
32 | + @boxes = Array.new | ||
33 | + if Profile.exists?(1) | ||
34 | + owner = Profile.find(1) | ||
35 | + @boxes = owner.boxes | ||
36 | + end | ||
37 | + | ||
38 | + if @boxes.length >= n | ||
39 | + @boxes = @boxes.first(n) | ||
40 | + else | ||
41 | + @boxes = @boxes | ||
42 | + end | ||
43 | + | ||
44 | + end | ||
45 | + | ||
46 | + def boxes_by_template(template) | ||
47 | + #f = YAML.load_file("#{TEMPLATE_DIR_PATH}/#{template}/#{template}.yml") | ||
48 | + f = YAML.load_file("#{RAILS_ROOT}/public/templates/default/default.yml") | ||
49 | + number_of_boxes = f[template.to_s]["number_of_boxes"] | ||
50 | + raise _("The file #{template}.yml it's not a valid template filename") if number_of_boxes.nil? | ||
51 | + number_of_boxes | ||
52 | + end | ||
53 | + | ||
54 | + | ||
31 | def set_default_template | 55 | def set_default_template |
32 | p = Profile.find(params[:object_id]) | 56 | p = Profile.find(params[:object_id]) |
33 | set_template(p,params[:template_name]) | 57 | set_template(p,params[:template_name]) |