2011-09-03 13:07:40 +02:00
|
|
|
require 'iconv'
|
|
|
|
|
2009-01-07 20:27:12 +01:00
|
|
|
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 = ""
|
2011-09-29 21:16:40 +02:00
|
|
|
html << "<div class=\"param_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=\""
|
2011-09-10 20:31:55 +02:00
|
|
|
value = val || object.instance_eval(field) || ""
|
2011-07-23 21:55:26 +02:00
|
|
|
html << value
|
|
|
|
html << "\"/>"
|
|
|
|
html << "<span class=\"description\">"
|
2011-09-10 20:31:55 +02:00
|
|
|
html << t(:example,:scope=>:common)
|
2011-07-23 21:55:26 +02:00
|
|
|
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
|
2011-09-10 20:31:55 +02:00
|
|
|
value = val || object.instance_eval(field) || ""
|
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
|
|
|
|
2011-09-10 20:31:55 +02:00
|
|
|
desc = t(:example,:scope=>:common) + ": " + example
|
2011-08-24 19:20:13 +02:00
|
|
|
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-09 22:10:25 +02:00
|
|
|
def single_action(text,scope,image)
|
|
|
|
html = ""
|
|
|
|
html << "<div class=\"actiongroup wat-cf\">"
|
|
|
|
html << "<button class=\"button\" name=\"#{text}\" type=\"submit\">"
|
|
|
|
html << "<img src=\""
|
|
|
|
html << current_theme_image_path(image)
|
|
|
|
html << "\" alt=\""
|
|
|
|
html << t(text.to_sym, :scope => scope.to_sym)
|
|
|
|
html << "\" />"
|
|
|
|
html << t(text.to_sym, :scope => scope.to_sym)
|
|
|
|
html << "</button></div>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def single_action_onclick(text,scope,image,onclick)
|
|
|
|
html = ""
|
|
|
|
html << "<div class=\"actiongroup 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 << t(text.to_sym, :scope => scope.to_sym)
|
|
|
|
html << "\" />"
|
|
|
|
html << t(text.to_sym, :scope => scope.to_sym)
|
|
|
|
html << "</button></div>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_action(buttons)
|
|
|
|
html = ""
|
|
|
|
html << "<div class=\"actiongroup 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,:scope=>b[:scope].to_sym)
|
|
|
|
html << "\" />"
|
|
|
|
html << t(b[:text].to_sym,:scope=>b[:scope].to_sym)
|
|
|
|
html << "</button> "
|
|
|
|
end
|
|
|
|
html << "</div>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_action_text(buttons,text)
|
|
|
|
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,:scope=>b[:scope].to_sym)
|
|
|
|
html << "\" />"
|
|
|
|
html << t(b[:text].to_sym,:scope=>b[:scope].to_sym)
|
|
|
|
html << "</button> "
|
|
|
|
end
|
|
|
|
html << text
|
|
|
|
html << "</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-09-09 22:10:25 +02:00
|
|
|
def select_field_table_t(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>"
|
|
|
|
t = []
|
|
|
|
table_choices.each do |c|
|
|
|
|
t << [t(c.to_sym,:scope=>:prefs),c.to_s]
|
|
|
|
end
|
|
|
|
html << select(object.class.to_s.downcase, field, options_for_select(t,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
|
|
|
|
|
2011-09-09 22:10:25 +02:00
|
|
|
#def nav_to_folders
|
|
|
|
# link_to( t(:folders,:scope=>:folder), :controller=>:folders, :action=>:index )
|
|
|
|
#end
|
|
|
|
#
|
|
|
|
#def nav_to_messages
|
|
|
|
# link_to( t(:messages,:scope=>:message), :controller=>:messages, :action=>:index )
|
|
|
|
#end
|
|
|
|
#
|
|
|
|
#def nav_to_compose
|
|
|
|
# link_to( t(:compose,:scope=>:compose), :controller=>:messages, :action=>:compose )
|
|
|
|
#end
|
|
|
|
#
|
|
|
|
#def nav_to_contacts
|
|
|
|
# link_to( t(:contacts,:scope=>:contact), contacts_path )
|
|
|
|
#end
|
|
|
|
#
|
|
|
|
#def nav_to_prefs
|
|
|
|
# link_to( t(:prefs,:scope=>:prefs), prefs_look_path )
|
|
|
|
#end
|
2011-07-29 20:05:47 +02:00
|
|
|
|
2011-09-16 19:44:29 +02:00
|
|
|
def single_navigation(label,scope)
|
|
|
|
s = ""
|
|
|
|
s += "<ul class=\"wat-cf\">"
|
|
|
|
s += "<li class=\"first active\">#{link_to(t(label,:scope=>scope),'#')}</li>"
|
|
|
|
s += "<li class=\"last\"> </li>"
|
|
|
|
s += "</ul>"
|
|
|
|
end
|
|
|
|
|
2011-07-29 20:05:47 +02:00
|
|
|
def main_navigation(active)
|
2011-09-09 22:10:25 +02:00
|
|
|
instance_variable_set("@#{active}", "active")
|
2011-07-29 20:05:47 +02:00
|
|
|
s = ""
|
|
|
|
s += "<ul class=\"wat-cf\">"
|
2011-09-09 22:10:25 +02:00
|
|
|
s += "<li class=\"first #{@messages_tab}\">#{link_to( t(:messages,:scope=>:message), messages_path )}</li>"
|
|
|
|
s += "<li class=\"#{@compose_tab}\">#{link_to( t(:compose,:scope=>:compose), compose_path )}</li>"
|
|
|
|
s += "<li class=\"#{@folders_tab}\">#{link_to( t(:folders,:scope=>:folder), folders_path )}</li>"
|
|
|
|
s += "<li class=\"#{@contacts_tab}\">#{link_to( t(:contacts,:scope=>:contact), contacts_path )}</li>"
|
|
|
|
s += "<li class=\"last #{@prefs_tab}\">#{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}</li>"
|
2011-07-29 20:05:47 +02:00
|
|
|
s += "</ul>"
|
|
|
|
end
|
|
|
|
|
2011-09-03 13:07:40 +02:00
|
|
|
def prefs_navigation(active)
|
2011-09-09 22:10:25 +02:00
|
|
|
instance_variable_set("@#{active}", "active")
|
2011-09-03 13:07:40 +02:00
|
|
|
s = ""
|
|
|
|
s += "<ul class=\"wat-cf\">"
|
2011-09-09 22:10:25 +02:00
|
|
|
s += "<li class=\"first #{@look_tab}\">#{link_to( t(:look,:scope=>:prefs), prefs_look_path )}</li>"
|
|
|
|
s += "<li class=\"#{@identity_tab}\">#{link_to( t(:identity,:scope=>:prefs), prefs_identity_path )}</li>"
|
|
|
|
s += "<li class=\"last #{@servers_tab}\">#{link_to( t(:servers,:scope=>:prefs), prefs_servers_path )}</li>"
|
2011-09-03 13:07:40 +02:00
|
|
|
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}> #{option_content} </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
|
|
|
|
|
2011-09-09 22:10:25 +02:00
|
|
|
def content_for_sidebar
|
2011-09-16 19:44:29 +02:00
|
|
|
s = render :partial => 'sidebar/logo'
|
|
|
|
s += render :partial => 'folders/list'
|
|
|
|
s += render :partial => 'sidebar/calendar_view'
|
2011-09-09 22:10:25 +02:00
|
|
|
s += render :partial => 'internal/version'
|
|
|
|
s
|
|
|
|
end
|
|
|
|
|
2011-09-24 22:13:45 +02:00
|
|
|
def boolean_answer(answer)
|
|
|
|
answer == true ? t(:true_answer,:scope=>:common) : t(:false_answer,:scope=>:common)
|
|
|
|
end
|
2011-07-29 20:05:47 +02:00
|
|
|
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|