module ActiveScaffold::DataStructures class Column include ActiveScaffold::Configurable attr_reader :active_record_class # this is the name of the getter on the ActiveRecord model. it is the only absolutely required attribute ... all others will be inferred from this name. attr_accessor :name # Whether to enable inplace editing for this column. Currently works for text columns, in the List. attr_reader :inplace_edit def inplace_edit=(value) self.clear_link if value @inplace_edit = value end # Whether this column set is collapsed by default in contexts where collapsing is supported attr_accessor :collapsed # AST allow_add_existing # Whether to enable add_existing for this column attr_accessor :allow_add_existing @allow_add_existing = true # Any extra parameters this particular column uses. This is for create/update purposes. def params # lazy initialize @params ||= Set.new end # the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form. # if left alone it will utilize human_attribute_name which includes localization for :scope => [:activerecord, :attributes] attr_writer :label # AST - still figuring out just exactly how to do this def label(options = {:count => 1}) # as_(@label, options)# || active_record_class.human_attribute_name(name.to_s) as_(@label) || active_record_class.human_attribute_name(name.to_s) end # a textual description of the column and its contents. this will be displayed with any associated form input widget, so you may want to consider adding a content example. attr_writer :description def description if @description @description else I18n.t name, :scope => [:activerecord, :description, active_record_class.to_s.underscore.to_sym], :default => '' end end # this will be /joined/ to the :name for the td's class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names. attr_accessor :css_class # whether the field is required or not. used on the form for visually indicating the fact to the user. # TODO: move into predicate attr_writer :required def required? @required end # sorting on a column can be configured four ways: # sort = true default, uses intelligent sorting sql default # sort = false sometimes sorting doesn't make sense # sort = {:sql => ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending. # sort = {:method => ""} define ruby-side code for sorting. this is SLOW with large recordsets! def sort=(value) if value.is_a? Hash value.assert_valid_keys(:sql, :method) @sort = value else @sort = value ? true : false # force true or false end end def sort self.initialize_sort if @sort === true @sort end def sortable? sort != false && !sort.nil? end # a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax. def sort_by(options) self.sort = options end # supported options: # * for association columns # * :select - displays a simple