enterprise_editor_controller.rb
1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class EnterpriseEditorController < ProfileAdminController
before_filter :logon, :check_enterprise
protect [:edit, :update], :edit_profile, :profile
protect [:destroy], :destroy_profile, :profile
# Show details about an enterprise
def index
@enterprise = @profile
end
# Provides an interface to editing the enterprise details
def edit
@validation_entities = Organization.find(:all) - [@enterprise]
end
# Saves the changes made in an enterprise
def update
if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info])
redirect_to :action => 'index'
else
flash[:notice] = _('Could not update the enterprise')
@validation_entities = Organization.find(:all) - [@enterprise]
render :action => 'edit'
end
end
# Elimitates the enterprise of the system
def destroy
@enterprise.destroy
flash[:notice] = _('Enterprise sucessfully erased from the system')
redirect_to '/'
end
# Activate a validated enterprise
def activate
if @enterprise.activate
flash[:notice] = _('Enterprise successfuly activacted')
else
flash[:notice] = _('Failed to activate the enterprise')
end
redirect_to :action => 'index'
end
protected
def logon
if logged_in?
@user = current_user
@person = @user.person
end
end
def check_enterprise
redirect_to '/' unless @profile.is_a?(Enterprise)
@enterprise = @profile
end
end