mailr/app/helpers/application_helper.rb

251 lines
7.6 KiB
Ruby
Raw Normal View History

2011-09-03 13:07:40 +02:00
require 'iconv'
module ApplicationHelper
2011-07-23 21:55:26 +02:00
2011-07-27 20:34:30 +02:00
def form_field(object,field,flabel,example,val)
2011-08-16 20:05:58 +02:00
model_name = eval(object.class.model_name)
2011-07-23 21:55:26 +02:00
html = ""
html << "<div class=\"group\">"
2011-08-24 19:20:13 +02:00
if not object.errors[field.to_sym].empty?
2011-07-23 21:55:26 +02:00
html << "<div class=\"fieldWithErrors\">"
end
2011-08-24 19:20:13 +02:00
2011-07-23 21:55:26 +02:00
html << "<label class=\"label\">"
2011-08-24 19:20:13 +02:00
flabel.nil? ? html << model_name.human_attribute_name(field) : html << t(flabel.to_sym)
2011-07-23 21:55:26 +02:00
html << "</label>"
2011-08-24 19:20:13 +02:00
if not object.errors[field.to_sym].empty?
2011-07-23 21:55:26 +02:00
html << "<span class=\"error\"> "
html << object.errors[field.to_sym].to_s
html << "</span>"
html << "</div>"
end
2011-08-16 20:05:58 +02:00
html << "<input id=\""
2011-07-23 21:55:26 +02:00
html << object.class.name.downcase+"_"+field
2011-08-16 20:05:58 +02:00
html << "\""
html << " name=\"#{object.class.name.downcase}[#{field}]\""
2011-08-24 19:20:13 +02:00
html << " type=\"text\" class=\"text_field\" value=\""
value = object.instance_eval(field) || val || ""
2011-07-23 21:55:26 +02:00
html << value
html << "\"/>"
html << "<span class=\"description\">"
html << t(:example)
html << ": "
html << example
html << "</span>"
html << "</div>"
end
2011-09-03 13:07:40 +02:00
def show_param_view(object,field,value)
2011-08-24 19:20:13 +02:00
model_name = eval(object.class.model_name)
html = ""
html << "<div class=\"group\">"
html << "<label class=\"label\">#{model_name.human_attribute_name(field)}: </label>"
html << value
html << "</div>"
html
end
def area_field(object,field,flabel,example,val,cols,rows)
model_name = eval(object.class.model_name)
html = ""
html << "<div class=\"group\">"
if not object.errors[field.to_sym].empty?
html << "<div class=\"fieldWithErrors\">"
end
html << "<label class=\"label\">"
flabel.nil? ? html << model_name.human_attribute_name(field) : html << t(flabel.to_sym)
html << "</label>"
if not object.errors[field.to_sym].empty?
html << "<span class=\"error\">"
html << object.errors[field.to_sym].to_s
html << "</span>"
html << "</div>"
end
name = object.class.name.downcase + '[' + field + ']'
id = object.class.name.downcase+"_"+field
value = object.instance_eval(field) || val || ""
2011-09-03 13:07:40 +02:00
html << "<textarea id=\"#{id}\" name=\"#{name}\" class=\"text_area\" cols=\"#{cols}\" rows=\"#{rows}\">#{value}</textarea>"
2011-08-24 19:20:13 +02:00
desc = t(:example) + ": " + example
html << "<span class=\"description\">#{desc}</span>"
html << "</div>"
end
2011-07-29 20:05:47 +02:00
def form_button(text,image)
2011-07-23 21:55:26 +02:00
html = ""
html << "<div class=\"group navform wat-cf\">"
html << "<button class=\"button\" type=\"submit\">"
html << "<img src=\""
2011-07-29 20:05:47 +02:00
html << current_theme_image_path(image)
2011-07-23 21:55:26 +02:00
html << "\" alt=\""
2011-08-16 20:05:58 +02:00
html << t(text.to_sym)
2011-07-23 21:55:26 +02:00
html << "\" />"
html << t(text.to_sym)
html << "</button></div>"
end
2011-09-03 13:07:40 +02:00
def form_buttons(buttons)
html = ""
html << "<div class=\"group navform wat-cf\">"
buttons.each do |b|
html << "<button class=\"button\" type=\"submit\" name=\"#{b[:text]}\">"
html << "<img src=\""
html << current_theme_image_path(b[:image])
html << "\" alt=\""
html << t(b[:text].to_sym)
html << "\" />"
html << t(b[:text].to_sym)
html << "</button> "
end
html << "</div>"
end
2011-07-29 20:05:47 +02:00
def form_button_value(text,image,onclick)
html = ""
html << "<div class=\"group navform wat-cf\">"
html << "<button class=\"button\" type=\"submit\" onclick=\"window.location='"
html << onclick
html << "'\">"
html << "<img src=\""
html << current_theme_image_path(image)
html << "\" alt=\""
html << text
html << "\" />"
html << t(text.to_sym)
html << "</button></div>"
end
2011-09-03 13:07:40 +02:00
def simple_input_field(name,id,label,value)
2011-07-29 20:05:47 +02:00
html = ""
2011-08-16 20:05:58 +02:00
html << "<div class=\"param_group\">"
2011-07-29 20:05:47 +02:00
html << "<label class=\"label\">#{label}</label>"
2011-09-03 13:07:40 +02:00
html << "<input name=\"#{name}[#{id}]\" id=\"#{name}_#{id} class=\"text_field\" type=\"text\" value=\"#{value}\">"
2011-07-29 20:05:47 +02:00
html << "</div>"
end
def select_field(name,object,label,blank)
html = ""
html << "<div class=\"group\">"
html << "<label class=\"label\">#{label}</label>"
html << select(name, name, object.all.collect {|p| [ p.name, p.id ] }, { :include_blank => (blank == true ? true : false)})
html << "</div>"
end
2011-08-16 20:05:58 +02:00
def select_field_table(object,field,table_choices,choice,blank)
model_name = eval(object.class.model_name)
html = ""
html << "<div class=\"param_group\">"
html << "<label class=\"label\">#{model_name.human_attribute_name(field)}</label>"
html << select(object.class.to_s.downcase, field, options_for_select(table_choices,choice), {:include_blank => blank})
html << "</div>"
end
2011-07-29 20:05:47 +02:00
#def form_simle_field(name,label,value)
# html = ""
# html << "<div class=\"group\">"
# html << "<label class=\"label\">#{label}</label>"
# html << "<input class=\"text_field\" type=\"text\" value=\"#{value}\">"
# html << "</div>"
#end
def nav_to_folders
2011-08-16 20:05:58 +02:00
link_to( t(:folders,:scope=>:folder), :controller=>:folders, :action=>:index )
2011-07-29 20:05:47 +02:00
end
def nav_to_messages
2011-08-16 20:05:58 +02:00
link_to( t(:messages,:scope=>:message), :controller=>:messages, :action=>:index )
2011-07-29 20:05:47 +02:00
end
def nav_to_compose
2011-08-16 20:05:58 +02:00
link_to( t(:compose,:scope=>:compose), :controller=>:messages, :action=>:compose )
2011-07-29 20:05:47 +02:00
end
def nav_to_contacts
2011-08-16 20:05:58 +02:00
link_to( t(:contacts,:scope=>:contact), contacts_path )
2011-07-29 20:05:47 +02:00
end
def nav_to_prefs
2011-09-03 13:07:40 +02:00
link_to( t(:prefs,:scope=>:prefs), prefs_look_path )
2011-07-29 20:05:47 +02:00
end
def main_navigation(active)
s = ""
s += "<ul class=\"wat-cf\">"
active == :messages ? s += "<li class=\"first active\">#{nav_to_messages}</li>" : s += "<li class=\"first\">#{nav_to_messages}</li>"
active == :compose ? s += "<li class=\"active\">#{nav_to_compose}</li>" : s += "<li>#{nav_to_compose}</li>"
active == :folders ? s += "<li class=\" active\">#{nav_to_folders}</li>" : s += "<li class=\"first\">#{nav_to_folders}</li>"
active == :contacts ? s += "<li class=\"active\">#{nav_to_contacts}</li>" : s += "<li>#{nav_to_contacts}</li>"
active == :prefs ? s += "<li class=\"active\">#{nav_to_prefs}</li>" : s += "<li>#{nav_to_prefs}</li>"
# active == :filters ? s += "<li class=\"active\">#{link_mail_filters}</li>" : s += "<li>#{link_mail_filters}</li>"
s += "</ul>"
end
2011-09-03 13:07:40 +02:00
def prefs_navigation(active)
look_active = ""
identity_active = ""
servers_active = ""
case active
when :look
look_active = "active"
when :identity
identity_active ="active"
when :servers
servers_active ="active"
end
s = ""
s += "<ul class=\"wat-cf\">"
s += "<li class=\"first #{look_active}\">#{link_to( t(:look,:scope=>:prefs), prefs_look_path )}</li>"
s += "<li class=\"#{identity_active}\">#{link_to( t(:identity,:scope=>:prefs), prefs_identity_path )}</li>"
s += "<li class=\"last #{servers_active}\">#{link_to( t(:servers,:scope=>:prefs), prefs_servers_path )}</li>"
s += "</ul>"
end
2011-07-29 20:05:47 +02:00
def multi_select(id, name, objects, selected_objects, label, value,joiner,content = {})
options = ""
objects.each do |o|
selected = selected_objects.include?(o) ? " selected=\"selected\"" : ""
option_value = escape_once(o.send(value))
text = [option_value]
unless content[:text].nil?
text = []
content[:text].each do |t|
text << o.send(t)
end
text = text.join(joiner)
end
text.gsub!(/^\./,'')
bracket = []
unless content[:bracket].nil?
content[:bracket].each do |b|
bracket << o.send(b)
end
bracket = bracket.join(joiner)
end
option_content = bracket.empty? ? "#{text}" : "#{text} (#{bracket})"
options << "<option value=\"#{option_value}\"#{selected}>&nbsp;&nbsp;#{option_content}&nbsp;&nbsp;</option>\n"
end
2011-09-03 13:07:40 +02:00
"<div class=\"param_group\"><label class=\"label\">#{label}</label><select multiple=\"multiple\" size=10 id=\"#{id}\" name=\"#{name}\">\n#{options}</select></div>"
end
def force_charset(text)
begin
Iconv.iconv("UTF-8",$defaults["msg_unknown_charset"],text)
rescue
text
end
2011-07-29 20:05:47 +02:00
end
end