diff --git a/app/controllers/enterprise_controller.rb b/app/controllers/enterprise_controller.rb index ce88662..28702ae 100644 --- a/app/controllers/enterprise_controller.rb +++ b/app/controllers/enterprise_controller.rb @@ -27,6 +27,7 @@ class EnterpriseController < ApplicationController def register @enterprise = Enterprise.new(params[:enterprise]) + @enterprise.organization_info = OrganizationInfo.new(params[:organization]) if @enterprise.save @enterprise.people << current_user.person flash[:notice] = _('Enterprise was succesfully created') @@ -51,6 +52,12 @@ class EnterpriseController < ApplicationController end end + def destroy + @enterprise = current_user.person.related_profiles.find(params[:id]) + @enterprise.destroy + redirect_to :action => 'index' + end + protected def logon diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e13d69b..1a46e1e 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -1,6 +1,3 @@ #An enterprise is a kind of profile. According to the system concept, only enterprises can offer products/services -class Enterprise < Profile - - validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true - +class Enterprise < Organization end diff --git a/app/models/organization.rb b/app/models/organization.rb new file mode 100644 index 0000000..e0f0f97 --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,3 @@ +class Organization < Profile + has_one :organization_info +end diff --git a/app/models/organization_info.rb b/app/models/organization_info.rb new file mode 100644 index 0000000..dcd4d8d --- /dev/null +++ b/app/models/organization_info.rb @@ -0,0 +1,5 @@ +class OrganizationInfo < ActiveRecord::Base + belongs_to :organization + + validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true +end diff --git a/app/views/enterprise/_enterprise.rhtml b/app/views/enterprise/_enterprise.rhtml index 9875423..9235801 100644 --- a/app/views/enterprise/_enterprise.rhtml +++ b/app/views/enterprise/_enterprise.rhtml @@ -1 +1,4 @@ -
<%= link_to _('Edit'), :action => 'edit', :id => enterprise %>
+<%= link_to _('Delete'), :action => 'destroy', :id => enterprise %>
+
-<%= text_field 'enterprise', 'contact_person', 'size' => 20 %>
-<%= text_field 'enterprise', 'acronym', 'size' => 20 %>
-<%= text_field 'enterprise', 'foundation_year', 'size' => 20 %>
-<%= text_field 'enterprise', 'legal_form', 'size' => 20 %>
-<%= text_field 'enterprise', 'economic_activity', 'size' => 20 %>
-<%= text_area 'enterprise', 'management_information', 'cols' => 40, 'rows' => 20 %>
<%= _('Identifier: ') %> <%= @enterprise.identifier %>
<%= _('Address: ') %> <%= @enterprise.address %>
<%= _('Contact phone: ') %> <%= @enterprise.contact_phone %>
-<%= _('Contact person: ') %> <%= @enterprise.contact_person %>
-<%= _('Acronym: ') %> <%= @enterprise.acronym %>
-<%= _('Foundation year: ') %> <%= @enterprise.foundation_year %>
-<%= _('Legal Form: ') %> <%= @enterprise.legal_form %>
-<%= _('Economic activity: ') %> <%= @enterprise.economic_activity %>
-<%= _('Management infomation: ') %> <%= @enterprise.management_information %>
+<%= _('Contact person: ') %> <%= @enterprise.organization_info.contact_person %>
+<%= _('Acronym: ') %> <%= @enterprise.organization_info.acronym %>
+<%= _('Foundation year: ') %> <%= @enterprise.organization_info.foundation_year %>
+<%= _('Legal Form: ') %> <%= @enterprise.organization_info.legal_form %>
+<%= _('Economic activity: ') %> <%= @enterprise.organization_info.economic_activity %>
+<%= _('Management infomation: ') %> <%= @enterprise.organization_info.management_information %>
<%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %>
+<%= link_to _('Delete enterprise'), :action => 'destroy', :id => @enterprise %>
<%= link_to _('Register new enterprise'), :action => 'register_form' %>
diff --git a/db/migrate/003_create_profiles.rb b/db/migrate/003_create_profiles.rb index e6019dc..0c88063 100644 --- a/db/migrate/003_create_profiles.rb +++ b/db/migrate/003_create_profiles.rb @@ -9,20 +9,11 @@ class CreateProfiles < ActiveRecord::Migration t.column :flexible_template_theme, :string, :default => "default" t.column :flexible_template_icon_theme, :string, :default => "default" t.column :active, :boolean, :default => false - + t.column :address, :string + t.column :contact_phone, :string + #person fields t.column :user_id, :integer - - #enterprise fields - t.column :address, :string - t.column :contact_phone, :string - t.column :contact_person, :string - t.column :acronym, :string - t.column :foundation_year, :integer, :limit => 4 - t.column :legal_form, :string - t.column :economic_activity, :string - t.column :management_information, :string - end end diff --git a/db/migrate/009_create_organizations.rb b/db/migrate/009_create_organizations.rb new file mode 100644 index 0000000..1a3f2fc --- /dev/null +++ b/db/migrate/009_create_organizations.rb @@ -0,0 +1,10 @@ +class CreateOrganizations < ActiveRecord::Migration + def self.up + create_table :organizations do |t| + end + end + + def self.down + drop_table :organizations + end +end diff --git a/db/migrate/010_create_organization_infos.rb b/db/migrate/010_create_organization_infos.rb new file mode 100644 index 0000000..8ffe65f --- /dev/null +++ b/db/migrate/010_create_organization_infos.rb @@ -0,0 +1,17 @@ +class CreateOrganizationInfos < ActiveRecord::Migration + def self.up + create_table :organization_infos do |t| + t.column :organization_id, :integer + t.column :contact_person, :string + t.column :acronym, :string + t.column :foundation_year, :integer, :limit => 4 + t.column :legal_form, :string + t.column :economic_activity, :string + t.column :management_information, :string + end + end + + def self.down + drop_table :organization_infos + end +end diff --git a/test/fixtures/organization_infos.yml b/test/fixtures/organization_infos.yml new file mode 100644 index 0000000..b49c4eb --- /dev/null +++ b/test/fixtures/organization_infos.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 +two: + id: 2 diff --git a/test/fixtures/organizations.yml b/test/fixtures/organizations.yml new file mode 100644 index 0000000..b49c4eb --- /dev/null +++ b/test/fixtures/organizations.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 +two: + id: 2 diff --git a/test/unit/organization_info_test.rb b/test/unit/organization_info_test.rb new file mode 100644 index 0000000..92cf899 --- /dev/null +++ b/test/unit/organization_info_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class OrganizationInfoTest < Test::Unit::TestCase + fixtures :organization_infos + + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb new file mode 100644 index 0000000..a728ec8 --- /dev/null +++ b/test/unit/organization_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class OrganizationTest < Test::Unit::TestCase + fixtures :organizations + + # Replace this with your real tests. + def test_truth + assert true + end +end -- libgit2 0.21.2