mailr/app/helpers/folder_helper.rb

73 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

2012-03-24 13:23:34 +01:00
module FolderHelper
2012-03-24 18:09:31 +01:00
def folder_link(options={})
folder = options[:folder]
active = ""
if options[:active]
active = "icon-white"
end
2012-03-24 13:23:34 +01:00
folder.parent.empty? ? name = folder.name : name = folder.parent.gsub(/\./,'#') + "#" + folder.name
if folder.isInbox?
2012-03-24 18:09:31 +01:00
name_shown = "<i class=\"icon-inbox #{active}\"></i>" + t(:inbox_name,:scope => :folder)
2012-03-24 13:23:34 +01:00
elsif folder.isSent?
2012-03-24 18:09:31 +01:00
name_shown = "<i class=\"icon-plane #{active}\"></i>" + t(:sent_name,:scope => :folder)
2012-03-24 13:23:34 +01:00
elsif folder.isDrafts?
2012-03-24 18:09:31 +01:00
name_shown = "<i class=\"icon-book #{active}\"></i>" + t(:drafts_name,:scope => :folder)
2012-03-24 13:23:34 +01:00
elsif folder.isTrash?
2012-03-24 18:09:31 +01:00
name_shown = "<i class=\"icon-trash #{active}\"></i>" +t(:trash_name,:scope => :folder)
2012-03-24 13:23:34 +01:00
else
2012-03-24 18:09:31 +01:00
name_shown = "<i class=\"icon-none\"></i>" + folder.name.capitalize
2012-03-24 13:23:34 +01:00
end
if folder.isTrash?
if not folder.total.zero?
name_shown += " <button class=\"btn btn-mini btn-danger\" onclick=\"window.location='#{folders_emptybin_path}'\" href=\"#\">#{t(:emptybin,:scope=>:folder)}</button>"
#name_shown += raw link_to(t(:emptybin,:scope=>:folder),folders_emptybin_path)
#name_shown += ')'
end
else
if !folder.unseen.zero?
name_shown += ' (' + folder.unseen.to_s + ')'
end
end
link_to name_shown.html_safe, folders_select_path(:id => name)
end
def pretty_folder_name(folder)
if folder.nil?
t(:no_selected,:scope=>:folder)
else
if folder.isInbox?
t(:inbox_name,:scope => :folder)
elsif folder.isSent?
t(:sent_name,:scope => :folder)
elsif folder.isDrafts?
t(:drafts_name,:scope => :folder)
elsif folder.isTrash?
t(:trash_name,:scope => :folder)
else
folder.name.capitalize
end
end
end
def select_for_folders(name,id,collection,label,choice,blank)
html = ""
html << "<div class=\"param_group\">"
html << "<label class=\"label\">#{label}</label>"
html << simple_select_for_folders(name,id,collection,choice,blank)
html << "</div>"
end
def simple_select_for_folders(name,id,collection,choice,blank)
html = ""
html << select(name , id, options_from_collection_for_select(collection, 'id', 'full_name', choice),{ :include_blank => (blank == true ? true : false)})
html
end
end