lib/ab_admin/config/base.rb in ab_admin-0.6.1 vs lib/ab_admin/config/base.rb in ab_admin-0.7.0
- old
+ new
@@ -18,12 +18,12 @@
end
def self.default_for_model(model, options={})
new.tap do |builder|
builder.field(:id) unless options[:skip].try(:include?, :id)
- model.content_columns.each do |column|
- column_name = column.name.to_sym
+ model.column_names.each do |column|
+ column_name = column.to_sym
next if options[:skip].try(:include?, column_name)
builder.field(column_name)
end
end
end
@@ -38,11 +38,13 @@
self.partial_name = 'search_form'
end
class Export < BaseBuilder
def render_options
- {column_names: fields.map(&:name), column_data: fields.map(&:data), column_separator: options[:column_separator]}
+ {column_names: fields.map(&:name), column_data: fields.map(&:data),
+ column_separator: options[:column_separator], worksheet_name: options[:worksheet_name],
+ filename: options[:filename]}
end
end
class Form < BaseBuilder
self.partial_name = 'form'
@@ -106,16 +108,19 @@
false
end
end
class BatchAction
- attr_reader :name, :options, :data, :title
+ attr_reader :name, :options, :data, :title, :form
def initialize(name, options={}, &block)
@name = name
@options = options
- @title = options[:title] || I18n.t("admin.actions.batch_#{name}.link")
+ if options.has_key?(:form)
+ @form = options[:form].is_a?(String) ? options[:form] : "##{name}_batch_form"
+ end
+ @title = options[:title] || I18n.t("admin.actions.batch_#{name}.link", default: name.to_s.humanize)
@data = block_given? ? block : name.to_sym
end
def confirm
options[:confirm]
@@ -150,7 +155,22 @@
def collection?
options[:collection]
end
end
+
+ class Scope
+ attr_reader :name, :options, :data
+
+ def initialize(name, options={}, &block)
+ @name = name
+ @options = options
+ @data = block
+ end
+
+ def apply(relation, params)
+ return relation unless params[name].present?
+ data.is_a?(Proc) ? data.call(relation, params) : relation.public_send(name)
+ end
+ end
end
-end
\ No newline at end of file
+end