Created
August 18, 2009 02:04
-
-
Save coreymartella/169496 to your computer and use it in GitHub Desktop.
helpers for DMD apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Methods added to this helper will be available to all templates in the application. | |
module DmdHelper | |
def admin_logged_in? | |
#TODO figure out if admin_logged_in | |
true | |
end | |
def title(page_title, show_in_body=true, &block) | |
content_for(:title) { page_title } | |
if show_in_body | |
heading = block_given? ? capture(&block) : content_tag(:h1,page_title.split(' // ').last) | |
content_for(:heading) { content_tag(:div, heading, :class => "heading") } | |
end | |
end | |
PANEL_HEADER_1= '<div class="section"><div class="title_wrapper">' | |
PANEL_HEADER_1_TABLE = '<div class="section table_section"><div class="title_wrapper">' | |
PANEL_HEADER_2 = '<span class="title_wrapper_left"></span></div> | |
<div class="section_content"> | |
<div class="sct"> | |
<div class="sct_left"><div class="sct_right"><div class="sct_left"><div class="sct_right">' | |
def panel(title,options={},&block) | |
concat(options[:table] ? PANEL_HEADER_1_TABLE : PANEL_HEADER_1) | |
concat content_tag(:h2,title) #TODO Support options here | |
if options[:tabs] | |
panel_tabs_to_html(options) | |
else | |
concat '<ul class="section_menu"></ul>' | |
end | |
concat PANEL_HEADER_2 | |
concat "<div class=\"table_wrapper #{:table_wrapper_tight if options[:tight_table]}\"><div class=\"table_wrapper_inner\">" if options[:table] | |
concat "<div class=\"wrapper_tight\"><div class=\"tight_wrapper_inner\">" if options[:tight] | |
concat capture(&block) | |
concat '</div></div>' if options[:table] | |
concat '</div></div>' if options[:tight] | |
concat '</div></div></div></div> | |
</div> | |
<span class="scb"><span class="scb_left"></span><span class="scb_right"></span></span> | |
</div> | |
</div>' | |
end | |
def padded_panel(title,&block) | |
panel title, &block | |
end | |
def table_panel(title,options={},&block) | |
panel(title,options.merge(:table => true),&block) | |
end | |
def tight_table_panel(title,options={},&block) | |
panel(title,options.merge(:table => true, :tight_table => true),&block) | |
end | |
def flexigrid_panel(title,options={},&block) | |
panel(title,options.merge(:table => true, :tight_table => true),&block) | |
end | |
def tabbed_panel(title,tabs,options={},&block) | |
panel(title,options.merge(:tabs => tabs),&block) | |
end | |
def tabbed_table_panel(title,tabs,options={},&block) | |
table_panel(title,options.merge(:tabs => tabs),&block) | |
end | |
def tabbed_tight_table_panel(title,tabs,options={},&block) | |
tight_table_panel(title,options.merge(:tabs => tabs),&block) | |
end | |
def panel_tabs_to_html(options={}) | |
tabs = options[:tabs] | |
#VINCE Make this convert to UL and add the proper classes | |
concat "<ul class=\"section_menu\" style=\"#{options[:tabs_style]}\">" | |
if tabs.is_a?String | |
concat tabs | |
elsif tabs.is_a?(Hash) && tabs.keys.include?(:partial) | |
concat render(tabs) | |
elsif tabs.is_a?Hash | |
#TODO come up with a schema for passing tabs as params {:container_id => "Name"} could work well | |
concat tabs.map{|k,v| "<li><a class=\"panel_tab\" id=\"#{k}_tab\" href=\"#\"><span><span class=\"tab_text\">#{v}</span></span></a></li>"}.join("") | |
elsif tabs.is_a?Array | |
concat tabs.map{|t| "<li><a class=\"panel_tab #{t[2] ? :active : nil}\" id=\"#{t[1]}_tab\" href=\"#\"><span><span class=\"tab_text\">#{t.first}</span></span></a></li>"}.join("") | |
end | |
concat '</ul>' | |
end | |
def logged_in_msg | |
"Welcome #{current_user.first_name rescue current_user.login}" if logged_in? | |
end | |
def mark_required_msg | |
"<span class=\"required_msg\">Required Fields are labeled like this</span>" | |
end | |
def mark_optional_msg | |
"<span class=\"optional_msg\">Optional Fields are labeled like this</span>" | |
end | |
def controller?(*args) | |
args.map(&:to_s).include? controller.controller_name | |
end | |
def action?(*args) | |
args.map(&:to_s).include? controller.action_name | |
end | |
def controller_and_action?(cname,aname) | |
controller?(cname) && action?(aname) | |
end | |
def edit_link(resource, options={}) | |
options[:title] ||= "Edit" | |
link_to icon_image_tag('edit.png'),"/#{resource.class.to_s.underscore.downcase.pluralize}/#{resource.id}/edit",options | |
end | |
def delete_link(resource, options={}) | |
options[:title] ||= "Delete" | |
options[:method] ||= :delete | |
options[:confirm] ||= "Are you sure you want to delete #{resource.class.to_s.underscore.gsub("_"," ").humanize} ##{resource.id}" | |
link_to icon_image_tag('delete.png'),"/#{resource.class.to_s.underscore.downcase.pluralize}/#{resource.id}",options | |
end | |
def include_behaviour(name) | |
javascript_include_tag "behaviours/#{name}" | |
#@behaviours ||= [] | |
#@behaviours << "behaviours/#{name}" | |
end | |
def icon_image_tag(src,options={}) | |
image_tag("icons/#{src}",options) | |
end | |
def tooltip_content(options={},&block) | |
concat(content_tag(:div, capture(&block),:class => 'tooltip_content', :style => "display: none;"),block.binding) | |
end | |
def clippy(text, bgcolor='#FFFFFF') | |
html = <<-EOF | |
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" | |
width="110" | |
height="14" | |
id="clippy" > | |
<param name="movie" value="/flash/clippy.swf"/> | |
<param name="allowScriptAccess" value="always" /> | |
<param name="quality" value="high" /> | |
<param name="scale" value="noscale" /> | |
<param NAME="FlashVars" value='text=#{CGI::escape text}' /> | |
<param name="wmode" value="transparent" /> | |
<embed src="/clippy.swf" | |
width="110" | |
height="14" | |
name="clippy" | |
quality="high" | |
allowScriptAccess="always" | |
type="application/x-shockwave-flash" | |
pluginspage="http://www.macromedia.com/go/getflashplayer" | |
FlashVars='text=#{CGI::escape text}' | |
wmode="transparent" | |
/> | |
</object> | |
EOF | |
end | |
def spanned_link_to(text,url,options={}) | |
link_to "<span>#{text}</span>", url, options | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment