# These helper methods can be called in your template to set variables to be used in the layout
# This module should be included in all views globally,
# to do so you may need to add this line to your ApplicationController
# helper :layout
module LayoutHelper
# allows the inclusion of javascript files in the
section for specific views
def javascript(*files)
content_for(:head, javascript_include_tag(*files))
end
# allows the inclusion of css files in the section for specific views
def stylesheet(*files)
content_for(:head, stylesheet_link_tag(*files))
end
# change the for specific views
def title(page_title)
content_for(:title, page_title)
end
# change the class => page for specific layouts
def page(page_name)
content_for(:page, page_name)
end
# a link to the previous visited page
def link_to_back
link_to(t("label.back"), :back)
end
def flash_message
flash.each do |message_type, message|
haml_concat render(:partial => "shared/flash_message", :locals => {:message_type => message_type, :message => message}) +
javascript_tag(
visual_effect(:appear, "flash_box", :duration => 0.5, :to => 0.7, :queue => {:position => :end, :scope => :folder}) +
visual_effect(:fade, "flash_box", :duration => 0.5, :delay => 8, :from => 0.7, :queue => {:position => :end, :scope => :folder}))
flash.discard
end unless flash.blank?
end
# helpers for nested forms
def add_child_link(name, f, method)
fields = new_child_fields(f, method)
link_to_function(name, h("insert_fields(this, '#{method}', '#{escape_javascript(fields)}')"))
end
def remove_child_link(name, f)
f.hidden_field(:_delete) + link_to_function(name, "remove_fields(this)")
end
def new_child_fields(form_builder, method, options = {})
options[:object] ||= form_builder.object.class.reflect_on_association(method).klass.new
options[:partial] ||= method.to_s.singularize
options[:form_builder_local] ||= :f
form_builder.fields_for(method, options[:object], :child_index => "new_#{method}") do |f|
render(:partial => options[:partial], :locals => { options[:form_builder_local] => f })
end
end
end