2010-05-19 16:17:45 +00:00
|
|
|
module Admin::CustomFieldsHelper
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-10-07 00:45:41 +00:00
|
|
|
def options_for_field_kind
|
2011-05-19 15:44:04 +00:00
|
|
|
%w(string text category boolean date file has_one has_many).map do |kind|
|
2011-03-04 23:29:40 +00:00
|
|
|
[t("custom_fields.kind.#{kind}"), kind]
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
2010-05-19 16:17:45 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
def options_for_order_by(content_type, collection_name)
|
2010-10-30 22:30:30 +00:00
|
|
|
options = %w{created_at updated_at _position_in_list}.map do |type|
|
2010-05-25 00:32:12 +00:00
|
|
|
[t("admin.content_types.form.order_by.#{type.gsub(/^_/, '')}"), type]
|
|
|
|
end
|
|
|
|
options + options_for_highlighted_field(content_type, collection_name)
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-03-09 23:54:38 +00:00
|
|
|
def options_for_order_direction
|
|
|
|
%w(asc desc).map do |direction|
|
|
|
|
[t("admin.content_types.form.order_direction.#{direction}"), direction]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
def options_for_highlighted_field(content_type, collection_name)
|
|
|
|
custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym
|
|
|
|
collection = content_type.send(custom_fields_collection_name)
|
2010-10-30 22:30:30 +00:00
|
|
|
collection.delete_if { |f| f.label == 'field name' || f.kind == 'file' }
|
2010-05-25 00:32:12 +00:00
|
|
|
collection.map { |field| [field.label, field._name] }
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
def options_for_group_by_field(content_type, collection_name)
|
|
|
|
custom_fields_collection_name = "ordered_#{collection_name.singularize}_custom_fields".to_sym
|
|
|
|
collection = content_type.send(custom_fields_collection_name)
|
|
|
|
collection.delete_if { |f| not f.category? }
|
|
|
|
collection.map { |field| [field.label, field._name] }
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-22 13:04:40 +00:00
|
|
|
def options_for_text_formatting
|
2011-03-09 23:54:38 +00:00
|
|
|
options = %w(none html).map do |option|
|
2010-06-22 13:04:40 +00:00
|
|
|
[t("admin.custom_fields.text_formatting.#{option}"), option]
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-05-19 15:44:04 +00:00
|
|
|
def options_for_association_target
|
2011-06-01 21:43:12 +00:00
|
|
|
current_site.content_types.collect do |c|
|
|
|
|
c.persisted? ? [c.name, c.content_klass.to_s] : nil
|
|
|
|
end.compact
|
2011-05-19 15:44:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def options_for_has_one(field)
|
|
|
|
target_contents_from_field(field).collect { |c| [c._label, c._id] }
|
|
|
|
end
|
|
|
|
|
|
|
|
alias :options_for_has_many :options_for_has_one
|
|
|
|
|
|
|
|
def target_contents_from_field(field)
|
|
|
|
content_type = field.target.constantize._parent
|
|
|
|
content_type.ordered_contents
|
|
|
|
end
|
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|