2009-05-07 16:53:18 +00:00
|
|
|
module ApplicationHelper
|
2011-02-08 02:07:40 +00:00
|
|
|
|
|
|
|
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
|
2012-05-23 05:00:51 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
def colorize_in_use_locale(locale)
|
|
|
|
@site_in_use_locales.include?(locale)? 'green' : 'red'
|
|
|
|
end
|
|
|
|
|
2011-02-08 02:07:40 +00:00
|
|
|
def flash_messages
|
|
|
|
return unless messages = flash.keys.select{|k| FLASH_NOTICE_KEYS.include?(k)}
|
|
|
|
formatted_messages = messages.map do |type|
|
|
|
|
content_tag :div, :class => type.to_s do
|
|
|
|
message_for_item(flash[type], flash["#{type}_item".to_sym])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
raw(formatted_messages.join)
|
|
|
|
end
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
def link_back
|
2011-05-26 05:48:09 +00:00
|
|
|
link_to t('back'), get_go_back, :class => 'nav'
|
2011-04-19 07:05:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Clean the link back
|
|
|
|
def get_go_back
|
|
|
|
begin
|
2011-05-02 05:28:38 +00:00
|
|
|
if request.url.include?('locale=')
|
2011-04-19 07:05:48 +00:00
|
|
|
session[:last_page]
|
|
|
|
else
|
2012-02-28 20:21:56 +00:00
|
|
|
session[:last_page] = remove_locale(request.referer)
|
2011-04-19 07:05:48 +00:00
|
|
|
end
|
|
|
|
rescue
|
|
|
|
eval(params[:controller].split('/').join('_') << '_url')
|
|
|
|
end
|
2011-04-13 10:19:51 +00:00
|
|
|
end
|
|
|
|
|
2012-02-28 20:21:56 +00:00
|
|
|
# Remove the locale but keep all the other params
|
|
|
|
def remove_locale(url)
|
|
|
|
target = url.split('?')
|
|
|
|
vars = target[1].split('&') rescue []
|
|
|
|
vars.delete_if {|var| var.include? 'locale=' }
|
|
|
|
if vars.size > 0
|
|
|
|
target[0].to_s + '?' + vars.join('&')
|
|
|
|
else
|
|
|
|
target[0].to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_locale(url, locale)
|
|
|
|
if url.include?('?')
|
|
|
|
url + "&locale=#{locale}"
|
|
|
|
else
|
|
|
|
url + "?locale=#{locale}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-08 02:07:40 +00:00
|
|
|
def message_for_item(message, item = nil)
|
|
|
|
if item.is_a?(Array)
|
|
|
|
message % link_to(*item)
|
|
|
|
else
|
|
|
|
message % item
|
|
|
|
end
|
|
|
|
end
|
2011-12-23 10:34:21 +00:00
|
|
|
|
|
|
|
def add_attribute(partial, f, attribute)
|
|
|
|
new_object = f.object.send(attribute).build
|
|
|
|
fields = f.fields_for(attribute, new_object, :child_index => "new_#{attribute}") do |f|
|
|
|
|
render :partial => partial, :object => new_object, :locals => {:f => f}
|
|
|
|
end
|
|
|
|
end
|
2012-05-01 08:05:05 +00:00
|
|
|
|
2012-05-11 08:44:40 +00:00
|
|
|
def active_for_ob_auths_object(object_class,field = :object_auth_id)
|
|
|
|
unless active_for_action("object_auths_new_interface","setting").nil?
|
|
|
|
ob_auth = ObjectAuth.find params[field]
|
|
|
|
ob_auth.obj_authable_type == object_class.to_s ? 'active' : nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def active_for_ob_auth(ob_auth_title,field = :object_auth_id)
|
|
|
|
unless active_for_action("module_apps_new_interface","setting").nil?
|
|
|
|
oa_auth = ObjectAuth.find params[field]
|
|
|
|
oa_auth.title == ob_auth_title ? 'active' : nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def active_for_app_auth(app_title ='', opt={:controller_name => 'module_apps_new_interface',:action_name=>'setting',:field => :module_app_id})
|
|
|
|
unless active_for_action(opt[:controller_name],opt[:action_name]).nil?
|
|
|
|
app = ModuleApp.find params[opt[:field]]
|
2012-05-01 08:05:05 +00:00
|
|
|
app.title == app_title ? 'active' : nil
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2012-02-22 05:44:01 +00:00
|
|
|
|
|
|
|
def active_for_controllers(*controller_names)
|
2012-04-23 08:12:07 +00:00
|
|
|
(controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? 'active' : nil
|
2012-02-22 05:44:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def visible_for_controllers(*controller_names)
|
2012-04-23 08:12:07 +00:00
|
|
|
(controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? '' : 'hide'
|
2012-02-22 05:44:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def active_for_action(controller_name, action_name)
|
2012-04-12 10:14:00 +00:00
|
|
|
((controller.controller_name.eql?(controller_name) || request.fullpath.eql?(controller_name)) && controller.action_name.eql?(action_name)) ? 'active' : nil
|
2012-02-22 05:44:01 +00:00
|
|
|
end
|
2012-05-13 11:32:05 +00:00
|
|
|
|
2012-03-21 17:51:16 +00:00
|
|
|
def page_metas(page)
|
2012-05-06 16:54:18 +00:00
|
|
|
tmp_meta = {}
|
2012-03-21 17:51:16 +00:00
|
|
|
metas = ''
|
2012-05-06 16:54:18 +00:00
|
|
|
@site.site_metas.each do |meta|
|
2012-03-21 17:51:16 +00:00
|
|
|
name, content = meta.get_name_content
|
2012-05-06 16:54:18 +00:00
|
|
|
tmp_meta.merge!(name => content)
|
2012-03-21 17:51:16 +00:00
|
|
|
end rescue nil
|
2012-05-06 16:54:18 +00:00
|
|
|
page.page_metas.each do |meta|
|
|
|
|
name, content = meta.get_name_content
|
|
|
|
tmp_meta.merge!(name => content)
|
|
|
|
end rescue nil
|
|
|
|
tmp_meta.each_pair{|name, content|
|
|
|
|
metas << "<meta name='#{name}' content='#{content}' />\n"
|
|
|
|
} if !tmp_meta.blank?
|
|
|
|
metas
|
2012-03-21 17:51:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def page_title(page)
|
2012-05-07 07:11:43 +00:00
|
|
|
res = "<title>"
|
|
|
|
page_title = page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]
|
2012-05-11 08:16:09 +00:00
|
|
|
if page.root? && @site.title
|
2012-05-07 07:11:43 +00:00
|
|
|
res << @site.title[I18n.locale]
|
|
|
|
elsif @site.title && @site.title_always_on
|
|
|
|
res << @site.title[I18n.locale] + ' - ' + page_title
|
|
|
|
else
|
|
|
|
res << page_title
|
|
|
|
end
|
|
|
|
res << "</title>\n"
|
2012-03-21 17:51:16 +00:00
|
|
|
end
|
|
|
|
|
2012-04-25 17:49:02 +00:00
|
|
|
def page_stylesheets(page, edit=nil)
|
2012-03-21 17:51:16 +00:00
|
|
|
stylesheets = ''
|
2012-04-25 17:49:02 +00:00
|
|
|
unless edit
|
|
|
|
stylesheets << "<link href='/assets/bootstrap.css' rel='stylesheet' type='text/css' />\n"
|
|
|
|
stylesheets << "<link href='/assets/bootstrap-orbit.css' rel='stylesheet' type='text/css' />\n"
|
|
|
|
stylesheets << "<link href='/assets/style.css' rel='stylesheet' type='text/css' />\n"
|
|
|
|
end
|
2012-03-21 17:51:16 +00:00
|
|
|
stylesheets << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.reset_css
|
2012-05-08 09:21:26 +00:00
|
|
|
stylesheets << "<link href='#{asset_path 'banner_nav.css'}' rel='stylesheet' type='text/css' />\n"
|
2012-03-21 17:51:16 +00:00
|
|
|
stylesheets << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.default_css
|
|
|
|
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
|
|
|
|
stylesheets << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />\n" if theme
|
|
|
|
stylesheets
|
|
|
|
end
|
|
|
|
|
2012-04-25 17:49:02 +00:00
|
|
|
def page_javascripts(page, edit=nil)
|
2012-03-21 17:51:16 +00:00
|
|
|
javascripts = ''
|
2012-04-25 17:49:02 +00:00
|
|
|
unless edit
|
|
|
|
javascripts << "<script type='text/javascript' src='/static/jquery.js'></script>\n"
|
|
|
|
javascripts << "<script type='text/javascript' src='/assets/bootstrap.js'></script>\n"
|
|
|
|
javascripts << "<script type='text/javascript' src='/assets/jquery.tinyscrollbar.min.js'></script>\n"
|
|
|
|
javascripts << "<script type='text/javascript' src='/assets/jquery.isotope.min.js'></script>\n"
|
|
|
|
javascripts << "<script type='text/javascript' src='/assets/orbit-bar-member.js'></script>\n"
|
|
|
|
javascripts << "<script type='text/javascript' src='/assets/orbit_bar.js'></script>\n"
|
2012-05-04 11:11:28 +00:00
|
|
|
javascripts << "<script type='text/javascript' src='/assets/orbit-bar-search.js'></script>\n"
|
2012-04-25 17:49:02 +00:00
|
|
|
end
|
2012-04-27 03:02:56 +00:00
|
|
|
javascripts << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>\n"
|
2012-03-21 17:51:16 +00:00
|
|
|
javascripts << "<script type='text/javascript' src='/static/kernel.js'></script>\n"
|
|
|
|
javascripts << "<script type='text/javascript' src='/assets/event.js'></script>\n"
|
|
|
|
page.design.javascripts.each do |js|
|
|
|
|
# javascripts << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
|
|
|
end
|
|
|
|
javascripts
|
|
|
|
end
|
|
|
|
|
2012-05-06 16:53:52 +00:00
|
|
|
def active_when_current_locale_eq(locale)
|
2012-05-07 07:55:45 +00:00
|
|
|
locale.to_sym == I18n.locale ? 'active in': ''
|
2012-05-06 16:53:52 +00:00
|
|
|
end
|
|
|
|
|
2012-05-16 08:42:43 +00:00
|
|
|
def at_least_module_manager
|
2012-05-15 10:55:16 +00:00
|
|
|
is_manager? || is_admin?
|
2012-05-16 08:42:43 +00:00
|
|
|
end
|
|
|
|
|
2012-05-15 13:26:09 +00:00
|
|
|
def dislpay_view_count(object)
|
|
|
|
"#{t(:view_count)}: #{object.view_count}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors(options={})
|
2012-05-18 06:13:11 +00:00
|
|
|
Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count
|
2012-05-15 13:26:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_today
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day})
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_this_week
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week})
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_this_month
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month})
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_this_year
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year})
|
|
|
|
end
|
|
|
|
|
2012-05-15 10:55:16 +00:00
|
|
|
def at_least_module_manager
|
|
|
|
is_manager? || is_admin?
|
|
|
|
end
|
|
|
|
|
2012-05-18 11:42:36 +00:00
|
|
|
def display_date_time(object)
|
|
|
|
object.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_date(object)
|
|
|
|
object.strftime("%Y-%m-%d")
|
|
|
|
end
|
|
|
|
|
2009-05-07 16:53:18 +00:00
|
|
|
end
|