address field. js and style is broken

This commit is contained in:
Matthew K. Fu JuYuan authored and chris committed 2012-11-20 09:53:36 +08:00
1 parent be448d42c9
commit a85e5fcc0d
14 files changed
+386 -311

No files matched your search

+83 -100
View File
@@ -1,5 +1,4 @@
class AttributeField
include Mongoid::Document
include Mongoid::Timestamps
include ::AttributeFieldsHelper
@@ -8,8 +7,6 @@ class AttributeField
field :markup ,:default=>"text_field"
field :option_list ,:type => Hash,:default => {}
field :markup_options,:type => Hash
# field :locale, :type => Boolean, :default => true
# field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :to_delete,:type=> Boolean,:default => false
@@ -18,18 +15,11 @@ class AttributeField
field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar",:format=>"format3"}
field :typeD,:type=> Hash,:default=>{:cross_lang=>false}
field :typeE,:type=> Hash,:default=>{}
#field :title, localize: true
field :title, localize: true
belongs_to :attribute
# belongs_to :role
has_many :attribute_values,:autosave => true, :dependent => :destroy
before_save :check_option_list
# validates_uniqueness_of :key
def markup_value
get_data["option_list"]
@@ -52,12 +42,6 @@ class AttributeField
(self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false
end
# def markup_value=(var)
# if !self_defined_markup_options?
# self[:markup_value] = (eval(var) rescue {})
# end
# end
def option_list
if self_defined_markup_options?
#Class need to have corresponding field and value agent
@@ -71,8 +55,6 @@ class AttributeField
end
end
def markup_options=(var)
self[:markup_options] = (eval(var) rescue {})
end
@@ -99,92 +81,18 @@ class AttributeField
end
# def title_translations
# if locale
# return self.locale_title_translations
# else
# return self[:neutral_title] #Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
# end
# end
# def title_translations=(var)
# if locale
# self.locale_title_translations = var
# end
# end
# def title
# if locale
# return self.locale_title
# else
# return self.neutral_title
# end
# end
# def check_title
# if locale
# self.locale_title_translations = self[:temp_title]
# else
# self.neutral_title = self[:temp_title]
# end
# self.unset("temp_title")
# end
# def title=(var)
# self["temp_title"] = var
# end
# # Convert the string list_options into an array
# def select_list_options=(var)
# self.list_options = var.gsub(' ', '').split(',')
# end
# # Convert the array list_options into a string
# def select_list_options
# self.list_options.to_a.join(', ')
# 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) }
# av[loc] = Hash[splited_str.each_with_index.map{|t,index| [index.to_s,t]}] rescue {"0"=>av[loc].to_s}
end
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
# av[loc] = av["val"].invert.keys.join(",") rescue av["val"]
# av.save(:validate => false)
end
av.unset("val")
av.save
end #of self.attribute_values.each
end
end
def typeA=(var)
if self["typeA"]["add_more"] != var["add_more"]
case var["add_more"]
when "true" #from no-add_more to add_more
add_more_convert(:to_add_more)
else #from add_more to no-add_more
add_more_convert(:to_no_add_more)
end # of case
end # of if
check_add_more_convert(var)
check_cross_lang_convert(var,"typeA")
self["typeA"] = var
end
def typeD=(var)
check_cross_lang_convert(var,"typeD")
self["typeD"] = var
end
def is_built_in?
self.built_in
end
@@ -195,7 +103,82 @@ class AttributeField
protected
def check_option_list
self[:option_list] = self[panel]["option_list"]
self[:option_list] = self[panel]["option_list"] rescue nil
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
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} }
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)
if self["typeA"]["add_more"] != var["add_more"]
case var["add_more"]
when "true" #from no-add_more to add_more
add_more_convert(:to_add_more)
else #from add_more to no-add_more
add_more_convert(:to_no_add_more)
end # of case
end # of if
end
def check_cross_lang_convert(var,field)
if self[field]["cross_lang"] != var["cross_lang"]
case var["cross_lang"]
when "true" #from no-add_more to add_more
cross_lang_convert(:to_cross_lang)
else #from add_more to no-add_more
cross_lang_convert(:to_no_cross_lang)
end # of case
end # of if
end
end
+47 -51
View File
@@ -12,35 +12,13 @@ class AttributeValue
before_save :data_proc
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
def add_more_counter
index_max = self["val"].count rescue 0
index_max == 0 ? 1 : index_max
end
def data_proc
unless self[:temp_data].nil?
case self.attribute_field.markup
when 'text_field','text_area'
if self.attribute_field.add_more
self["val"] = self["temp_data"]
else # if not add_more
self[:temp_data].each{|key,val|
self[key] = val
} if(!self.attribute_field.get_data[:cross_lang])
self["val"] = self[:temp_data] if(self.attribute_field.get_data[:cross_lang])
end # of self.attribute_field.add_more
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys
end #end of case self.attribute_field.markup
end # of self[:temp_data].nil?
self.unset('temp_data')
self.unset('temp')
end #of data_proc
def value(index = nil)
result = case self.attribute_field.markup
when 'text_field','text_area'
@@ -48,7 +26,7 @@ class AttributeValue
index.nil? ? self["val"] : self["val"][index]
# self.attribute_field.get_data[:cross_lang] ? Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] : self["val"] #if !self.attribute_field.get_data[:cross_lang]
else
self.attribute_field.get_data[:cross_lang] ? self["val"] : Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
self.attribute_field.get_data["cross_lang"] =="true" ? self["val"] : Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
end
when 'select','date','radio_button'
self["val"]
@@ -62,17 +40,6 @@ class AttributeValue
self[:temp_data] = value
end
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
end
def get_value_by_locale(locale,add_more_index=nil)
@@ -106,23 +73,52 @@ class AttributeValue
end
end
# def get_values
# unless ['select','checkbox','radio_button'].include?(self.attribute_field.markup )
# if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"]
# return Hash[VALID_LOCALES.collect{|lang| [lang,get_value_by_locale(lang.to_sym)]}]
# else
# return get_value_by_locale("")
# end
# else
# if self.attribute_field.markup == "select"
# self[:value]
# else
# self[:value].keys rescue self[:value]
# end
# end
# end
protected
protected
def unset_all_lang_values
VALID_LOCALES.each{|t| self.unset t}
end
def data_proc
unless self[:temp_data].nil?
case self.attribute_field.markup
when 'text_field','text_area'
if self.attribute_field.add_more
self["val"] = self["temp_data"]
else # if not add_more
if self.attribute_field.can_muti_lang_input?
self[:temp_data].each do |key,val|
self[key] = val
end if(!self.attribute_field.get_data[:cross_lang])
else
self["val"] = self[:temp_data]
end
end # of self.attribute_field.add_more
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys
end #end of case self.attribute_field.markup
end # of self[:temp_data].nil?
self.unset('temp_data')
self.unset('temp')
end #of data_proc
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
end
def get_date
Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
end