2011-04-28 14:47:34 +00:00
|
|
|
class AttributeValue
|
|
|
|
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2012-10-08 08:58:33 +00:00
|
|
|
include Mongoid::MultiParameterAttributes
|
2011-04-28 14:47:34 +00:00
|
|
|
|
|
|
|
field :key
|
|
|
|
|
2011-12-23 10:34:21 +00:00
|
|
|
belongs_to :attribute_field
|
|
|
|
belongs_to :user
|
2012-10-08 08:58:33 +00:00
|
|
|
|
|
|
|
before_save :check_key
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
|
2012-10-08 08:58:33 +00:00
|
|
|
|
|
|
|
def check_key
|
|
|
|
self.key = attribute_field.key
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(*field)
|
|
|
|
if field.size < 1
|
|
|
|
self[field[0]]
|
|
|
|
else
|
|
|
|
self[(field[0].to_s.delete "=")] = field[1]
|
|
|
|
end
|
2011-12-23 10:34:21 +00:00
|
|
|
end
|
2011-04-28 14:47:34 +00:00
|
|
|
|
2012-10-08 08:58:33 +00:00
|
|
|
def get_value_by_locale(locale)
|
|
|
|
case self.attribute_field.markup
|
|
|
|
when "text_field"
|
|
|
|
self.attribute_field.locale ? self[locale] : self[:value]
|
|
|
|
when "select"
|
|
|
|
self.attribute_field.markup_value[self[:value]][locale.to_s] || NoData
|
2012-10-12 10:09:02 +00:00
|
|
|
when "text_area"
|
|
|
|
#self[:value]
|
2012-10-08 08:58:33 +00:00
|
|
|
when "date"
|
|
|
|
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i)
|
|
|
|
when "addr"
|
|
|
|
self[:value]
|
2012-10-12 10:09:02 +00:00
|
|
|
when "radio_button"
|
|
|
|
self[:value]
|
|
|
|
when "checkbox"
|
|
|
|
self[:value]
|
|
|
|
when "date_durnation"
|
|
|
|
self[:value]
|
2012-10-08 08:58:33 +00:00
|
|
|
else
|
|
|
|
self.attribute_field.locale ? self[locale] : self[:value]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_values
|
2012-10-12 10:09:02 +00:00
|
|
|
if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"]
|
2012-10-08 08:58:33 +00:00
|
|
|
return Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
|
|
|
|
else
|
|
|
|
return self[:value]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-28 14:47:34 +00:00
|
|
|
end
|