module AutoAdminDjangoTheme extend AutoAdmin::ThemeHelpers def self.directory(*subdirs) File.join(File.dirname(File.dirname(__FILE__)), 'themes', 'django', *subdirs) end helper do def history_link record link = "(Unnamed #{human_model(record.model).downcase})" link = record.object_label unless record.object_label.blank? link = link_to h(link), :model => record.model, :action => 'edit', :id => record.obj_id unless record.change == 'delete' link end def history_link_class record case record.change when 'add'; 'addlink' when 'delete'; 'deletelink' else 'changelink' end end end class FormProcessor < AutoAdminSimpleTheme::FormProcessor end class FormBuilder < AutoAdminSimpleTheme::FormBuilder def fieldset_class(style) case style when :fields then 'module aligned' when :table then 'module' end end def wrap_field(field_type, field_name, options) options[:class] = options[:class] ? options[:class].dup : '' if field_name column = model.find_column( field_name ) assoc = model.reflect_on_association( field_name.to_sym ) column_type = ( assoc && assoc.macro ) || ( column && column.type ) end case field_type when :text_field case column_type when :string options[:class] << ' vTextField' options[:size] ||= 30 options[:maxlength] ||= column.limit when :integer, :decimal options[:class] << ' vIntegerField' options[:size] ||= 10 when :text options[:class] << ' vTextField' options[:size] ||= 50 end when :text_area options[:class] << ' vLargeTextField' when :check_box options[:class] << ' vCheckboxField' when :date_select options[:class] << ' vDateField' when :datetime_select options[:class] << ' vTimeField' when :select options[:class] << ' vSelectMultipleField' if options[:multiple] end #.vFileUploadField { border:none; } #.vURLField { width:380px; } #.vLargeTextField, .vXMLLargeTextField { width:480px; } options[:class].strip! inner = super inner << %(
#{h options[:caption]}
) if options[:caption] if field_name && field_invalid?(field_name) %(| #{link} | ) else %(#{yield} | ) end end end end
|---|