new code for attribute fields and values for new member interface

This commit is contained in:
Matthew K. Fu JuYuan authored and chris committed 2012-10-26 11:19:55 +08:00
1 parent 293dc80ceb
commit 8b9cffd4f2
15 files changed
+226 -116

No files matched your search

+28 -11
View File
@@ -5,12 +5,15 @@ class AttributeField
include AttributeFieldHelper
field :key
field :markup #[select,text_field,email,date,addr]
field :markup
field :markup_value ,:type => Hash
field :markup_options,:type => Hash
field :locale, :type => Boolean, :default => true
field :list_options, :type => Array
# field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :add_more,:type => Boolean, :default => false
#field :title, localize: true
field :locale_title, localize: true
@@ -21,6 +24,20 @@ class AttributeField
has_many :attribute_values
# validates_uniqueness_of :key
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
def role
self.attribute.role
end
@@ -46,7 +63,7 @@ class AttributeField
return self.neutral_title
end
end
def title=(var)
# binding.pry
if locale
@@ -56,15 +73,15 @@ class AttributeField
end
end
# Convert the string list_options into an array
def select_list_options=(var)
self.list_options = var.gsub(' ', '').split(',')
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
# # Convert the array list_options into a string
# def select_list_options
# self.list_options.to_a.join(', ')
# end
def is_built_in?
self.built_in
+10 -4
View File
@@ -11,7 +11,7 @@ class AttributeValue
before_save :check_key
NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
def check_key
self.key = attribute_field.key
@@ -31,19 +31,25 @@ class AttributeValue
self.attribute_field.locale ? self[locale] : self[:value]
when "select"
self.attribute_field.markup_value[self[:value]][locale.to_s] || NoData
when "email"
self[:value]
when "text_area"
#self[:value]
when "date"
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i)
when "addr"
self[:value]
when "radio_button"
self[:value]
when "checkbox"
self[:value]
when "date_durnation"
self[:value]
else
self.attribute_field.locale ? self[locale] : self[:value]
end
end
def get_values
if self.attribute_field.locale && !(NO_MULTI_TAG.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,self[lang.to_sym]]}]
else
return self[:value]