2012-02-04 01:10:55 +00:00
|
|
|
module Locomotive
|
|
|
|
module CustomFieldsHelper
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_custom_field_type
|
|
|
|
%w(string text select boolean date file belongs_to has_many many_to_many).map do |type|
|
2012-03-01 10:07:22 +00:00
|
|
|
[t("custom_fields.type.#{type}"), type]
|
2012-02-04 01:10:55 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_label_field(content_type)
|
|
|
|
content_type.ordered_entries_custom_fields.find_all do |field|
|
|
|
|
%w(string date).include?(field.type)
|
|
|
|
end.map do |field|
|
|
|
|
[field.label, field._id]
|
|
|
|
end
|
2011-08-11 20:45:46 +00:00
|
|
|
end
|
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_group_by_field(content_type)
|
|
|
|
content_type.ordered_entries_custom_fields.find_all do |field|
|
|
|
|
%w(select).include?(field.type)
|
|
|
|
end.map do |field|
|
|
|
|
[field.label, field._id]
|
|
|
|
end
|
2011-08-11 20:45:46 +00:00
|
|
|
end
|
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_order_by(content_type)
|
|
|
|
options = %w{created_at updated_at _position}.map do |type|
|
|
|
|
[t("locomotive.content_types.form.order_by.#{type.gsub(/^_/, '')}"), type]
|
|
|
|
end
|
|
|
|
options + options_for_label_field(content_type)
|
2011-06-23 23:17:08 +00:00
|
|
|
end
|
2011-05-19 15:44:04 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_order_direction
|
|
|
|
%w(asc desc).map do |direction|
|
|
|
|
[t("locomotive.content_types.form.order_direction.#{direction}"), direction]
|
|
|
|
end
|
2011-06-23 23:17:08 +00:00
|
|
|
end
|
2011-05-19 15:44:04 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_text_formatting
|
|
|
|
%w(none html).map do |option|
|
|
|
|
[t("locomotive.custom_fields.text_formatting.#{option}"), option]
|
|
|
|
end
|
2011-12-22 01:59:30 +00:00
|
|
|
end
|
2011-12-22 00:31:33 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_content_type
|
|
|
|
current_site.content_types.map do |c|
|
|
|
|
c != @content_type ? [c.name, c.klass_with_custom_fields(:entries).to_s] : nil
|
|
|
|
end.compact
|
|
|
|
end
|
2012-01-31 00:50:09 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_content_type_inverse_of
|
|
|
|
{}.tap do |hash|
|
|
|
|
current_site.content_types.where(:'entries_custom_fields.type'.in => %w(belongs_to many_to_many)).each do |content_type|
|
|
|
|
content_type.entries_custom_fields.each do |field|
|
|
|
|
if %w(belongs_to many_to_many).include?(field.type)
|
2012-03-01 10:07:22 +00:00
|
|
|
type = field.type == 'belongs_to' ? 'has_many' : field.type
|
|
|
|
hash[type] ||= []
|
|
|
|
hash[type] << {
|
2012-02-04 01:10:55 +00:00
|
|
|
:label => field.label,
|
|
|
|
:name => field.name,
|
|
|
|
:class_name => content_type.klass_with_custom_fields(:entries).to_s
|
|
|
|
}
|
|
|
|
end
|
2012-02-01 01:01:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-01-31 00:50:09 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
end
|
|
|
|
end
|