profile_editor_controller.rb
2.54 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class ProfileEditorController < MyProfileController
protect 'edit_profile', :profile, :except => [:destroy_profile]
protect 'destroy_profile', :profile, :only => [:destroy_profile]
def index
@pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)}
end
helper :profile
# edits the profile info (posts back)
def edit
@profile_data = profile
@possible_domains = profile.possible_domains
if request.post?
params[:profile_data][:fields_privacy] ||= {} if profile.person? && params[:profile_data].is_a?(Hash)
begin
Profile.transaction do
Image.transaction do
if profile.update_attributes!(params[:profile_data])
redirect_to :action => 'index', :profile => profile.identifier
end
end
end
rescue Exception => ex
if profile.identifier.blank?
profile.identifier = params[:profile]
end
session[:notice] = _('Cannot update profile')
logger.error ex.to_s
end
end
end
def enable
@to_enable = profile
if request.post? && params[:confirmation]
unless @to_enable.update_attribute('enabled', true)
session[:notice] = _('%s was not enabled.') % @to_enable.name
end
redirect_to :action => 'index'
end
end
def disable
@to_disable = profile
if request.post? && params[:confirmation]
unless @to_disable.update_attribute('enabled', false)
session[:notice] = _('%s was not disabled.') % @to_disable.name
end
redirect_to :action => 'index'
end
end
def update_categories
@object = profile
@categories = @toplevel_categories = environment.top_level_categories
if params[:category_id]
@current_category = Category.find(params[:category_id])
@categories = @current_category.children
end
render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data', :multiple => true}, :layout => false
end
def header_footer
@no_design_blocks = true
if request.post?
@profile.update_header_and_footer(params[:custom_header], params[:custom_footer])
redirect_to :action => 'index'
else
@header = boxes_holder.custom_header
@footer = boxes_holder.custom_footer
end
end
def destroy_profile
if request.post?
if @profile.destroy
session[:notice] = _('The profile was deleted.')
redirect_to :controller => 'home'
else
session[:notice] = _('Could not delete profile')
end
end
end
end