module Qadmin module Helper include ::Qadmin::Options def fieldset(legend = nil, options = {}, &block) concat(content_tag_for(:fieldset, options) do content_tag(:legend, legend) if legend capture(&block) end) end def admin_controls(name, options = {}, &block) return if respond_to?(:overlay?) && overlay? controller = options[:controller] || name.to_s.tableize assumed_object = self.instance_variable_get "@#{name}" obj = options[:object] || assumed_object || nil parent = options[:parent] || false parent_link_attributes = parent ? {parent.class.to_s.foreign_key => parent.id} : {} general_link_attributes = {:controller => controller}.merge(parent_link_attributes) control_links = { :index => link_to(image_tag('admin/icon_list.png') + " Back to List", general_link_attributes.merge(:action => 'index')), :new => link_to(image_tag('admin/icon_new.png') + " New", general_link_attributes.merge(:action => 'new')), :edit => link_to(image_tag('admin/icon_edit.png') + " Edit", general_link_attributes.merge(:action => 'edit', :id => obj)), :show => link_to(image_tag('admin/icon_show.png') + " View", general_link_attributes.merge(:action => 'show', :id => obj)), :destroy => link_to(image_tag('admin/icon_destroy.png') + " Delete", general_link_attributes.merge(:action => 'destroy', :id => obj), :confirm => 'Are you sure?', :method => :delete), :ports => link_to(image_tag('admin/icon_export.png') + " Import/Export", general_link_attributes.merge(:action => 'ports')) } control_sets = { :index => [:new], :new => [:index], :edit => [:index,:new,:show,:destroy], :show => [:index,:new,:edit,:destroy] } control_set = (options[:for] ? control_sets[options[:for]] : options[:controls]) control_set << :ports if options[:ports] controls = Array(control_set).collect {|c| control_links[c] }.compact html = "" html << %{} concat(html,block.binding) else html << %{} html end end def sortable_column_header(attribute_name, options = {}) end def admin_table(collection, options = {}) html = '' html << '' attributes = options[:attributes] || model_klass.column_names attributes.each_with_index do |attribute, i| html << (i == 0 ? '' end html << %{ } collection.each do |instance| html << %{} attributes.each_with_index do |attribute, i| if i == 0 html << %{} else html << %{} end end html << %{} html << %{} html << %{} html << '' end html << '
' : '') html << sortable_column_header(attribute) html << 'View Edit Delete
#{link_to(instance.send(attribute), send("#{model_instance_name}_path", instance))}#{h(instance.send(attribute))}#{link_to(image_tag('admin/icon_show.png'), send("#{model_instance_name}_path", instance))}#{link_to(image_tag('admin/icon_edit.png'), send("edit_#{model_instance_name}_path", instance))}#{link_to(image_tag('admin/icon_destroy.png'), send("#{model_instance_name}_path", instance), :confirm => 'Are you sure?', :method => :delete)}
' end def alt_rows %{class="#{cycle('alt', '')}"} end end end