mailr/app/controllers/application_controller.rb

71 lines
1.8 KiB
Ruby
Raw Normal View History

2011-07-21 20:20:15 +02:00
require 'yaml'
2011-06-24 23:48:08 +02:00
2011-07-21 20:20:15 +02:00
class ApplicationController < ActionController::Base
2011-06-24 23:48:08 +02:00
2011-07-21 20:20:15 +02:00
protect_from_forgery
2011-08-16 20:05:58 +02:00
before_filter :load_defaults,:current_user,:set_locale
before_filter :plugins_configuration
2011-08-24 19:20:13 +02:00
rescue_from ActiveRecord::RecordNotFound do
logger.custom('record_not_found','exc')
reset_session
redirect_to :controller=>'user', :action => 'login'
end
2011-08-02 23:12:17 +02:00
################################# protected section ###########################################
2011-07-21 20:20:15 +02:00
protected
2009-09-01 14:23:05 +02:00
2011-07-21 20:20:15 +02:00
def load_defaults
2011-07-24 15:56:47 +02:00
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
2011-07-21 20:20:15 +02:00
end
2011-06-24 23:48:08 +02:00
2011-07-21 20:20:15 +02:00
def theme_resolver
2011-07-23 21:55:26 +02:00
if @current_user.nil?
2011-07-24 15:56:47 +02:00
$defaults['theme']
2011-07-23 21:55:26 +02:00
else
2011-07-24 22:22:13 +02:00
@current_user.prefs.theme || $defaults['theme']
2011-07-23 21:55:26 +02:00
end
2011-07-21 20:20:15 +02:00
end
2009-09-01 14:23:05 +02:00
2011-07-21 20:20:15 +02:00
def set_locale
2011-07-23 21:55:26 +02:00
if @current_user.nil?
2011-07-24 15:56:47 +02:00
I18n.locale = $defaults['locale'] || I18n.default_locale
2011-07-23 21:55:26 +02:00
else
2011-08-16 20:05:58 +02:00
I18n.locale = @current_user.prefs.locale.to_sym || I18n.default_locale
2011-07-23 21:55:26 +02:00
end
end
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def check_current_user
if @current_user.nil?
session["return_to"] = request.fullpath
2011-08-24 19:20:13 +02:00
redirect_to :controller => 'user', :action => 'login'
2011-07-23 21:55:26 +02:00
return false
end
2011-07-21 20:20:15 +02:00
end
2011-07-27 20:34:30 +02:00
def selected_folder
2011-07-29 20:21:17 +02:00
session[:selected_folder] ? @selected_folder = session[:selected_folder] : @selected_folder = $defaults['mailbox_inbox']
2011-07-27 20:34:30 +02:00
end
2011-07-31 22:45:29 +02:00
def get_current_folders
@folders_shown = @current_user.folders.shown.order("name asc")
2011-08-16 20:05:58 +02:00
@current_folder = @current_user.folders.find_by_full_name(@selected_folder)
2011-07-31 22:45:29 +02:00
end
2011-08-02 23:12:17 +02:00
##################################### private section ##########################################
2011-08-16 20:05:58 +02:00
private
def plugins_configuration
WillPaginate::ViewHelpers.pagination_options[:previous_label] = t(:previous_page)
WillPaginate::ViewHelpers.pagination_options[:next_label] = t(:next_page)
end
2011-08-02 23:12:17 +02:00
end
2011-08-16 20:05:58 +02:00