Commit 8fb1619b641c5238360cf356a6ed7e84e6e5e34b

Authored by MoisesMachado
1 parent 788a858c

ActionItem6: added actions to vis

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@301 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 # available in all controllers. 2 # available in all controllers.
3 class ApplicationController < ActionController::Base 3 class ApplicationController < ActionController::Base
4 4
  5 +# helper :all
  6 +
5 design :holder => 'virtual_community' 7 design :holder => 'virtual_community'
6 8
7 # Be sure to include AuthenticationSystem in Application Controller instead 9 # Be sure to include AuthenticationSystem in Application Controller instead
app/controllers/enterprise_controller.rb
@@ -4,8 +4,20 @@ class EnterpriseController &lt; ApplicationController @@ -4,8 +4,20 @@ class EnterpriseController &lt; ApplicationController
4 before_filter :logon, :my_enterprises 4 before_filter :logon, :my_enterprises
5 5
6 def index 6 def index
  7 + if @my_enterprises.size == 1
  8 + redirect_to :action => 'show', :id => @my_enterprises[0]
  9 + else
  10 + redirect_to :action => 'list'
  11 + end
  12 + end
  13 +
  14 + def list
7 @enterprises = Enterprise.find(:all) - @my_enterprises 15 @enterprises = Enterprise.find(:all) - @my_enterprises
8 - @pending_enterprises = current_user.person.my_enterprises(false) 16 + @pending_enterprises = current_user.person.pending_enterprises(false)
  17 + end
  18 +
  19 + def show
  20 + @enterprise = current_user.person.related_profiles.find(params[:id])
9 end 21 end
10 22
11 def register_form 23 def register_form
@@ -15,7 +27,6 @@ class EnterpriseController &lt; ApplicationController @@ -15,7 +27,6 @@ class EnterpriseController &lt; ApplicationController
15 27
16 def register 28 def register
17 @enterprise = Enterprise.new(params[:enterprise]) 29 @enterprise = Enterprise.new(params[:enterprise])
18 - @enterprise.identifier = @enterprise.name  
19 if @enterprise.save 30 if @enterprise.save
20 @enterprise.people << current_user.person 31 @enterprise.people << current_user.person
21 flash[:notice] = _('Enterprise was succesfully created') 32 flash[:notice] = _('Enterprise was succesfully created')
@@ -26,10 +37,20 @@ class EnterpriseController &lt; ApplicationController @@ -26,10 +37,20 @@ class EnterpriseController &lt; ApplicationController
26 end 37 end
27 end 38 end
28 39
29 - def show  
30 - @enterprise = @my_enterprises.find{|e| e.id == params[:id]} 40 + def edit
  41 + @enterprise = current_user.person.related_profiles.find(params[:id])
31 end 42 end
32 - 43 +
  44 + def update
  45 + @enterprise = current_user.person.related_profiles.find(params[:id])
  46 + if @enterprise.update_attributes(params[:enterprise])
  47 + redirect_to :action => 'index'
  48 + else
  49 + flash[:notice] = _('Could not update the enterprise')
  50 + render :action => 'edit'
  51 + end
  52 + end
  53 +
33 protected 54 protected
34 55
35 def logon 56 def logon
@@ -37,6 +58,6 @@ class EnterpriseController &lt; ApplicationController @@ -37,6 +58,6 @@ class EnterpriseController &lt; ApplicationController
37 end 58 end
38 59
39 def my_enterprises 60 def my_enterprises
40 - @my_enterprises = current_user.person.my_enterprises 61 + @my_enterprises = current_user.person.enterprises
41 end 62 end
42 end 63 end
app/models/enterprise.rb
1 -#A enterprise is a kind of profile. According to the system concept, only enterprises can offer products/services 1 +#An enterprise is a kind of profile. According to the system concept, only enterprises can offer products/services
2 class Enterprise < Profile 2 class Enterprise < Profile
3 3
4 validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true 4 validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true
app/models/person.rb
@@ -3,13 +3,13 @@ class Person &lt; Profile @@ -3,13 +3,13 @@ class Person &lt; Profile
3 has_many :personal_affiliations, :class_name => 'Affiliation' 3 has_many :personal_affiliations, :class_name => 'Affiliation'
4 has_many :related_profiles, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile' 4 has_many :related_profiles, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile'
5 5
  6 + has_many :enterprises, :class_name => 'Enterprise', :through => :personal_affiliations, :source => 'profile', :conditions => ['active = ?', true]
  7 +
  8 + has_many :pending_enterprises, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile', :conditions => ['type = ? and active = ?', 'Enterprise', false]
  9 +
