disable data transform when switching attribute field type. new member stable
This commit is contained in:
1 parent
edf38644c9
commit
77386f0284
12 files changed
+174
-95
No files matched your search
@@ -30,12 +30,7 @@ class AttributeField
|
||||
end
|
||||
|
||||
def locale
|
||||
default = true
|
||||
if get_data["locale"].nil?
|
||||
return default
|
||||
else
|
||||
(get_data["locale"] == "true" ? true : false) rescue default
|
||||
end
|
||||
get_data["cross_lang"] == "true" ? false : true
|
||||
end
|
||||
|
||||
def self_defined_markup_options?
|
||||
@@ -107,56 +102,63 @@ protected
|
||||
end
|
||||
|
||||
def add_more_convert(opt)
|
||||
case opt
|
||||
when :to_add_more
|
||||
self.attribute_values.each do |av|
|
||||
VALID_LOCALES.each do |loc|
|
||||
splited_str = av[loc].split(",") rescue []
|
||||
av["val"] = [] if av["val"].nil?
|
||||
splited_str.each_with_index{|value,index| av["val"][index] = av["val"][index].nil? ? {loc=>value} : av["val"][index].merge(loc=>value) }
|
||||
end
|
||||
av.unset_all_lang_values
|
||||
av.save
|
||||
end #of self.attribute_values.each
|
||||
when :to_no_add_more
|
||||
self.attribute_values.each do |av|
|
||||
VALID_LOCALES.each do |loc|
|
||||
if av["val"].kind_of? Array
|
||||
av[loc] = av["val"].collect{|t| t[loc]}.join(",")
|
||||
else
|
||||
av[loc] = av["val"]
|
||||
end
|
||||
end
|
||||
av.unset("val")
|
||||
av.save
|
||||
end #of self.attribute_values.each
|
||||
end
|
||||
# case opt
|
||||
# when :to_add_more
|
||||
# self.attribute_values.each do |av|
|
||||
# VALID_LOCALES.each do |loc|
|
||||
# splited_str = av[loc].split(",") rescue []
|
||||
# av["val"] = [] if av["val"].nil?
|
||||
|
||||
# old_data = av["val"]
|
||||
# av["val"] = []
|
||||
# splited_str.each_with_index do |value,index|
|
||||
# av["val"][index] = {loc=>value}
|
||||
# end
|
||||
# av["val"] << old_data
|
||||
# end
|
||||
# av.unset_all_lang_values
|
||||
# av.save
|
||||
# end #of self.attribute_values.each
|
||||
# when :to_no_add_more
|
||||
# self.attribute_values.each do |av|
|
||||
# VALID_LOCALES.each do |loc|
|
||||
# binding.pry
|
||||
# if av["val"].kind_of? Array
|
||||
# av[loc] = av["val"].collect{|t| t[loc]}.join(",")
|
||||
# else
|
||||
# av[loc] = av["val"]
|
||||
# end
|
||||
# end
|
||||
# av.unset("val")
|
||||
# av.save
|
||||
# end #of self.attribute_values.each
|
||||
# end
|
||||
end
|
||||
|
||||
def cross_lang_convert(opt)
|
||||
case opt
|
||||
when :to_cross_lang
|
||||
self.attribute_values.each do |av|
|
||||
if add_more
|
||||
av["val"] = av["val"].collect{|t| t.invert.keys.join(",")}
|
||||
else
|
||||
av["val"] = VALID_LOCALES.collect{|t| av[t]}.join(",")
|
||||
av.unset_all_lang_values
|
||||
end
|
||||
av.save
|
||||
end #of self.attribute_values.each
|
||||
when :to_no_cross_lang
|
||||
default_locale = I18n.default_locale.to_s
|
||||
self.attribute_values.each do |av|
|
||||
if add_more
|
||||
av["val"] = av["val"].collect{|t| {default_locale => t} } #unless av["val"].nil?
|
||||
else
|
||||
av[default_locale] = av["val"]
|
||||
av.unset("val")
|
||||
end
|
||||
av.save
|
||||
end #of self.attribute_values.each
|
||||
end
|
||||
# case opt
|
||||
# when :to_cross_lang
|
||||
# self.attribute_values.each do |av|
|
||||
# if add_more
|
||||
# av["val"] = av["val"].collect{|t| t.invert.keys.join(",")}
|
||||
# else
|
||||
# av["val"] = VALID_LOCALES.collect{|t| av[t]}.join(",")
|
||||
# av.unset_all_lang_values
|
||||
# end
|
||||
# av.save
|
||||
# end #of self.attribute_values.each
|
||||
# when :to_no_cross_lang
|
||||
# default_locale = I18n.default_locale.to_s
|
||||
# self.attribute_values.each do |av|
|
||||
# if add_more
|
||||
# av["val"] = av["val"].collect{|t| {default_locale => t} } #unless av["val"].nil?
|
||||
# else
|
||||
# av[default_locale] = av["val"]
|
||||
# av.unset("val")
|
||||
# end
|
||||
# av.save
|
||||
# end #of self.attribute_values.each
|
||||
# end
|
||||
end
|
||||
|
||||
def check_add_more_convert(var)
|
||||
|
||||
@@ -49,7 +49,12 @@ class AttributeValue
|
||||
when "text_field"
|
||||
case self.attribute_field.add_more
|
||||
when true
|
||||
add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale]
|
||||
if self.attribute_field.locale
|
||||
add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale]
|
||||
else
|
||||
add_more_index.nil? ? self.value.join(",") : self.value(add_more_index)
|
||||
end
|
||||
|
||||
when false
|
||||
self.attribute_field.locale ? self[locale.to_s] : self.value
|
||||
end
|
||||
@@ -62,7 +67,11 @@ class AttributeValue
|
||||
self.attribute_field.locale ? self[locale.to_s] : self.value
|
||||
|
||||
when "date"
|
||||
get_date_by_format
|
||||
if self.attribute_field.date_is_range?
|
||||
get_date_by_format(:from) + ' ~ ' + get_date_by_format(:to)
|
||||
else
|
||||
get_date_by_format
|
||||
end
|
||||
|
||||
when "address"
|
||||
self.value[locale.to_s]
|
||||
@@ -83,6 +92,18 @@ class AttributeValue
|
||||
end
|
||||
end
|
||||
|
||||
def get_date(item = nil)
|
||||
case item
|
||||
when :from
|
||||
data = self[:val]["from"]
|
||||
when :to
|
||||
data = self[:val]["to"]
|
||||
when nil
|
||||
data = self[:val]
|
||||
end
|
||||
Date.new(data["(1i)"].to_i,data["(2i)"].to_i,data["(3i)"].to_i) rescue nil
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
@@ -130,9 +151,4 @@ def unset_all_lang_values
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def get_date
|
||||
Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user