Commit 9ede168f04418a60cc460635878908e7c5e24dbd

Authored by MoisesMachado
1 parent fdce3a03

ActionItem6: information of organization splited in two models: the organization…

… model that inherited from the profile and the organization_info holds the specific data for the organization


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@312 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/enterprise_controller.rb
... ... @@ -27,6 +27,7 @@ class EnterpriseController < ApplicationController
27 27  
28 28 def register
29 29 @enterprise = Enterprise.new(params[:enterprise])
  30 + @enterprise.organization_info = OrganizationInfo.new(params[:organization])
30 31 if @enterprise.save
31 32 @enterprise.people << current_user.person
32 33 flash[:notice] = _('Enterprise was succesfully created')
... ... @@ -51,6 +52,12 @@ class EnterpriseController &lt; ApplicationController
51 52 end
52 53 end
53 54  
  55 + def destroy
  56 + @enterprise = current_user.person.related_profiles.find(params[:id])
  57 + @enterprise.destroy
  58 + redirect_to :action => 'index'
  59 + end
  60 +
54 61 protected
55 62  
56 63 def logon
... ...
app/models/enterprise.rb
1 1 #An enterprise is a kind of profile. According to the system concept, only enterprises can offer products/services
2   -class Enterprise < Profile
3   -
4   - validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true
5   -
  2 +class Enterprise < Organization
6 3 end
... ...
app/models/organization.rb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +class Organization < Profile
  2 + has_one :organization_info
  3 +end
... ...
app/models/organization_info.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class OrganizationInfo < ActiveRecord::Base
  2 + belongs_to :organization
  3 +
  4 + validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true
  5 +end
... ...
app/views/enterprise/_enterprise.rhtml
1   -<li> <%= link_to enterprise.name, :action => 'show', :id => enterprise %> </li>
  1 +<li> <%= link_to enterprise.name, :action => 'show', :id => enterprise %>
  2 +<p> <%= link_to _('Edit'), :action => 'edit', :id => enterprise %> </p>
  3 +<p> <%= link_to _('Delete'), :action => 'destroy', :id => enterprise %> </p>
  4 +</li>
... ...
app/views/enterprise/_form.rhtml
... ... @@ -8,19 +8,19 @@
8 8 <%= text_field 'enterprise', 'contact_phone', 'size' => 20 %></p>
9 9  
10 10 <p><label for="contact_person"><%= _('Contact Person') %></label><br/>
11   -<%= text_field 'enterprise', 'contact_person', 'size' => 20 %></p>
  11 +<%= text_field 'organization_info', 'contact_person', 'size' => 20 %></p>
12 12  
13 13 <p><label for="acronym"><%= _('Acronym') %></label><br/>
14   -<%= text_field 'enterprise', 'acronym', 'size' => 20 %></p>
  14 +<%= text_field 'organization_info', 'acronym', 'size' => 20 %></p>
15 15  
16 16 <p><label for="foundation_year"><%= _('Foundation Year') %></label><br/>
17   -<%= text_field 'enterprise', 'foundation_year', 'size' => 20 %></p>
  17 +<%= text_field 'organization_info', 'foundation_year', 'size' => 20 %></p>
18 18  
19 19 <p><label for="legal_form"><%= _('Legal Form') %></label><br/>
20   -<%= text_field 'enterprise', 'legal_form', 'size' => 20 %></p>
  20 +<%= text_field 'organization_info', 'legal_form', 'size' => 20 %></p>
21 21  
22 22 <p><label for="economic_activity"><%= _('Economic Activity') %></label><br/>
23   -<%= text_field 'enterprise', 'economic_activity', 'size' => 20 %></p>
  23 +<%= text_field 'organization_info', 'economic_activity', 'size' => 20 %></p>
