59 lines
1.4 KiB
Ruby
59 lines
1.4 KiB
Ruby
class ApplicationController < ActionController::Base
|
|
before_filter :set_locale
|
|
layout :layout_by_resource
|
|
|
|
|
|
protect_from_forgery
|
|
|
|
private
|
|
|
|
def set_locale
|
|
I18n.locale = :nl
|
|
end
|
|
|
|
def layout_by_resource
|
|
if devise_controller?
|
|
case session[:user_return_to]
|
|
when /\/user\// then ''
|
|
when /obtain_token/ then 'obtain_token'
|
|
else 'theme1'
|
|
end
|
|
else
|
|
"application"
|
|
end
|
|
end
|
|
def check_active_list_state
|
|
if current_user.try(:active_list_id)
|
|
unless active_list.active?
|
|
current_user.list_is_closed!
|
|
redirect_to user_root_path, alert: t('messages.the_list_has_been_closed', list: List.model_name.human)
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
def active_list
|
|
return nil unless current_user.try(:active_list_id).present?
|
|
@active_list ||= List.find(current_user.active_list_id)
|
|
end
|
|
alias :active_list_object :active_list
|
|
helper_method :active_list_object
|
|
|
|
def js_alert(*args)
|
|
options = args.extract_options!
|
|
message = args.first || ''
|
|
{ok: false, message: message}.merge(options).to_json
|
|
end
|
|
def js_notice(*args)
|
|
options = args.extract_options!
|
|
message = args.first || ''
|
|
{ok: true, message: message}.merge(options).to_json
|
|
end
|
|
|
|
def broadcast_user(uid, event, data = {})
|
|
message = {channel: channel, data: {event: event, data: data}}
|
|
uri = URI.parse("http://localhost:9292/faye")
|
|
Net::HTTP.post_form(uri, :message => message.to_json)
|
|
end
|
|
end
|