Commit 8fb1619b641c5238360cf356a6ed7e84e6e5e34b
1 parent
788a858c
Exists in
master
and in
28 other branches
ActionItem6: added actions to vis
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@301 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
72 additions
and
24 deletions
Show diff stats
app/controllers/application.rb
app/controllers/enterprise_controller.rb
... | ... | @@ -4,8 +4,20 @@ class EnterpriseController < ApplicationController |
4 | 4 | before_filter :logon, :my_enterprises |
5 | 5 | |
6 | 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 | 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 | 21 | end |
10 | 22 | |
11 | 23 | def register_form |
... | ... | @@ -15,7 +27,6 @@ class EnterpriseController < ApplicationController |
15 | 27 | |
16 | 28 | def register |
17 | 29 | @enterprise = Enterprise.new(params[:enterprise]) |
18 | - @enterprise.identifier = @enterprise.name | |
19 | 30 | if @enterprise.save |
20 | 31 | @enterprise.people << current_user.person |
21 | 32 | flash[:notice] = _('Enterprise was succesfully created') |
... | ... | @@ -26,10 +37,20 @@ class EnterpriseController < ApplicationController |
26 | 37 | end |
27 | 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 | 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 | 54 | protected |
34 | 55 | |
35 | 56 | def logon |
... | ... | @@ -37,6 +58,6 @@ class EnterpriseController < ApplicationController |
37 | 58 | end |
38 | 59 | |
39 | 60 | def my_enterprises |
40 | - @my_enterprises = current_user.person.my_enterprises | |
61 | + @my_enterprises = current_user.person.enterprises | |
41 | 62 | end |
42 | 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 | 2 | class Enterprise < Profile |
3 | 3 | |
4 | 4 | validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true | ... | ... |
app/models/person.rb
... | ... | @@ -3,13 +3,13 @@ class Person < Profile |
3 | 3 | has_many :personal_affiliations, :class_name => 'Affiliation' |
4 | 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 | 10 | has_many :friendships |
7 | 11 | has_many :friends, :class_name => 'Person', :through => :friendships |
8 | 12 | |
9 | 13 | has_many :other_friendships |
10 | 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 | 15 | end | ... | ... |
app/views/enterprise/_enterprise.rhtml
... | ... | @@ -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 | -<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 %> |
... | ... | @@ -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 | 3 | <h2><%= _('Register enterprise') %></h2> |
4 | 4 | |
5 | 5 | <% form_tag :action => 'register' do %> |
6 | + <p><label for="identifier"><%= _('Identifier') %></label><br/> | |
7 | + <%= text_field 'enterprise', 'identifier', 'size' => 20 %></p> | |
6 | 8 | <%= render :partial => 'form' %> |
7 | 9 | <p><%= submit_tag _('Register') %> |
8 | 10 | <%= link_to _('Cancel'), :action => 'index' %></p> | ... | ... |
... | ... | @@ -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> | ... | ... |