Orbit/app/helpers/orbit_backend_helper.rb

45 lines
1.5 KiB
Ruby
Raw Normal View History

2012-04-29 15:39:28 +00:00
module OrbitBackendHelper
def sortable(column)
direction = (column == params[:sort] && params[:direction] == "asc") ? "desc" : "asc"
{:sort => column, :direction => direction}
end
def is_sort_active?(name)
res = ''
res << ' select' if params[:sort].eql?(name)
res << ' active' if params[:sort].eql?(name) && params[:direction].eql?('asc')
res
end
def is_sort?(name)
' web-symbol' if params[:sort].eql?(name)
end
def is_filter_active?(type, id)
' active' if (@filter[type].include?(id.to_s) rescue nil)
end
def render_sort_bar(delete_all, *titles)
2012-04-29 15:39:28 +00:00
content_tag :table, :class => "table main-list" do
content_tag :thead do
content_tag :tr, :class => "sort-header" do
concat (content_tag :th, :class => "span1 strong" do
2012-04-29 22:27:38 +00:00
concat check_box_tag :check_all
concat link_to content_tag(:i, nil, :class => "icon-trash"), '#', :class => "list-remove"
2012-04-29 15:39:28 +00:00
end) if delete_all
titles.each do |title|
concat render_title(title[0], title[1], title[2], title[3])
2012-04-29 15:39:28 +00:00
end
end
end
end
end
def render_title(title, fields, span, translation)
2012-04-29 15:39:28 +00:00
content_tag :th, :class => "sort #{span} #{is_sort_active?(title)}" do
link_to (t(translation) + content_tag(:b, nil, :class => is_sort?(title))).html_safe, url_for({:filter => @filter}.merge(sortable(title).merge(:sort_options => fields))), :class => 'js_history'
end
end
end