module EasyAdminUi
module ViewHelpers
def wpaginate(collection)
will_paginate(collection, :previous_label => t('will_paginate.previous'), :next_label => t('will_paginate.next'))
end
def table_head(titles, actions, options = {:class => "easy"})
concat("
" +
content_tag(:thead,
content_tag(:tr, (
titles.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(''),
:class => th_class)
end
).join('') + (actions ? content_tag(:th, '', :class => 'actions') : '')
)
)
)
options[:body_id] ? concat("") : concat('')
yield
concat('
')
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(' '), :class => "act")
].join(' '),
:id => options[:id], :class => ["#{cyc = cycle("even", "odd")}", options[:class]].join(' '))
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, ' - ' + 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('Are you sure? ') +
link_to_remote("Yes", :url => delete_path, :method => :delete) + ' ' +
link_to_function("No", "$('cnf_#{obj.id}').hide();") + raw('')
end
end
end