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)
|
||||
|
||||
Reference in new issue
Block a user