add new member with role interface. add more not usable.

role management new attribute is ok. delete is ok.
This commit is contained in:
Matthew K. Fu JuYuan authored and chris committed 2012-11-04 20:42:58 +08:00
1 parent fe0e49c3e9
commit beb843f75b
25 files changed
+1159 -512

No files matched your search

+66 -36
View File
@@ -5,26 +5,38 @@ class AttributeField
include ::AttributeFieldsHelper
field :key
field :markup
field :markup_value ,:type => Hash
field :markup ,:default=>"text_field"
field :option_list ,:type => Hash,:default => {}
field :markup_options,:type => Hash
field :locale, :type => Boolean, :default => true
# 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 :add_more,:type => Boolean, :default => false
field :to_delete,:type=> Boolean,:default => false
field :typeA,:type=> Hash,:default=>{}
field :typeB,:type=> Hash,:default=>{}
field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar"}
field :typeD,:type=> Hash,:default=>{}
field :typeE,:type=> Hash,:default=>{}
#field :title, localize: true
field :locale_title, localize: true
field :neutral_title
field :neutral_for
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 add_more
(get_data["add_more"] == "true" ? true : false) rescue false
end
def locale
(get_data["locale"] == "true" ? true : false) rescue false
end
def self_defined_markup_options?
(self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false
@@ -36,16 +48,16 @@ class AttributeField
end
end
def markup_value
def option_list
if self_defined_markup_options?
#Class need to have corresponding field and value agent
# Ex: For "status" the class must have field called "statuses" for the relation and "statuses_for_select" for the select function
method = self.attribute.role.method(self[:key].pluralize+"_for_"+markup)
return (method.call rescue {})
elsif self[:markup_value].nil? || (self[:markup_value].empty?)
elsif self[:option_list].nil? || (self[:option_list].empty?)
return {}
else
return self[:markup_value]
return self[:option_list]
end
end
@@ -68,36 +80,49 @@ class AttributeField
self.attribute.role
end
def title_translations
if locale
return locale_title_translations
else
return Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
end
def panel
panel = LIST[:markups][self[:markup]]["panel"]
end
def title_translations=(var)
if locale
self.locale_title_translations = var
end
def get_data
self[panel]
end
def title
if locale
return self.locale_title
else
return self.neutral_title
end
end
def title=(var)
# binding.pry
if locale
self.locale_title = var
else
self.neutral_title = var
end
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)
@@ -117,4 +142,9 @@ class AttributeField
self.disabled
end
protected
def check_option_list
self[:option_list] = self[panel]["option_list"]
end
end