2011-12-23 10:34:21 +00:00
|
|
|
class AttributeField
|
|
|
|
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2012-10-15 05:54:29 +00:00
|
|
|
include ::AttributeFieldsHelper
|
2012-10-08 08:58:33 +00:00
|
|
|
|
2011-12-23 10:34:21 +00:00
|
|
|
field :key
|
2012-10-12 10:09:02 +00:00
|
|
|
field :markup
|
2012-10-08 08:58:33 +00:00
|
|
|
field :markup_value ,:type => Hash
|
2012-10-12 10:09:02 +00:00
|
|
|
field :markup_options,:type => Hash
|
2011-12-23 10:34:21 +00:00
|
|
|
field :locale, :type => Boolean, :default => true
|
2012-10-12 10:09:02 +00:00
|
|
|
# field :list_options, :type => Array
|
2011-12-23 10:34:21 +00:00
|
|
|
field :built_in, :type => Boolean, :default => false
|
|
|
|
field :disabled, :type => Boolean, :default => false
|
2012-10-12 10:09:02 +00:00
|
|
|
field :add_more,:type => Boolean, :default => false
|
|
|
|
|
2012-09-13 10:39:27 +00:00
|
|
|
#field :title, localize: true
|
|
|
|
|
|
|
|
field :locale_title, localize: true
|
|
|
|
field :neutral_title
|
|
|
|
|
2012-01-24 07:12:06 +00:00
|
|
|
belongs_to :attribute
|
2012-09-17 04:06:21 +00:00
|
|
|
# belongs_to :role
|
2011-12-23 10:34:21 +00:00
|
|
|
has_many :attribute_values
|
|
|
|
|
|
|
|
# validates_uniqueness_of :key
|
2012-10-12 10:09:02 +00:00
|
|
|
|
|
|
|
def markup_options=(var)
|
|
|
|
self[:markup_options] = (eval(var) rescue {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def markup_options
|
|
|
|
if self[:markup_options].nil?
|
|
|
|
return {}
|
|
|
|
else
|
|
|
|
Hash[self[:markup_options].map{|key,val|[key.to_sym,val]}] rescue {}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-09-17 04:06:21 +00:00
|
|
|
def role
|
|
|
|
self.attribute.role
|
|
|
|
end
|
|
|
|
|
2012-09-13 10:39:27 +00:00
|
|
|
def title_translations
|
|
|
|
if locale
|
|
|
|
return locale_title_translations
|
|
|
|
else
|
|
|
|
return Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def title_translations=(var)
|
|
|
|
if locale
|
2012-09-17 04:06:21 +00:00
|
|
|
self.locale_title_translations = var
|
2012-09-13 10:39:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
if locale
|
|
|
|
return self.locale_title
|
|
|
|
else
|
|
|
|
return self.neutral_title
|
|
|
|
end
|
|
|
|
end
|
2012-10-12 10:09:02 +00:00
|
|
|
|
2012-09-13 10:39:27 +00:00
|
|
|
def title=(var)
|
2012-10-08 08:58:33 +00:00
|
|
|
# binding.pry
|
2012-09-13 10:39:27 +00:00
|
|
|
if locale
|
|
|
|
self.locale_title = var
|
|
|
|
else
|
|
|
|
self.neutral_title = var
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
# # Convert the string list_options into an array
|
|
|
|
# def select_list_options=(var)
|
|
|
|
# self.list_options = var.gsub(' ', '').split(',')
|
|
|
|
# end
|
2011-12-23 10:34:21 +00:00
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
# # Convert the array list_options into a string
|
|
|
|
# def select_list_options
|
|
|
|
# self.list_options.to_a.join(', ')
|
|
|
|
# end
|
2011-12-23 10:34:21 +00:00
|
|
|
|
|
|
|
def is_built_in?
|
|
|
|
self.built_in
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_disabled?
|
|
|
|
self.disabled
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|