Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
HtmlTable
=========
A HtmlTable plugin that should easily tie in w/ authz routines (eg cancan).
It has 1 class & module: Formatter and Helpers.
Helpers provides #html_table_for and takes a collection and options hash as its only args.
Table columns must be based on db columns or AR associations/aggregations right now but translating eg Name => Group or Children => Sub-Groups is possible and by default any protected attributes are not shown in html ('id','type' by def. for all objects).
Using the Reflections module from Rails I was able to get a list of associations/aggregations.
Todo
====
test Helpers module
add the ability to add custom table columns
? get management links to show in own column
Example
=======
Columns can be blacklisted when html_table_for is called, eg:
:blacklist => ['Groups','Registered Memberships'].
Links to actions can also be blacklisted eg:
:edit_group_path => {
:blacklisted => false, # can? :update, Group
:use_obj => true,
:options => {
:class => 'fake_button'
}
}
<%=raw html_table_for(@groups, {
:blacklist => ['Groups','Registered Memberships'],
:column_map => {
:memberships => { # maps Group#memberships association to use Group#members instead
:column_name => 'Memberships', # keeps Memberships as the html column name
:method => :members
},
:name => {
:column_name => 'Group' # use Group instead of Name as the html column name
}
},
:table_options => {
:class => 'nice_table tablesorter'
},
:table_body_options => {
:management_link_methods => {
:new_group_membership_path => { # name of the path helper to build the link
:blacklisted => false, # authz check
:use_obj => true, # whether or not to pass the object from collection to the path helper
:text => 'add members',
:options => { # html options hash passed straight to #link_to
:class => 'fake_button'
}
},
:edit_group_path => {
:blacklisted => false, # authz check
:use_obj => true,
:options => {
:class => 'fake_button'
}
},
:group_path => {
:blacklisted => false, # authz check
:use_obj => true,
:text => 'delete',
:options => {
:class => 'fake_button',
:method => 'delete', # setup std rails delete link
:confirm => 'Are you sure you want to delete this group?'
}
}
}
}
}) %>
Copyright (c) 2010 [Jeremiah Heller], released under the MIT license