comparison app/controllers/users_controller.rb @ 195:172b8d25c1ae live

Merge from branch "feature_64"
author Chris Cannam
date Mon, 07 Feb 2011 13:47:47 +0000
parents f9fe5ef6156e
children 73ff0e6a11b1
comparison
equal deleted inserted replaced
170:6d10c3b6fe17 195:172b8d25c1ae
52 def show 52 def show
53 @user = User.find(params[:id]) 53 @user = User.find(params[:id])
54 54
55 if @user.ssamr_user_detail != nil 55 if @user.ssamr_user_detail != nil
56 @description = @user.ssamr_user_detail.description 56 @description = @user.ssamr_user_detail.description
57
58 if @user.ssamr_user_detail.institution_type != nil
59 # institution_type is true for listed institutions
60 if (@user.ssamr_user_detail.institution_type)
61 @institution_name = Institution.find(@user.ssamr_user_detail.institution_id).name
62 else
63 @institution_name = @user.ssamr_user_detail.other_institution
64 end
65 end
57 end 66 end
58 67
59 # show projects based on current user visibility 68 # show projects based on current user visibility
60 @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current)) 69 @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current))
61 70
80 89
81 @user = User.new(:language => Setting.default_language) 90 @user = User.new(:language => Setting.default_language)
82 @auth_sources = AuthSource.find(:all) 91 @auth_sources = AuthSource.find(:all)
83 92
84 @ssamr_user_details = SsamrUserDetail.new 93 @ssamr_user_details = SsamrUserDetail.new
85
86 end 94 end
87 95
88 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } 96 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
89 def create 97 def create
90 @notification_options = User::MAIL_NOTIFICATION_OPTIONS 98 @notification_options = User::MAIL_NOTIFICATION_OPTIONS
129 @user = User.find(params[:id]) 137 @user = User.find(params[:id])
130 @notification_options = @user.valid_notification_options 138 @notification_options = @user.valid_notification_options
131 @notification_option = @user.mail_notification 139 @notification_option = @user.mail_notification
132 140
133 @ssamr_user_details = @user.ssamr_user_detail 141 @ssamr_user_details = @user.ssamr_user_detail
142
143 if @user.ssamr_user_detail == nil
144 @selected_institution_id = nil
145 else
146 @selected_institution_id = @user.ssamr_user_detail.institution_id.to_i
147 end
134 148
135 @auth_sources = AuthSource.find(:all) 149 @auth_sources = AuthSource.find(:all)
136 @membership ||= Member.new 150 @membership ||= Member.new
137 end 151 end
138 152
161 @ssamr_user_details = SsamrUserDetail.new() 175 @ssamr_user_details = SsamrUserDetail.new()
162 @user.ssamr_user_detail = @ssamr_user_details 176 @user.ssamr_user_detail = @ssamr_user_details
163 else 177 else
164 @ssamr_user_details = @user.ssamr_user_detail 178 @ssamr_user_details = @user.ssamr_user_detail
165 end 179 end
166 180
167
168 if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty? 181 if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty?
169 @ssamr_user_details.description = @user.ssamr_user_detail.description 182 @ssamr_user_details.description = @user.ssamr_user_detail.description
183 @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id
184 @ssamr_user_details.other_institution = @user.ssamr_user_detail.other_institution
185 @ssamr_user_details.institution_type = @user.ssamr_user_detail.institution_type
186
170 else 187 else
171 @ssamr_user_details.description = params[:ssamr_user_details][:description] 188 @ssamr_user_details.description = params[:ssamr_user_details][:description]
172 @ssamr_user_details.save! 189 @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id]
190 @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution]
191 @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type]
173 end 192 end
174 193
175 if @user.save 194 if @user.save
176 @user.pref.save 195 @user.pref.save
177 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) 196 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])