From 8fb1619b641c5238360cf356a6ed7e84e6e5e34b Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 1 Aug 2007 17:37:38 +0000 Subject: [PATCH] ActionItem6: added actions to vis --- app/controllers/application.rb | 2 ++ app/controllers/enterprise_controller.rb | 33 +++++++++++++++++++++++++++------ app/models/enterprise.rb | 2 +- app/models/person.rb | 8 ++++---- app/views/enterprise/_enterprise.rhtml | 2 +- app/views/enterprise/edit.rhtml | 9 +++++++++ app/views/enterprise/index.rhtml | 12 ------------ app/views/enterprise/list.rhtml | 12 ++++++++++++ app/views/enterprise/register_form.rhtml | 2 ++ app/views/enterprise/show.rhtml | 14 ++++++++++++++ 10 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 app/views/enterprise/edit.rhtml delete mode 100644 app/views/enterprise/index.rhtml create mode 100644 app/views/enterprise/list.rhtml create mode 100644 app/views/enterprise/show.rhtml diff --git a/app/controllers/application.rb b/app/controllers/application.rb index ca530a5..f76c4fe 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -2,6 +2,8 @@ # available in all controllers. class ApplicationController < ActionController::Base +# helper :all + design :holder => 'virtual_community' # Be sure to include AuthenticationSystem in Application Controller instead diff --git a/app/controllers/enterprise_controller.rb b/app/controllers/enterprise_controller.rb index 878ce98..ce88662 100644 --- a/app/controllers/enterprise_controller.rb +++ b/app/controllers/enterprise_controller.rb @@ -4,8 +4,20 @@ class EnterpriseController < ApplicationController before_filter :logon, :my_enterprises def index + if @my_enterprises.size == 1 + redirect_to :action => 'show', :id => @my_enterprises[0] + else + redirect_to :action => 'list' + end + end + + def list @enterprises = Enterprise.find(:all) - @my_enterprises - @pending_enterprises = current_user.person.my_enterprises(false) + @pending_enterprises = current_user.person.pending_enterprises(false) + end + + def show + @enterprise = current_user.person.related_profiles.find(params[:id]) end def register_form @@ -15,7 +27,6 @@ class EnterpriseController < ApplicationController def register @enterprise = Enterprise.new(params[:enterprise]) - @enterprise.identifier = @enterprise.name if @enterprise.save @enterprise.people << current_user.person flash[:notice] = _('Enterprise was succesfully created') @@ -26,10 +37,20 @@ class EnterpriseController < ApplicationController end end - def show - @enterprise = @my_enterprises.find{|e| e.id == params[:id]} + def edit + @enterprise = current_user.person.related_profiles.find(params[:id]) end - + + def update + @enterprise = current_user.person.related_profiles.find(params[:id]) + if @enterprise.update_attributes(params[:enterprise]) + redirect_to :action => 'index' + else + flash[:notice] = _('Could not update the enterprise') + render :action => 'edit' + end + end + protected def logon @@ -37,6 +58,6 @@ class EnterpriseController < ApplicationController end def my_enterprises - @my_enterprises = current_user.person.my_enterprises + @my_enterprises = current_user.person.enterprises end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a8657bb..e13d69b 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -1,4 +1,4 @@ -#A enterprise is a kind of profile. According to the system concept, only enterprises can offer products/services +#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 diff --git a/app/models/person.rb b/app/models/person.rb index dde7c9d..1e9fad3 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -3,13 +3,13 @@ class Person < Profile has_many :personal_affiliations, :class_name => 'Affiliation' has_many :related_profiles, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile' + has_many :enterprises, :class_name => 'Enterprise', :through => :personal_affiliations, :source => 'profile', :conditions => ['active = ?', true] + + has_many :pending_enterprises, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile', :conditions => ['type = ? and active = ?', 'Enterprise', false] + has_many :friendships has_many :friends, :class_name => 'Person', :through => :friendships has_many :other_friendships has_many :other_friend, :class_name => 'Person', :through => :other_friendships, :foreign_key => 'friend_id' - - def my_enterprises(status = true) - related_profiles.find(:all, :conditions => ['type = ? and active = ?', 'Enterprise', status]) - end end diff --git a/app/views/enterprise/_enterprise.rhtml b/app/views/enterprise/_enterprise.rhtml index cfea5a2..9875423 100644 --- a/app/views/enterprise/_enterprise.rhtml +++ b/app/views/enterprise/_enterprise.rhtml @@ -1 +1 @@ -
  • <%= link_to enterprise.name %>
  • +
  • <%= link_to enterprise.name, :action => 'show', :id => enterprise %>
  • diff --git a/app/views/enterprise/edit.rhtml b/app/views/enterprise/edit.rhtml new file mode 100644 index 0000000..88fd12d --- /dev/null +++ b/app/views/enterprise/edit.rhtml @@ -0,0 +1,9 @@ +<%= error_messages_for 'enterprise' %> + +

    <%= _('Edit enterprise informations') %>

    + +<% form_tag :action => 'update', :id => @enterprise do %> + <%= render :partial => 'form' %> +

    <%= submit_tag _('Register') %> +<%= link_to _('Cancel'), :action => 'index' %>

    +<% end %> diff --git a/app/views/enterprise/index.rhtml b/app/views/enterprise/index.rhtml deleted file mode 100644 index 25fd449..0000000 --- a/app/views/enterprise/index.rhtml +++ /dev/null @@ -1,12 +0,0 @@ -

    <%= link_to _('Register new enterprise'), :action => 'register_form' %>

    -

    <%= _('Listing my enterprises') %>

    - - -<% unless @pending_enterprises.blank? %> -

    <%= _('Listing pending enterprises') %>

    - -<% end %> diff --git a/app/views/enterprise/list.rhtml b/app/views/enterprise/list.rhtml new file mode 100644 index 0000000..25fd449 --- /dev/null +++ b/app/views/enterprise/list.rhtml @@ -0,0 +1,12 @@ +

    <%= link_to _('Register new enterprise'), :action => 'register_form' %>

    +

    <%= _('Listing my enterprises') %>

    + + +<% unless @pending_enterprises.blank? %> +

    <%= _('Listing pending enterprises') %>

    + +<% end %> diff --git a/app/views/enterprise/register_form.rhtml b/app/views/enterprise/register_form.rhtml index 5e8c563..da430c5 100644 --- a/app/views/enterprise/register_form.rhtml +++ b/app/views/enterprise/register_form.rhtml @@ -3,6 +3,8 @@

    <%= _('Register enterprise') %>

    <% form_tag :action => 'register' do %> +


    + <%= text_field 'enterprise', 'identifier', 'size' => 20 %>

    <%= render :partial => 'form' %>

    <%= submit_tag _('Register') %> <%= link_to _('Cancel'), :action => 'index' %>

    diff --git a/app/views/enterprise/show.rhtml b/app/views/enterprise/show.rhtml new file mode 100644 index 0000000..75f26d9 --- /dev/null +++ b/app/views/enterprise/show.rhtml @@ -0,0 +1,14 @@ +

    <%= @enterprise.name %>

    + +

    <%= _('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 %>

    + +

    <%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %>

    +

    <%= link_to _('Register new enterprise'), :action => 'register_form' %>

    -- libgit2 0.21.2