diff --git a/app/controllers/admin/edit_template_controller.rb b/app/controllers/admin/edit_template_controller.rb index bcb5f6d..f130b10 100644 --- a/app/controllers/admin/edit_template_controller.rb +++ b/app/controllers/admin/edit_template_controller.rb @@ -4,7 +4,8 @@ class EditTemplateController < AdminController def block_types %w[ - FavoriteLinksProfile + FavoriteLinks + ListBlock ] end diff --git a/app/controllers/application.rb b/app/controllers/application.rb index f71ff90..35d20d4 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -42,7 +42,8 @@ class ApplicationController < ActionController::Base def render_not_found(path = nil) @path ||= request.path - render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404) && false + raise "#{@path} not found" +# render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404) && false end def load_admin_controller diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 54719be..88961e2 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -11,7 +11,7 @@ class ProfileEditorController < MyProfileController %w[ FavoriteLinksProfile ListBlock - EnterprisesBlock + ProfileInfoBlock ] end diff --git a/app/design_blocks/enterprises_block/controllers/enterprises_block_controller.rb b/app/design_blocks/enterprises_block/controllers/enterprises_block_controller.rb deleted file mode 100644 index e3b24fc..0000000 --- a/app/design_blocks/enterprises_block/controllers/enterprises_block_controller.rb +++ /dev/null @@ -1,51 +0,0 @@ -class EnterprisesBlockController < ApplicationController - - # This controller always has the object @design_block available to it. - # The method acts_as_design_block load a before_filter that always load - # this object. - - needs_profile - - acts_as_design_block - - # You must have a hash on format: - # { - # 'action name' => 'How the action will be displayed on menu' - # } - # - # EX: - # CONTROL_ACTION_OPTIONS = { - # 'design_edit' => _('Edit'), - # 'manage_links' => _('Manage Links') - # } - # - # This hash will define the options menu on edit mode. - CONTROL_ACTION_OPTIONS = { -# 'edit' => _('Edit') - } - - - ########################### - # Mandatory methods - ########################### - - def index - @enterprises = Enterprise.find(:all) - design_render - end - - ########################### - # Other Sample of methods - ########################### - -# def edit -# design_render_on_edit -# end - -# def save -# @design_block.update_attributes(params[:design_block]) -# design_render_on_edit :nothing => true -# end - - -end diff --git a/app/design_blocks/enterprises_block/helpers/enterprises_block_helper.rb b/app/design_blocks/enterprises_block/helpers/enterprises_block_helper.rb deleted file mode 100644 index cc629c1..0000000 --- a/app/design_blocks/enterprises_block/helpers/enterprises_block_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -module EnterprisesBlockHelper - -end diff --git a/app/design_blocks/enterprises_block/helpers/list_block_helper.rb b/app/design_blocks/enterprises_block/helpers/list_block_helper.rb deleted file mode 100644 index 6887d0f..0000000 --- a/app/design_blocks/enterprises_block/helpers/list_block_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -module ListBlockHelper - -end diff --git a/app/design_blocks/enterprises_block/models/enterprises_block.rb b/app/design_blocks/enterprises_block/models/enterprises_block.rb deleted file mode 100644 index 0f1b321..0000000 --- a/app/design_blocks/enterprises_block/models/enterprises_block.rb +++ /dev/null @@ -1,15 +0,0 @@ -class EnterprisesBlock < Design::Block - - # Define an specific method using the settings hash serialized - # variable to keep the value desired by method. - # - # EX: - # def max_number_of_element= value - # self.settings[:limit_number] = value - # end - - def self.description - _('Enterprises Block') - end - -end diff --git a/app/design_blocks/enterprises_block/views/index.rhtml b/app/design_blocks/enterprises_block/views/index.rhtml deleted file mode 100644 index b147bb0..0000000 --- a/app/design_blocks/enterprises_block/views/index.rhtml +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/app/design_blocks/list_block/controllers/list_block_controller.rb b/app/design_blocks/list_block/controllers/list_block_controller.rb index 75b8704..1f83b3a 100644 --- a/app/design_blocks/list_block/controllers/list_block_controller.rb +++ b/app/design_blocks/list_block/controllers/list_block_controller.rb @@ -5,7 +5,7 @@ class ListBlockController < ApplicationController # this object. needs_profile - + acts_as_design_block # You must have a hash on format: @@ -30,8 +30,8 @@ class ListBlockController < ApplicationController ########################### def index - @people = @design_block.people - design_render + @elements = @design_block.elements + design_render :action => @design_block.view end ########################### @@ -40,6 +40,7 @@ class ListBlockController < ApplicationController def edit + @elements_types = @design_block.elements_types design_render_on_edit :controller => 'list_block', :action => 'edit' end diff --git a/app/design_blocks/list_block/models/list_block.rb b/app/design_blocks/list_block/models/list_block.rb index f37258c..20e47f8 100644 --- a/app/design_blocks/list_block/models/list_block.rb +++ b/app/design_blocks/list_block/models/list_block.rb @@ -20,8 +20,26 @@ class ListBlock < Design::Block self.settings[:limit_number] end - def people - Person.find(:all, :limit => limit_number) + def elements_types + ['Person', 'Enterprise'] + end + + def element_type + self.settings[:element_type] + end + + def element_type= value + return nil unless elements_types.include?(value) + self.settings[:element_type] = value + end + + def elements + return nil unless element_type + self.element_type.constantize.find(:all, :limit => limit_number) + end + + def view + element_type.to_s.underscore end end diff --git a/app/design_blocks/list_block/views/edit.rhtml b/app/design_blocks/list_block/views/edit.rhtml index 2dda4db..f113014 100644 --- a/app/design_blocks/list_block/views/edit.rhtml +++ b/app/design_blocks/list_block/views/edit.rhtml @@ -4,10 +4,15 @@

