2009-05-07 16:53:18 +00:00
|
|
|
module ApplicationHelper
|
2011-02-08 02:07:40 +00:00
|
|
|
|
|
|
|
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
|
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-04-19 07:05:48 +00:00
|
|
|
link_to t('back'), get_go_back
|
|
|
|
end
|
|
|
|
|
|
|
|
# Clean the link back
|
|
|
|
# Remove the locale but keep all the other params
|
|
|
|
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
|
|
|
|
target = request.referer.split('?')
|
|
|
|
vars = target[1].split('&') rescue []
|
|
|
|
vars.delete_if {|var| var.include? 'locale=' }
|
|
|
|
session[:last_page] = if vars.size > 0
|
|
|
|
target[0].to_s + '?' + vars.join('&')
|
|
|
|
else
|
|
|
|
target[0].to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
eval(params[:controller].split('/').join('_') << '_url')
|
|
|
|
end
|
2011-04-13 10:19:51 +00:00
|
|
|
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-05-09 10:49:57 +00:00
|
|
|
|
2011-05-13 01:08:42 +00:00
|
|
|
def render_node_and_children(node)
|
2011-05-09 10:49:57 +00:00
|
|
|
ret = ''
|
|
|
|
if node
|
2011-05-13 01:08:42 +00:00
|
|
|
case node._type
|
|
|
|
when 'Page'
|
2011-05-18 02:00:00 +00:00
|
|
|
dest = admin_page_path(node)
|
2011-05-13 01:08:42 +00:00
|
|
|
when 'Link'
|
2011-05-18 02:00:00 +00:00
|
|
|
dest = admin_link_path(node)
|
2011-05-13 01:08:42 +00:00
|
|
|
end
|
2011-05-09 10:49:57 +00:00
|
|
|
ret << "<li>"
|
2011-05-13 01:08:42 +00:00
|
|
|
ret << (link_to node.name, dest)
|
|
|
|
ret << ' | ' << (link_to 'new_link', new_admin_link_path(:parent_id => node.id)) if node._type.eql?('Page')
|
|
|
|
ret << ' | ' << (link_to t(:delete), delete_admin_link_path(node, :authenticity_token => form_authenticity_token), :confirm => t('sure?'), :class => 'delete') if node._type.eql?('Link')
|
|
|
|
ret << render_children(node)
|
2011-05-09 10:49:57 +00:00
|
|
|
ret << "</li>"
|
|
|
|
end
|
|
|
|
ret.html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_children(parent)
|
2011-05-13 01:08:42 +00:00
|
|
|
if children = parent.children
|
|
|
|
ret = ''
|
|
|
|
ret << "<ul>"
|
|
|
|
children.each do |child|
|
|
|
|
ret << render_node_and_children(child)
|
|
|
|
end
|
|
|
|
ret << "</ul>"
|
|
|
|
ret
|
2011-05-09 10:49:57 +00:00
|
|
|
end
|
|
|
|
end
|
2011-02-08 02:07:40 +00:00
|
|
|
|
2009-05-07 16:53:18 +00:00
|
|
|
end
|