2016-06-29 06:57:45 +00:00
|
|
|
class SeminarSignupField
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Mongoid::Attributes::Dynamic
|
|
|
|
include ::AttributeFieldsHelper
|
|
|
|
include ::Admin::SeminarsFieldHelper
|
|
|
|
|
|
|
|
field :key, type: String
|
2023-04-12 03:33:32 +00:00
|
|
|
field :sort_number, type: Integer
|
2023-01-11 09:44:40 +00:00
|
|
|
# field :af_count
|
2016-06-29 06:57:45 +00:00
|
|
|
field :title, type: String, localize: true
|
|
|
|
field :markup, default: "text_field"
|
2023-04-12 03:33:32 +00:00
|
|
|
field :option_list, type: Hash, default: {}
|
2016-06-29 06:57:45 +00:00
|
|
|
field :markup_options, type: Hash
|
|
|
|
field :built_in, type: Boolean, default: false
|
|
|
|
field :disabled, type: Boolean, default: false
|
2023-01-11 09:44:40 +00:00
|
|
|
# field :to_delete, type: Boolean, default: false
|
2023-10-07 14:34:07 +00:00
|
|
|
|
2016-06-29 06:57:45 +00:00
|
|
|
field :to_require,type: Boolean, default: true
|
2023-10-07 14:34:07 +00:00
|
|
|
|
2016-06-29 06:57:45 +00:00
|
|
|
field :typeA, type: Hash, default: {cross_lang: false}
|
|
|
|
field :typeB, type: Hash, default: {}
|
|
|
|
field :typeC, type: Hash, default: {calendar: "west_calendar", format: "format3"}
|
|
|
|
field :typeD, type: Hash, default: {cross_lang: false}
|
|
|
|
field :typeE, type: Hash, default: {}
|
2021-04-24 10:41:50 +00:00
|
|
|
field :typeF, type: Hash, default: {}
|
2016-06-29 06:57:45 +00:00
|
|
|
belongs_to :seminar_main
|
|
|
|
has_many :seminar_signup_values, autosave: true, dependent: :destroy
|
2019-11-26 15:52:52 +00:00
|
|
|
accepts_nested_attributes_for :seminar_signup_values, :allow_destroy => true
|
2023-04-12 03:33:32 +00:00
|
|
|
index({seminar_main_id: 1, sort_number: 1, _id: 1, disabled: -1}, { unique: false, background: false })
|
2016-06-29 06:57:45 +00:00
|
|
|
before_save :check_option_list
|
2023-01-11 09:44:40 +00:00
|
|
|
before_save do |record|
|
|
|
|
record.instance_variable_set(:@key_changed, record.key_changed?)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
after_save do |record|
|
|
|
|
if record.instance_variable_get(:@key_changed)
|
|
|
|
record.seminar_signup_values.update_all(:key=>record.key)
|
|
|
|
end
|
|
|
|
end
|
2016-06-29 06:57:45 +00:00
|
|
|
def markup_value
|
|
|
|
get_data["option_list"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_more
|
|
|
|
(get_data["add_more"] == "true" ? true : false) rescue false
|
|
|
|
end
|
|
|
|
|
|
|
|
def locale
|
2023-09-27 16:18:01 +00:00
|
|
|
tmp = get_data
|
|
|
|
!tmp || get_data["cross_lang"] == "true" ? false : true
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self_defined_markup_options?
|
|
|
|
(self.seminar.method(self[:key].pluralize.to_sym) && self.seminar.method(self[:key].pluralize+"_for_"+markup)) rescue false
|
|
|
|
end
|
|
|
|
|
|
|
|
def option_list
|
|
|
|
if self_defined_markup_options?
|
2023-10-07 14:34:07 +00:00
|
|
|
#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
|
2016-06-29 06:57:45 +00:00
|
|
|
method = self.seminar.method(self[:key].pluralize+"_for_"+markup)
|
|
|
|
return (method.call rescue {})
|
|
|
|
elsif self[:option_list].nil? || (self[:option_list].empty?)
|
|
|
|
return {}
|
|
|
|
else
|
|
|
|
return self[:option_list]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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 panel
|
2021-04-24 10:41:50 +00:00
|
|
|
panel = $seminar_list[:markups][self[:markup]]["panel"]
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_data
|
|
|
|
self[panel]
|
|
|
|
end
|
|
|
|
|
|
|
|
def typeA=(var)
|
|
|
|
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
|
2023-10-07 14:34:07 +00:00
|
|
|
|
2016-06-29 06:57:45 +00:00
|
|
|
def is_disabled?
|
|
|
|
self.disabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.add_seminar_signup_field(seminar,seminar_param, seminar_signup_field_id=nil,field_status)
|
|
|
|
@field_name = 'seminar'
|
|
|
|
if field_status.eql?(true)
|
|
|
|
@seminar_signup_field = self.find(seminar_signup_field_id) rescue nil
|
2023-01-11 09:44:40 +00:00
|
|
|
if @seminar_signup_field.nil?
|
|
|
|
@seminar_signup_field = seminar.seminar_signup_fields.build(seminar_param)
|
|
|
|
@seminar_signup_field.save
|
|
|
|
else
|
|
|
|
@seminar_signup_field.update(seminar_param)
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
else
|
2023-01-11 09:44:40 +00:00
|
|
|
@seminar_signup_field = seminar.seminar_signup_fields.build(seminar_param)
|
|
|
|
@seminar_signup_field.save
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
return @seminar_signup_field
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
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
|
2023-10-07 14:34:07 +00:00
|
|
|
cross_lang_convert(:to_cross_lang)
|
2016-06-29 06:57:45 +00:00
|
|
|
else #from add_more to no-add_more
|
|
|
|
cross_lang_convert(:to_no_cross_lang)
|
|
|
|
end # of case
|
|
|
|
end # of if
|
|
|
|
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
|
2023-10-07 14:34:07 +00:00
|
|
|
add_more_convert(:to_add_more)
|
2016-06-29 06:57:45 +00:00
|
|
|
else #from add_more to no-add_more
|
|
|
|
add_more_convert(:to_no_add_more)
|
|
|
|
end # of case
|
|
|
|
end # of if
|
|
|
|
end
|
|
|
|
|
2023-10-07 14:34:07 +00:00
|
|
|
def cross_lang_convert(opt)
|
|
|
|
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_option_list
|
|
|
|
self[:option_list] = self[panel]["option_list"] rescue nil
|
|
|
|
end
|
|
|
|
|
2023-10-07 14:34:07 +00:00
|
|
|
def add_more_convert(opt)
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2023-10-07 14:34:07 +00:00
|
|
|
end
|