<%= text_field 'design_block', 'title'%> +

+ +

+ + <%= select 'design_block', 'element_type', @elements_types %>

- + <%= text_field 'design_block', 'limit_number'%>

diff --git a/app/design_blocks/list_block/views/enterprise.rhtml b/app/design_blocks/list_block/views/enterprise.rhtml new file mode 100644 index 0000000..eed5b71 --- /dev/null +++ b/app/design_blocks/list_block/views/enterprise.rhtml @@ -0,0 +1,5 @@ + diff --git a/app/design_blocks/list_block/views/index.rhtml b/app/design_blocks/list_block/views/index.rhtml deleted file mode 100644 index aef8595..0000000 --- a/app/design_blocks/list_block/views/index.rhtml +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/app/design_blocks/list_block/views/person.rhtml b/app/design_blocks/list_block/views/person.rhtml new file mode 100644 index 0000000..f6be13d --- /dev/null +++ b/app/design_blocks/list_block/views/person.rhtml @@ -0,0 +1,5 @@ + diff --git a/app/design_blocks/profile_info_block/controllers/profile_info_block_controller.rb b/app/design_blocks/profile_info_block/controllers/profile_info_block_controller.rb new file mode 100644 index 0000000..d35fddc --- /dev/null +++ b/app/design_blocks/profile_info_block/controllers/profile_info_block_controller.rb @@ -0,0 +1,51 @@ +class ProfileInfoBlockController < ApplicationController + + # This controller always has the object @design_block available to it. + # The method acts_as_design_block load a before_filter that always load + # this object. + + needs_profile + + acts_as_design_block + + # You must have a hash on format: + # { + # 'action name' => 'How the action will be displayed on menu' + # } + # + # EX: + # CONTROL_ACTION_OPTIONS = { + # 'design_edit' => _('Edit'), + # 'manage_links' => _('Manage Links') + # } + # + # This hash will define the options menu on edit mode. + CONTROL_ACTION_OPTIONS = { +# 'edit' => _('Edit') + } + + + ########################### + # Mandatory methods + ########################### + + def index + @info = @profile.info + design_render + end + + ########################### + # Other Sample of methods + ########################### + + def edit + design_render_on_edit + end + + def save + @design_block.update_attributes(params[:design_block]) + design_render_on_edit :nothing => true + end + + +end diff --git a/app/design_blocks/profile_info_block/helpers/profile_info_block_helper.rb b/app/design_blocks/profile_info_block/helpers/profile_info_block_helper.rb new file mode 100644 index 0000000..9d0344f --- /dev/null +++ b/app/design_blocks/profile_info_block/helpers/profile_info_block_helper.rb @@ -0,0 +1,3 @@ +module ProfileInfoBlockHelper + +end diff --git a/app/design_blocks/profile_info_block/models/profile_info_block.rb b/app/design_blocks/profile_info_block/models/profile_info_block.rb new file mode 100644 index 0000000..50f9737 --- /dev/null +++ b/app/design_blocks/profile_info_block/models/profile_info_block.rb @@ -0,0 +1,15 @@ +class ProfileInfoBlock < Design::Block + + # Define an specific method using the settings hash serialized + # variable to keep the value desired by method. + # + # EX: + # def max_number_of_element= value + # self.settings[:limit_number] = value + # end + + def self.description + 'ProfileInfoBlock' + end + +end diff --git a/app/design_blocks/profile_info_block/views/index.rhtml b/app/design_blocks/profile_info_block/views/index.rhtml new file mode 100644 index 0000000..3ec0b96 --- /dev/null +++ b/app/design_blocks/profile_info_block/views/index.rhtml @@ -0,0 +1,3 @@ +<%= image_tag @profile.image.public_filename(:thumb) if @profile.image %>
+<%= @profile.name %>
+<%= n_('1 years', '%{num} years', @info.age) % {:num => @info.age} %>
diff --git a/app/models/person_info.rb b/app/models/person_info.rb index b8dffd5..aefb611 100644 --- a/app/models/person_info.rb +++ b/app/models/person_info.rb @@ -1,15 +1,16 @@ class PersonInfo < ActiveRecord::Base - # FIXME: add file_column :photo - belongs_to :person def summary - [ - [ PersonInfo.columns_hash['name'].human_name, self.name ], - [ PersonInfo.columns_hash['address'].human_name, self.address ], - [ PersonInfo.columns_hash['contact_information'].human_name, self.contact_information ], - ] + ['name', 'sex', 'birth_date', 'address', 'city', 'state', 'country'].map do |col| + [ PersonInfo.columns_hash[col] && PersonInfo.columns_hash[col].human_name, self.send(col) ] + end + end + + def age + a = Date.today.year - birth_date.year + Date.today.yday > birth_date.yday ? a : a-1 end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 2e77dbf..75363bf 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -34,6 +34,7 @@ class Profile < ActiveRecord::Base not_found cat tag + environment ] belongs_to :user diff --git a/app/views/category/_product_category.rhtml b/app/views/category/_product_category.rhtml index 861465a..8c6ee8d 100644 --- a/app/views/category/_product_category.rhtml +++ b/app/views/category/_product_category.rhtml @@ -1,3 +1,4 @@ +<%= link_to(_('I consume this'), {:profile => current_user.login, :controller => 'consumed_products', :action => 'new', 'consumption[product_category_id]' => @category.id }, :method => :post) %>