2007-03-30 04:36:52 +00:00
|
|
|
class PreferencesController < ApplicationController
|
2011-08-17 22:51:02 +02:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def index
|
2011-01-16 18:14:07 +01:00
|
|
|
@page_title = t('preferences.page_title')
|
2011-02-14 22:18:30 +01:00
|
|
|
@prefs = current_user.prefs
|
2011-08-17 22:51:02 +02:00
|
|
|
@user = current_user
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
2011-08-17 22:51:02 +02:00
|
|
|
@prefs = current_user.prefs
|
|
|
|
|
@user = current_user
|
2007-07-30 05:29:18 +00:00
|
|
|
user_updated = current_user.update_attributes(params['user'])
|
|
|
|
|
prefs_updated = current_user.preference.update_attributes(params['prefs'])
|
2011-08-17 22:51:02 +02:00
|
|
|
if (user_updated && prefs_updated)
|
2011-10-24 21:47:15 +02:00
|
|
|
if !params['user']['password'].blank? # password updated?
|
|
|
|
|
logout_user t('preferences.password_changed')
|
|
|
|
|
else
|
|
|
|
|
preference_updated
|
|
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
else
|
2011-08-17 22:51:02 +02:00
|
|
|
msg = "Preferences could not be updated: "
|
|
|
|
|
msg += "User model errors; " unless user_updated
|
|
|
|
|
msg += "Prefs model errors; " unless prefs_updated
|
|
|
|
|
notify :warning, msg
|
|
|
|
|
render 'index'
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-08-17 22:51:02 +02:00
|
|
|
|
|
|
|
|
def render_date_format
|
|
|
|
|
format = params[:date_format]
|
|
|
|
|
render :text => l(Date.today, :format => format)
|
|
|
|
|
end
|
|
|
|
|
|
2011-10-24 21:47:15 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
# Display notification if preferences are successful updated
|
|
|
|
|
def preference_updated
|
|
|
|
|
notify :notice, t('preferences.updated')
|
|
|
|
|
redirect_to :action => 'index'
|
|
|
|
|
end
|
|
|
|
|
|
2010-01-17 11:33:35 -08:00
|
|
|
end
|