Commit f1a174eaa6ab36330baf012140201962cc4c8461

Authored by MoisesMachado
1 parent fcffa9a4

ActionItem135: created view article block


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1084 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
... ... @@ -42,8 +42,8 @@ class ApplicationController < ActionController::Base
42 42  
43 43 def render_not_found(path = nil)
44 44 @path ||= request.path
45   - raise "#{@path} not found"
46   -# render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404) && false
  45 +# raise "#{@path} not found"
  46 + render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404) && false
47 47 end
48 48  
49 49 def load_admin_controller
... ...
app/design_blocks/profile_info_block/controllers/profile_info_block_controller.rb
... ... @@ -31,6 +31,7 @@ class ProfileInfoBlockController < ApplicationController
31 31  
32 32 def index
33 33 @info = @profile.info
  34 + @can_edit = current_user.person.has_permission?('edit_profile', @profile)
34 35 design_render
35 36 end
36 37  
... ...
app/design_blocks/profile_info_block/views/index.rhtml
1 1 <%= image_tag @profile.image.public_filename(:thumb) if @profile.image %> <br>
2   -<%= @profile.name %><br>
3   -<%= n_('1 years', '%{num} years', @info.age) % {:num => @info.age} %><br>
  2 +<%= link_to_myprofile(_('Change photo'), {:action => 'change_image'}, @profile.identifier ) %><br>
  3 +<%= _('User since %d') % @profile.created_at.year if @profile.created_at %><br>
  4 +<%= @info.name ? @info.name : @profile.name if @profile.name %><br>
  5 +<%= n_('1 year', '%{num} years', @info.age) % {:num => @info.age} if @info.birth_date%><br>
  6 +
... ...
app/design_blocks/view_article/controllers/view_article_controller.rb 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +class ViewArticleController < ApplicationController
  2 +
  3 + # This controller always has the object @design_block available to it.
  4 + # The method acts_as_design_block load a before_filter that always load
  5 + # this object.
  6 +
  7 + needs_profile
  8 +
  9 + acts_as_design_block
  10 +
  11 + # You must have a hash on format:
  12 + # {
  13 + # 'action name' => 'How the action will be displayed on menu'
  14 + # }
  15 + #
  16 + # EX:
  17 + # CONTROL_ACTION_OPTIONS = {
  18 + # 'design_edit' => _('Edit'),
  19 + # 'manage_links' => _('Manage Links')
  20 + # }
  21 + #
  22 + # This hash will define the options menu on edit mode.
  23 + CONTROL_ACTION_OPTIONS = {
  24 + 'edit' => _('Edit')
  25 + }
  26 +
  27 +
  28 + ###########################
  29 + # Mandatory methods
  30 + ###########################
  31 +
  32 + def index
  33 + design_render
  34 + end
  35 +
  36 + ###########################
  37 + # Other Sample of methods
  38 + ###########################
  39 +
  40 + def edit
  41 + design_render_on_edit
  42 + end
  43 +
  44 + def save
  45 + @design_block.update_attributes(params[:design_block])
  46 + design_render_on_edit :nothing => true
  47 + end
  48 +
  49 +
  50 +end
... ...
app/design_blocks/view_article/helpers/view_article_helper.rb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +module ViewArticleHelper
  2 +
  3 +end
... ...
app/design_blocks/view_article/models/view_article.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +class ViewArticle < Design::Block
  2 +
  3 + # Define an specific method using the settings hash serialized
  4 + # variable to keep the value desired by method.
  5 + #
  6 + # EX:
  7 + # def max_number_of_element= value
  8 + # self.settings[:limit_number] = value
  9 + # end
  10 +
  11 + def self.description
  12 + 'ViewArticle'
  13 + end
  14 +
  15 + def page
  16 + self.settings[:page]
  17 + end
  18 +
  19 + def page= value
  20 + self.settings[:page] = value
  21 + end
  22 +
  23 + def profile
  24 + self.settings[:page]
  25 + end
  26 +
  27 + def profile= value
  28 + self.settings[:page] = value
  29 + end
  30 +
  31 +end
... ...
app/design_blocks/view_article/views/edit.rhtml 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<h2> <%= _('Editing article shown') %> </h2>
  2 +
  3 +<% design_form_remote_tag( :url => {:action => 'save'}) do %>
  4 + <p>
  5 + <label for="design_block_title"> <%= _("Title") %> </label>
  6 + <%= text_field 'design_block', 'title'%>
  7 + </p>
  8 +
  9 + <p>
  10 + <label for="design_block_page"> <%= _("Page to show") %> </label>
  11 + <%= text_field 'design_block', 'page'%>
  12 + </p>
  13 +
  14 + <%= submit_tag _('Save') %>
  15 +<% end %>
... ...
app/design_blocks/view_article/views/index.rhtml 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render_component(:controller => 'content_viewer', :action => 'view_page', :params => {:profile => @profile.identifier, :page => [@design_block.page], :no_layout => true}) %>
... ...
app/models/person_info.rb
... ... @@ -10,7 +10,7 @@ class PersonInfo &lt; ActiveRecord::Base
10 10  
11 11 def age
12 12 a = Date.today.year - birth_date.year
13   - Date.today.yday > birth_date.yday ? a : a-1
  13 + Date.today.yday >= birth_date.yday ? a : a-1
14 14 end
15 15  
16 16 end
... ...
app/views/profile_editor/change_image.rhtml
1   -<% form_for :image, @image, :html => { :multipart => true }, :url => { :action => 'change_image'} do |f| %>
  1 +<% form_for :image, @image, :html => { :multipart => true }, :url => { :action => 'edit_image_preview'} do |f| %>
2 2 <%= display_form_field(_('Image'), f.file_field( :uploaded_data ) ) %>
3 3 <%= display_submit_tag(_('Upload')) %>
4 4 <%= link_to _('Cancel'), :action => 'index' %>
... ...
db/migrate/003_create_profiles.rb
... ... @@ -19,6 +19,7 @@ class CreateProfiles &lt; ActiveRecord::Migration
19 19 #enterprise fields
20 20 t.column :region_id, :integer
21 21  
  22 + t.column :created_at, :datetime
22 23 end
23 24 end
24 25  
... ...