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
|
2013-05-27 12:44:31 +02:00
|
|
|
user_updated = current_user.update_attributes(user_params)
|
|
|
|
prefs_updated = current_user.preference.update_attributes(prefs_params)
|
2011-08-17 22:51:02 +02:00
|
|
|
if (user_updated && prefs_updated)
|
2013-09-13 15:19:25 +03:00
|
|
|
if params['user']['password'].present? # password updated?
|
2011-10-24 21:47:15 +02:00
|
|
|
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]
|
2014-12-30 22:56:19 +00:00
|
|
|
render :text => l(Date.current, :format => format)
|
2011-08-17 22:51:02 +02:00
|
|
|
end
|
|
|
|
|
2011-10-24 21:47:15 +02:00
|
|
|
private
|
|
|
|
|
2013-05-27 12:44:31 +02:00
|
|
|
def prefs_params
|
|
|
|
params.require(:prefs).permit(
|
2014-08-14 21:05:05 -05:00
|
|
|
:date_format, :week_starts, :show_number_completed,
|
|
|
|
:show_completed_projects_in_sidebar, :show_hidden_contexts_in_sidebar,
|
|
|
|
:staleness_starts, :due_style, :locale, :title_date_format, :time_zone,
|
|
|
|
:show_hidden_projects_in_sidebar, :show_project_on_todo_done,
|
|
|
|
:review_period, :refresh, :verbose_action_descriptors,
|
2013-05-27 12:44:31 +02:00
|
|
|
:mobile_todos_per_page, :sms_email, :sms_context_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_params
|
|
|
|
params.require(:user).permit(:login, :first_name, :last_name, :password_confirmation, :password, :auth_type, :open_id_url)
|
|
|
|
end
|
|
|
|
|
2011-10-24 21:47:15 +02:00
|
|
|
# Display notification if preferences are successful updated
|
|
|
|
def preference_updated
|
|
|
|
notify :notice, t('preferences.updated')
|
|
|
|
redirect_to :action => 'index'
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2010-01-17 11:33:35 -08:00
|
|
|
end
|