6 has_many :friendships 10 has_many :friendships
7 has_many :friends, :class_name => 'Person', :through => :friendships 11 has_many :friends, :class_name => 'Person', :through => :friendships
8 12
9 has_many :other_friendships 13 has_many :other_friendships
10 has_many :other_friend, :class_name => 'Person', :through => :other_friendships, :foreign_key => 'friend_id' 14 has_many :other_friend, :class_name => 'Person', :through => :other_friendships, :foreign_key => 'friend_id'
11 -  
12 - def my_enterprises(status = true)  
13 - related_profiles.find(:all, :conditions => ['type = ? and active = ?', 'Enterprise', status])  
14 - end  
15 end 15 end
app/views/enterprise/_enterprise.rhtml
1 -<li> <%= link_to enterprise.name %> </li> 1 +<li> <%= link_to enterprise.name, :action => 'show', :id => enterprise %> </li>
app/views/enterprise/edit.rhtml 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +<%= error_messages_for 'enterprise' %>
  2 +
  3 +<h2><%= _('Edit enterprise informations') %></h2>
  4 +
  5 +<% form_tag :action => 'update', :id => @enterprise do %>
  6 + <%= render :partial => 'form' %>
  7 +<p><%= submit_tag _('Register') %>
  8 +<%= link_to _('Cancel'), :action => 'index' %></p>
  9 +<% end %>
app/views/enterprise/index.rhtml
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
1 -<p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> </p>  
2 -<h2> <%= _('Listing my enterprises') %> </h2>  
3 -<ul>  
4 - <%= render :partial => 'enterprise', :collection => @my_enterprises %>  
5 -</ul>  
6 -  
7 -<% unless @pending_enterprises.blank? %>  
8 - <h2> <%= _('Listing pending enterprises') %> </h2>  
9 - <ul>  
10 - <%= render :partial => 'enterprise', :collection => @pending_enterprises %>  
11 - </ul>  
12 -<% end %>  
app/views/enterprise/list.rhtml 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +<p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> </p>
  2 +<h2> <%= _('Listing my enterprises') %> </h2>
  3 +<ul>
  4 + <%= render :partial => 'enterprise', :collection => @my_enterprises %>
  5 +</ul>
  6 +
  7 +<% unless @pending_enterprises.blank? %>
  8 + <h2> <%= _('Listing pending enterprises') %> </h2>
  9 + <ul>
  10 + <%= render :partial => 'enterprise', :collection => @pending_enterprises %>
  11 + </ul>
  12 +<% end %>
app/views/enterprise/register_form.rhtml
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 <h2><%= _('Register enterprise') %></h2> 3 <h2><%= _('Register enterprise') %></h2>
4 4
5 <% form_tag :action => 'register' do %> 5 <% form_tag :action => 'register' do %>
  6 + <p><label for="identifier"><%= _('Identifier') %></label><br/>
  7 + <%= text_field 'enterprise', 'identifier', 'size' => 20 %></p>
6 <%= render :partial => 'form' %> 8 <%= render :partial => 'form' %>
7 <p><%= submit_tag _('Register') %> 9 <p><%= submit_tag _('Register') %>
8 <%= link_to _('Cancel'), :action => 'index' %></p> 10 <%= link_to _('Cancel'), :action => 'index' %></p>
app/views/enterprise/show.rhtml 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +<h3> <%= @enterprise.name %> </h3>
  2 +
  3 +<p> <%= _('Identifier: ') %> <%= @enterprise.identifier %> </p>
  4 +<p> <%= _('Address: ') %> <%= @enterprise.address %> </p>
  5 +<p> <%= _('Contact phone: ') %> <%= @enterprise.contact_phone %> </p>
  6 +<p> <%= _('Contact person: ') %> <%= @enterprise.contact_person %> </p>
  7 +<p> <%= _('Acronym: ') %> <%= @enterprise.acronym %> </p>
  8 +<p> <%= _('Foundation year: ') %> <%= @enterprise.foundation_year %> </p>
  9 +<p> <%= _('Legal Form: ') %> <%= @enterprise.legal_form %> </p>
  10 +<p> <%= _('Economic activity: ') %> <%= @enterprise.economic_activity %> </p>
  11 +<p> <%= _('Management infomation: ') %> <%= @enterprise.management_information %> </p>
  12 +
  13 +<p> <%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %> </p>
  14 +<p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> </p>