<%= stylesheet_link_tag("will_filter/filter") -%> <% if results.size > 0 %>
<%= paginate(results) %> Showing <%= results.offset_value + 1 %> - <%= results.offset_value + results.length %> of <%= results.total_count %>
<% carray = [] # stores the order of the columns opts[:columns].each_with_index do |column, index| cmeta = {} # supported notations for columns => [ # :id, # [:id, lambda{|obj| obj.id}], # [:id, lambda{|obj| obj.id}, "color: white"], # [:id, lambda{|obj| obj.id}, {:style => "color: white"}], # [:id, {:filterable => true, :value => lambda{|obj| obj.id}}], # [:id, {:filterable => true, :value => lambda{|obj| obj.id}}], # {:key => :id, :filterable => true} # ] if column.is_a?(Array) if column.size < 2 raise WillFilter::FilterException.new("Array table column definition must have at least two elements") end cmeta[:key] = column[0] # first param must always be the column key if column[1].is_a?(Hash) # second param is a hash cmeta.merge!(column[1]) else cmeta[:value] = column[1] unless column[2].nil? if column[2].is_a?(Hash) # third param can be a set of attributes cmeta.merge!(column[2]) elsif column[2].is_a?(String) # third param can be a string, which represents a style cmeta[:style] = column[2] else raise WillFilter::FilterException.new("Unsupported table column format #{column[2]}") end end end elsif column.is_a?(Hash) cmeta = column cmeta[:key] ||= "key_#{index}" else cmeta[:key] = column end carray << cmeta sort_direction = filter && filter.column_sorted?(cmeta[:key]) ? filter.order_type : "asc" sort_direction_click = filter && filter.column_sorted?(cmeta[:key]) ? (sort_direction == "asc" ? "desc" : "asc") : "asc" if cmeta[:sort_key] sort_key = cmeta[:sort_key].call(filter) else sort_key = cmeta[:key] end if cmeta[:sortable].nil? sortable = filter && filter.contains_column?(cmeta[:key]) else sortable = cmeta[:sortable] end if cmeta[:title].is_a?(Proc) column_title = cmeta[:title].call(filter) else # column_title = cmeta[:title] || filter ? filter.condition_title_for(cmeta[:key]) : "Undefined" if filter column_title = cmeta[:title] || filter.condition_title_for(cmeta[:key]) else column_title = cmeta[:title] || cmeta[:key].to_s.titleize end if sortable column_title = link_to(column_title, filter.to_params(:wf_order => cmeta[:key], :wf_order_type => sort_direction_click), :title => "sort by #{cmeta[:key]} ascending", :class => "sort_link") end end # column class name title_class_name = cmeta[:title_class] || cmeta[:key].to_s title_class_name << " sortable" if sortable title_class_name << " current_sort" if filter && filter.column_sorted?(sort_key) title_class_name << " #{sort_direction}" # extra styling that can be applied on a column title_style = cmeta[:title_style] || "" title_style << ";width:15px" if cmeta[:key] == :checkbox %> <% end %> <% if opts[:header] %> <%=render(:partial => "/will_filter/common/results_table_summary", :locals => {:data => opts[:header], :filter => filter, :carray => carray}) %> <% end -%> <% results.each_with_index do |obj, index| %> <% carray.each_with_index do |cmeta, column_index| %> <% value_style = cmeta[:style] || 'padding-top:2px;padding-bottom:2px;vertical-align:middle;' # should be moved to css value_class = cmeta[:class] || '' if cmeta[:value].nil? value = obj.send(cmeta[:key]) elsif cmeta[:value].is_a?(Proc) value = cmeta[:value].call(obj) else value = cmeta[:value] end value_style << 'width:30px;' if cmeta[:key] == :checkbox value_class << ' current_sort' if filter and filter.column_sorted?(cmeta[:key]) if cmeta[:filterable] filter_value = cmeta[:value].nil? ? value : obj.send(cmeta[:key]) end %> <% end -%> <% end -%> <% if opts[:footer] %> <%=render(:partial => "/will_filter/common/results_table_summary", :locals => {:data => opts[:footer], :filter => filter, :carray => carray}) %> <% end -%>
<% if sortable %>
<%= link_to "", filter.to_params(:wf_order => sort_key, :wf_order_type => 'asc'), :title => "sort by #{sort_key} ascending", :class => 'up' %> <%= link_to "", filter.to_params(:wf_order => sort_key, :wf_order_type => 'desc'), :title => "sort by #{sort_key} descending", :class => 'down' %>
<%= column_title %>
<% elsif cmeta[:key] == :checkbox %> <%= check_box_tag("wf_check_all", "", false, :onClick => "wfCheckAll(this)") %> <% else %> <%= column_title %> <% end %>
<% if cmeta[:filterable] %>
<%=link_to(image_tag("will_filter/filter.png", :style=>"width:12px;"), results.add_filter_condition(cmeta[:key], :is, filter_value.to_s).to_params, {:title => "Show only #{filter_value}"}) %>
<% end -%> <% if cmeta[:key] == :checkbox %> <%= check_box_tag("#{value}[]", obj.id, false, :id => "wf_check_#{index}", :onClick => "wfVerifyTrigger(this)") %> <% elsif value.is_a?(Hash) %> <% value.each do |key, value| %> <%=key%>: <%= value %>; <% end -%> <% elsif value.is_a?(Time) %> <%= value.strftime("%m/%d/%Y %l:%M:%S") %> <% elsif value.is_a?(Date) %> <%= value.strftime("%m/%d/%Y") %> <% else %> <%= value.to_s %> <% end -%>
<% else %>
No results found
<% end %>