24 24  
25 25 <p><label for="management_information"><%= _('Management Information') %></label><br/>
26   -<%= text_area 'enterprise', 'management_information', 'cols' => 40, 'rows' => 20 %></p>
  26 +<%= text_area 'organization_info', 'management_information', 'cols' => 40, 'rows' => 20 %></p>
... ...
app/views/enterprise/show.rhtml
... ... @@ -3,12 +3,13 @@
3 3 <p> <%= _('Identifier: ') %> <%= @enterprise.identifier %> </p>
4 4 <p> <%= _('Address: ') %> <%= @enterprise.address %> </p>
5 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>
  6 +<p> <%= _('Contact person: ') %> <%= @enterprise.organization_info.contact_person %> </p>
  7 +<p> <%= _('Acronym: ') %> <%= @enterprise.organization_info.acronym %> </p>
  8 +<p> <%= _('Foundation year: ') %> <%= @enterprise.organization_info.foundation_year %> </p>
  9 +<p> <%= _('Legal Form: ') %> <%= @enterprise.organization_info.legal_form %> </p>
  10 +<p> <%= _('Economic activity: ') %> <%= @enterprise.organization_info.economic_activity %> </p>
  11 +<p> <%= _('Management infomation: ') %> <%= @enterprise.organization_info.management_information %> </p>
12 12  
13 13 <p> <%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %> </p>
  14 +<p> <%= link_to _('Delete enterprise'), :action => 'destroy', :id => @enterprise %> </p>
14 15 <p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> </p>
... ...
db/migrate/003_create_profiles.rb
... ... @@ -9,20 +9,11 @@ class CreateProfiles &lt; ActiveRecord::Migration
9 9 t.column :flexible_template_theme, :string, :default => "default"
10 10 t.column :flexible_template_icon_theme, :string, :default => "default"
11 11 t.column :active, :boolean, :default => false
12   -
  12 + t.column :address, :string
  13 + t.column :contact_phone, :string
  14 +
13 15 #person fields
14 16 t.column :user_id, :integer
15   -
16   - #enterprise fields
17   - t.column :address, :string
18   - t.column :contact_phone, :string
19   - t.column :contact_person, :string
20   - t.column :acronym, :string
21   - t.column :foundation_year, :integer, :limit => 4
22   - t.column :legal_form, :string
23   - t.column :economic_activity, :string
24   - t.column :management_information, :string
25   -
26 17 end
27 18 end
28 19  
... ...
db/migrate/009_create_organizations.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class CreateOrganizations < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :organizations do |t|
  4 + end
  5 + end
  6 +
  7 + def self.down
  8 + drop_table :organizations
  9 + end
  10 +end
... ...
db/migrate/010_create_organization_infos.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class CreateOrganizationInfos < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :organization_infos do |t|
  4 + t.column :organization_id, :integer
  5 + t.column :contact_person, :string
  6 + t.column :acronym, :string
  7 + t.column :foundation_year, :integer, :limit => 4
  8 + t.column :legal_form, :string
  9 + t.column :economic_activity, :string
  10 + t.column :management_information, :string
  11 + end
  12 + end
  13 +
  14 + def self.down
  15 + drop_table :organization_infos
  16 + end
  17 +end
... ...
test/fixtures/organization_infos.yml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
  2 +one:
  3 + id: 1
  4 +two:
  5 + id: 2
... ...
test/fixtures/organizations.yml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
  2 +one:
  3 + id: 1
  4 +two:
  5 + id: 2
... ...
test/unit/organization_info_test.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class OrganizationInfoTest < Test::Unit::TestCase
  4 + fixtures :organization_infos
  5 +
  6 + # Replace this with your real tests.
  7 + def test_truth
  8 + assert true
  9 + end
  10 +end
... ...
test/unit/organization_test.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class OrganizationTest < Test::Unit::TestCase
  4 + fixtures :organizations
  5 +
  6 + # Replace this with your real tests.
  7 + def test_truth
  8 + assert true
  9 + end
  10 +end
... ...