add new member with role interface. add more not usable.
role management new attribute is ok. delete is ok.
This commit is contained in:
1 parent
fe0e49c3e9
commit
beb843f75b
25 files changed
+1159
-512
No files matched your search
@@ -11,6 +11,7 @@ class Attribute
|
||||
has_many :attribute_fields, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
|
||||
|
||||
|
||||
def is_built_in?
|
||||
self.built_in
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -10,11 +10,56 @@ class AttributeValue
|
||||
belongs_to :user
|
||||
|
||||
before_save :check_key
|
||||
|
||||
before_save :data_proc
|
||||
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
|
||||
|
||||
|
||||
def data_proc
|
||||
# binding.pry
|
||||
# binding.pry if self.attribute_field.markup == 'radio_button'
|
||||
if self.attribute_field.locale
|
||||
case self.attribute_field.markup
|
||||
when 'text_field','text_area'
|
||||
# binding.pry
|
||||
self[:temp_data].each{|key,val|
|
||||
self[key] = val
|
||||
} unless self[:temp_data].nil?
|
||||
when 'select','date','radio_button'
|
||||
self["val"] = self[:temp_data]
|
||||
when 'checkbox'
|
||||
self["val"] = self[:temp_data].keys rescue {}
|
||||
end #end of case
|
||||
else # if not locale
|
||||
case self.attribute_field.markup
|
||||
when 'text_field','text_area'
|
||||
self["val"] = self[:temp_data]
|
||||
when 'select','date','radio_button'
|
||||
self["val"] = self[:temp_data]
|
||||
when 'checkbox'
|
||||
self["val"] = self[:temp_data].keys rescue {}
|
||||
end #end of case
|
||||
end
|
||||
self.unset('temp_data')
|
||||
end
|
||||
|
||||
def value
|
||||
|
||||
result=""
|
||||
if self.attribute_field.locale && (self.attribute_field.markup == "text_field" || self.attribute_field.markup == "text_area")
|
||||
result= Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
|
||||
else
|
||||
result = self["val"]
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
#save everything to temp_data waiting for futher process
|
||||
# binding
|
||||
self[:temp_data] = value
|
||||
end
|
||||
|
||||
def check_key
|
||||
binding.pry if attribute_field.nil?
|
||||
self.key = attribute_field.key
|
||||
end
|
||||
|
||||
@@ -27,45 +72,46 @@ class AttributeValue
|
||||
end
|
||||
|
||||
def get_value_by_locale(locale)
|
||||
|
||||
case self.attribute_field.markup
|
||||
when "text_field"
|
||||
self.attribute_field.locale ? self[locale] : self[:value]
|
||||
self.attribute_field.locale ? self.value[locale.to_s] : self.value
|
||||
when "select"
|
||||
markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : eval(self.attribute_field.markup_value)
|
||||
markup_values[self[:value]][locale.to_s] rescue 'NoData'
|
||||
markup_values[self.value][locale.to_s] rescue 'NoData'
|
||||
when "text_area"
|
||||
self.attribute_field.locale ? self[locale] : self[:value]
|
||||
self.attribute_field.locale ? self.value[locale.to_s] : self.value
|
||||
when "date"
|
||||
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i) rescue nil
|
||||
Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
|
||||
when "addr"
|
||||
self[:value]
|
||||
self.value
|
||||
when "radio_button"
|
||||
markup_values = eval(self.attribute_field.markup_value)
|
||||
markup_values[self[:value].first[0]][locale.to_s]
|
||||
when "checkbox"
|
||||
markup_values[self.value][locale.to_s]
|
||||
when "checkbox"
|
||||
markup_values = eval(self.attribute_field.markup_value)
|
||||
self[:value].keys.collect{|key| markup_values[key][locale.to_s] }.join(",")
|
||||
self.value.collect{|key| markup_values[key][locale.to_s] }.join(",")
|
||||
when "date_durnation"
|
||||
self[:value]
|
||||
self.value
|
||||
else
|
||||
self.attribute_field.locale ? self[locale] : self[:value]
|
||||
self.attribute_field.locale ? self.value[locale.to_s] : self.value
|
||||
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
|
||||
# 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
|
||||
|
||||
end
|
||||
@@ -38,7 +38,8 @@ class User
|
||||
before_save :save_roles
|
||||
scope :remote_account, where(:nccu_id.ne => nil)
|
||||
|
||||
validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
|
||||
# validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
|
||||
|
||||
# def new_attribute_values=(vars)
|
||||
# binding.pry
|
||||
# end
|
||||
|
||||
Reference in new issue
Block a user