module EasyAdminUi module ViewHelpers def table(items, columns, actions, options = {}, &block) html = ''.html_safe html << table_head(columns, actions, options) html << render(:collection => items, :partial => options[:partial]) html << my_table_end html end def table_head(columns, actions, options = {}) options[:class] ||= 'easy' html = ''.html_safe html << "".html_safe html << content_tag(:thead, content_tag(:tr, ( columns.map do |title, th_class| th_class ||= [] content_tag(:th, [ if th_class.include?('sortable') content_tag(:div, link_to('', '#', :class => 'sort_up') + link_to('', '#', :class => 'sort_down'), {:class => 'sort'}) else nil end, title ].compact.join('').html_safe, :class => th_class) end ).join('').html_safe + (actions ? content_tag(:th, '', :class => 'actions') : '') ) ) html << options[:body_id] ? "" : '' html end def table_row(options = {}) options[:actions] ||= [] content_tag(:tr, [ # Could pass: # # [category.created_at, {:class => '', :onmouseover => "javascript: blah"}] # [category.created_at, 'my_class_name'] # options[:cells].map do |txt, cell_opts| cell_opts = {:class => cell_opts} if cell_opts.is_a?(String) cell_opts ||= {} content_tag(:td, txt, cell_opts) end, options[:actions].blank? ? '' : content_tag(:td, options[:actions].join(' ').html_safe, :class => "act") ].join(' ').html_safe, :id => options[:id], :class => ["#{cyc = cycle("even", "odd")}", options[:class]].join(' ')).html_safe end def my_table_end '
'.html_safe end def right_align(content) [content, 'aright'] end def admin_show_link(item) link_to(image_tag("/images/icons/show.png"), :action => 'show', :id => item) end def admin_new_link content_tag(:span, raw(' - ') + link_to('New', :action => 'new')) end def admin_edit_link(item) link_to(image_tag("/images/icons/pencil.png"), :action => 'edit', :id => item) end # Use if below /admin/. def admin_delete_link_with_confirmation(obj, delete_path=nil) delete_path ||= eval("admin_#{obj.class.to_s.underscore}_path(obj)") delete_link_with_confirmation(obj, delete_path) end def delete_link_with_confirmation(obj, delete_path=nil) delete_path ||= eval("#{obj.class.to_s.underscore.singularize}_path(obj)") link_to_function(image_tag('/images/icons/delete.png'), "$('#cnf_#{obj.id}').show();") + ' ' + raw('') end end end