# The filters added to this controller will be run for all controllers in the application.
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
before_filter :localize
before_filter :user_login_filter
before_filter :add_scripts
model :customer
protected
def secure_user?() true end
def secure_cust?() false end
def additional_scripts() "" end
def onload_function() "" end
private
def add_scripts
@additional_scripts = additional_scripts()
@onload_function = onload_function()
end
def user_login_filter
if (secure_user? or secure_cust? )and logged_user.nil?
@session["return_to"] = @request.request_uri
redirect_to :controller=>"/login", :action => "index"
return false
end
end
alias login_required user_login_filter
def logged_user # returns customer id
@session['user']
end
def logged_customer
@session['user']
end
def localize
# We will use instance vars for the locale so we can make use of them in
# the templates.
@charset = 'utf-8'
@headers['Content-Type'] = "text/html; charset=#{@charset}"
# Here is a very simplified approach to extract the prefered language
# from the request. If all fails, just use 'en_EN' as the default.
temp = if @request.env['HTTP_ACCEPT_LANGUAGE'].nil?
[]
else
@request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.split('-') rescue []
end
language = temp.slice(0)
dialect = temp.slice(1)
@language = language.nil? ? 'en' : language.downcase # default is en
# If there is no dialect use the language code ('en' becomes 'en_EN').
@dialect = dialect.nil? ? @language.upcase : dialect
# The complete locale string consists of
# language_DIALECT (en_EN, en_GB, de_DE, ...)
@locale = "#{@language}_#{@dialect.upcase}"
@htmllang = @language == @dialect ? @language : "#{@language}-#{@dialect}"
# Finally, bind the textdomain to the locale. From now on every used
# _('String') will get translated into the right language. (Provided
# that we have a corresponding mo file in the right place).
bindtextdomain('messages', "#{RAILS_ROOT}/locale", @locale, @charset)
end
public
def include_tinymce(mode="textareas",elements="")
tinymce=''
tinymce << '
'
tinymce
end
helper_method :include_tinymce
def include_simple_tinymce(mode="textareas",elements="")
tinymce = ''
tinymce << '
'
tinymce
end
helper_method :include_simple_tinymce
end