lib/qadmin/helper.rb in quirkey-qadmin-0.1.0 vs lib/qadmin/helper.rb in quirkey-qadmin-0.1.1

- old
+ new

@@ -1,13 +1,14 @@ -module Qadmin - module Helper +module Qadmin + module Helper + include ::Qadmin::Options def fieldset(legend = nil, options = {}, &block) - content_tag(:fieldset, options) do + concat(content_tag_for(:fieldset, options) do content_tag(:legend, legend) if legend - yield - end + capture(&block) + end) end def admin_controls(name, options = {}, &block) return if respond_to?(:overlay?) && overlay? controller = options[:controller] || name.to_s.tableize @@ -47,9 +48,46 @@ concat(html,block.binding) else html << %{</ul>} html end + end + + def sortable_column_header(attribute_name, options = {}) + + end + + + def admin_table(collection, options = {}) + html = '<table>' + html << '<tr>' + attributes = options[:attributes] || model_klass.column_names + attributes.each_with_index do |attribute, i| + html << (i == 0 ? '<th class="first_col">' : '<th>') + html << sortable_column_header(attribute) + html << '</th>' + end + html << %{ + <th>View</th> + <th>Edit</th> + <th>Delete</th> + </tr> + } + collection.each do |instance| + html << %{<tr id="#{dom_id(instance)}" #{alt_rows}>} + attributes.each_with_index do |attribute, i| + if i == 0 + html << %{<td class="first_col">#{link_to(instance.send(attribute), send("#{model_instance_name}_path", instance))}</td>} + else + html << %{<td>#{h(instance.send(attribute))}</td>} + end + end + html << %{<td>#{link_to(image_tag('admin/icon_show.png'), send("#{model_instance_name}_path", instance))}</td>} + html << %{<td>#{link_to(image_tag('admin/icon_edit.png'), send("edit_#{model_instance_name}_path", instance))}</td>} + html << %{<td>#{link_to(image_tag('admin/icon_destroy.png'), send("#{model_instance_name}_path", instance), :confirm => 'Are you sure?', :method => :delete)}</td>} + html << '</tr>' + end + html << '</table>' end def alt_rows %{class="#{cycle('alt', '')}"} end \ No newline at end of file