add datagrid partials to allow pretty tables

This commit is contained in:
Felix Van der Jeugt 2015-09-10 13:53:27 +02:00
parent b2936f7645
commit 870fb16f00
7 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,11 @@
<%#
Indent in this file may cause extra space to appear.
You can add indent if whitespace doesn't matter for you
%>
<%- elements.each do |value, text, checked| -%>
<%- id = [form.object_name, filter.name, value].join('_').underscore -%>
<%= form.label filter.name, options.merge(:for => id) do -%>
<%= form.check_box(filter.name, form.datagrid_extra_checkbox_options.merge(:multiple => true, :id => id, :checked => checked), value.to_s, nil) -%>
<%= text -%>
<%- end -%>
<%- end -%>

View file

@ -0,0 +1,14 @@
<%= form_for grid, options do |f| -%>
<% grid.filters.each do |filter| %>
<div class="datagrid-filter filter">
<%= f.datagrid_label filter %>
<%= f.datagrid_filter filter, partials: options[:partials] %>
</div>
<% end %>
<div class="datagrid-actions">
<%= f.submit I18n.t("datagrid.form.search").html_safe, :class => "datagrid-submit" %>
<%# https://github.com/rails/rails/pull/14949 -%>
<% empty_parameter = Rails.version >= "4.1.0" && Rails.version <= '4.1.2' ? nil : {}-%>
<%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => empty_parameter), :class => "datagrid-reset" %>
</div>
<% end -%>

View file

@ -0,0 +1,8 @@
<tr>
<% grid.html_columns(*options[:columns]).each do |column| %>
<th class="<%= datagrid_column_classes(grid, column) %>">
<%= column.header %>
<%= datagrid_order_for(grid, column, options) if column.supports_order? && options[:order]%>
</th>
<% end %>
</tr>

View file

@ -0,0 +1,10 @@
<div class="order">
<%= link_to(
I18n.t("datagrid.table.order.asc").html_safe,
url_for(grid.param_name => grid.as_query.merge(:order => column.name, :descending => false)),
:class => "asc") %>
<%= link_to(
I18n.t("datagrid.table.order.desc").html_safe,
url_for(grid.param_name => grid.as_query.merge(:order => column.name, :descending => true )),
:class => "desc") %>
</div>

View file

@ -0,0 +1,3 @@
<%= form.text_field(filter.name, from_options) %>
<span class="separator <%= filter.type %>"> - </span>
<%= form.text_field(filter.name, to_options) %>

View file

@ -0,0 +1,5 @@
<tr class="<%= options[:cycle] && cycle(*options[:cycle]) %>">
<% grid.html_columns(*options[:columns]).each do |column| %>
<td class="<%= datagrid_column_classes(grid, column) %>"><%= datagrid_value(grid, column, asset) %></td>
<% end %>
</tr>

View file

@ -0,0 +1,18 @@
<%#
Local variables:
* grid - instance of Datagrid
* assets - Array of database Entities
* options - passed options Hash
%>
<%= content_tag :table, options[:html] do %>
<thead>
<%= datagrid_header(grid, options) %>
</thead>
<tbody>
<% if assets.any? %>
<%= datagrid_rows(grid, assets, options) %>
<% else %>
<tr><td class="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
<% end %>
</tbody>
<% end %>