2022-03-10 02:11:18 +00:00
|
|
|
class ApplicationFormSignupValue
|
2016-06-29 06:57:45 +00:00
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Mongoid::Attributes::Dynamic
|
|
|
|
include ::AttributeValuesHelper
|
2022-03-10 02:11:18 +00:00
|
|
|
include ::Admin::ApplicationFormsValuesHelper
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
field :key, type: String
|
|
|
|
|
2022-03-10 02:11:18 +00:00
|
|
|
belongs_to :application_form_signup_field
|
|
|
|
belongs_to :application_form_signup
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
before_save :check_key
|
|
|
|
before_save :data_proc
|
|
|
|
|
|
|
|
def add_more_counter
|
|
|
|
index_max = self["val"].count rescue 0
|
|
|
|
index_max == 0 ? 1 : index_max
|
|
|
|
end
|
|
|
|
|
|
|
|
def value(index = nil)
|
|
|
|
site = Site.first
|
2022-03-10 02:11:18 +00:00
|
|
|
result = case self.application_form_signup_field.markup
|
2016-06-29 06:57:45 +00:00
|
|
|
when 'text_field','text_area'
|
2022-03-10 02:11:18 +00:00
|
|
|
if self.application_form_signup_field.add_more and (self.application_form_signup_field.markup == "text_field")
|
2016-06-29 06:57:45 +00:00
|
|
|
index.nil? ? self["val"] : self["val"][index]
|
|
|
|
else
|
2022-03-10 02:11:18 +00:00
|
|
|
self.application_form_signup_field.get_data["cross_lang"] =="true" ? self["val"] : Hash[site.valid_locales.collect{|lang| [lang,self[lang.to_sym]]}]
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
when 'select','radio_button','address'
|
|
|
|
self["val"]
|
|
|
|
when 'date'
|
|
|
|
if !self["val"].blank? and !self["val"]['(1i)'].blank?
|
|
|
|
"#{self["val"]['(1i)']}/#{self["val"]['(2i)']}/#{self["val"]['(3i)']}"
|
|
|
|
else
|
|
|
|
self["val"]
|
|
|
|
end
|
|
|
|
when 'checkbox'
|
|
|
|
self["val"]
|
2022-03-10 02:11:18 +00:00
|
|
|
end #end of case self.application_form_signup_field.markup
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def value=(value)
|
|
|
|
#save everything to temp_data waiting for futher process
|
|
|
|
self[:temp_data] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_field_value
|
2022-03-10 02:11:18 +00:00
|
|
|
application_form_signup_field = self.application_form_signup_field
|
|
|
|
if (application_form_signup_field.markup.eql?("text_field") || application_form_signup_field.markup.eql?("text_area"))
|
2021-03-17 07:33:31 +00:00
|
|
|
if self.value.class == String
|
|
|
|
field_value = self.value
|
|
|
|
else
|
2016-06-29 06:57:45 +00:00
|
|
|
field_value = self.value[I18n.locale]
|
2021-03-17 07:33:31 +00:00
|
|
|
end
|
2022-03-10 02:11:18 +00:00
|
|
|
elsif (application_form_signup_field.markup.eql?("select") || application_form_signup_field.markup.eql?("radio_button"))
|
|
|
|
field_value = application_form_signup_field.markup_value["#{self.value}"][I18n.locale] rescue nil
|
|
|
|
elsif application_form_signup_field.markup.eql?("address")
|
2021-03-17 07:33:31 +00:00
|
|
|
field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ')
|
2022-03-10 02:11:18 +00:00
|
|
|
elsif application_form_signup_field.markup.eql?("date")
|
|
|
|
case application_form_signup_field.typeC['format']
|
2021-03-17 07:33:31 +00:00
|
|
|
when 'format1'
|
|
|
|
field_value = self.value.to_date.strftime("%Y/%m/%d")
|
|
|
|
when 'format2'
|
|
|
|
field_value = self.value.to_date.strftime("%Y/%m/%d")
|
|
|
|
when 'format3'
|
|
|
|
field_value = self.value.to_date.strftime("%Y/%m")
|
|
|
|
when 'format4'
|
|
|
|
field_value = self.value.to_date.strftime("%Y")
|
|
|
|
end
|
2022-03-10 02:11:18 +00:00
|
|
|
elsif application_form_signup_field.markup.eql?("checkbox")
|
|
|
|
field_value = self.value.map {|v| application_form_signup_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
field_value = (field_value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{field_value}' target='blank'>#{field_value}</a>" : field_value
|
|
|
|
field_value = (field_value =~ /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i) ? "<a href='mailto:#{field_value}'>#{field_value}</a>" : field_value
|
|
|
|
|
|
|
|
if !field_value.blank?
|
|
|
|
{
|
2022-03-10 02:11:18 +00:00
|
|
|
"key" => application_form_signup_field.key,
|
|
|
|
"title" => application_form_signup_field.title,
|
2016-06-29 06:57:45 +00:00
|
|
|
"value" => field_value,
|
|
|
|
"val" => field_value = self.value
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-10 02:11:18 +00:00
|
|
|
"key" => application_form_signup_field.key,
|
|
|
|
"title" => application_form_signup_field.title,
|
2016-06-29 06:57:45 +00:00
|
|
|
"value" => "",
|
|
|
|
"val" => field_value = self.value
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_value_by_locale(locale,add_more_index=nil)
|
2022-03-10 02:11:18 +00:00
|
|
|
application_form_signup_field = self.application_form_signup_field
|
|
|
|
case application_form_signup_field.markup
|
2016-06-29 06:57:45 +00:00
|
|
|
when "text_field"
|
2022-03-10 02:11:18 +00:00
|
|
|
case application_form_signup_field.add_more
|
2021-03-17 07:33:31 +00:00
|
|
|
when true
|
2022-03-10 02:11:18 +00:00
|
|
|
if application_form_signup_field.locale
|
2021-03-17 07:33:31 +00:00
|
|
|
add_more_index.nil? ? self.value.collect{|t| t[locale.to_s]}.join(",") : self.value(add_more_index)[locale]
|
|
|
|
else
|
|
|
|
add_more_index.nil? ? self.value.join(",") : self.value(add_more_index)
|
|
|
|
end
|
|
|
|
|
|
|
|
when false
|
2022-03-10 02:11:18 +00:00
|
|
|
application_form_signup_field.locale ? self[locale.to_s] : self.value
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
when "select"
|
2022-03-10 02:11:18 +00:00
|
|
|
markup_values = application_form_signup_field.self_defined_markup_options? ? application_form_signup_field.markup_value : self.application_form_signup_field.markup_value
|
2016-06-29 06:57:45 +00:00
|
|
|
markup_values[self.value][locale.to_s] rescue 'NoData'
|
|
|
|
|
|
|
|
when "text_area"
|
2022-03-10 02:11:18 +00:00
|
|
|
application_form_signup_field.locale ? self[locale.to_s] : self.value
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
when "date"
|
2022-03-10 02:11:18 +00:00
|
|
|
if application_form_signup_field.date_is_range?
|
2016-06-29 06:57:45 +00:00
|
|
|
get_date_by_format(:from) + ' ~ ' + get_date_by_format(:to)
|
|
|
|
# self.value["from"] + ' ~ ' + self.value["to"]
|
|
|
|
else
|
|
|
|
get_date_by_format
|
|
|
|
# self.value
|
|
|
|
end
|
|
|
|
|
|
|
|
when "address"
|
|
|
|
self.value[locale.to_s]
|
|
|
|
|
|
|
|
when "radio_button"
|
2022-03-10 02:11:18 +00:00
|
|
|
markup_values = application_form_signup_field.markup_value
|
2016-06-29 06:57:45 +00:00
|
|
|
markup_values[self.value][locale.to_s]
|
|
|
|
|
|
|
|
when "checkbox"
|
2022-03-10 02:11:18 +00:00
|
|
|
markup_values = application_form_signup_field.markup_value
|
2016-06-29 06:57:45 +00:00
|
|
|
self.value.collect{|key| markup_values["#{key}"][I18n.locale]}.join(",")
|
|
|
|
when "date_durnation"
|
|
|
|
self.value
|
|
|
|
|
|
|
|
else
|
2022-03-10 02:11:18 +00:00
|
|
|
application_form_signup_field.locale ? self[locale.to_s] : self.value
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_date(item = nil)
|
|
|
|
case item
|
|
|
|
when :from
|
|
|
|
# data = self[:val]["from"]
|
|
|
|
data = self.value["from"]
|
|
|
|
when :to
|
|
|
|
# data = self[:val]["to"]
|
|
|
|
data = self.value["to"]
|
|
|
|
when nil
|
|
|
|
# data = self[:val]
|
|
|
|
data = self.value
|
|
|
|
end
|
|
|
|
|
|
|
|
# Date.new(data["(1i)"].to_i,data["(2i)"].to_i,data["(3i)"].to_i) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.put_field_values(member, field_value_param, field_value_id=nil,field_value_status)
|
|
|
|
if field_value_status.eql?(true)
|
2022-03-10 02:11:18 +00:00
|
|
|
@application_form_signup_field_value = member.application_form_signup_values.find(field_value_id) rescue nil
|
|
|
|
if @application_form_signup_field_value!=nil
|
|
|
|
@application_form_signup_field_value.update(field_value_param) rescue nil
|
|
|
|
@application_form_signup_field_value.save rescue nil
|
2019-11-26 15:52:52 +00:00
|
|
|
end
|
2016-06-29 06:57:45 +00:00
|
|
|
else
|
2022-03-10 02:11:18 +00:00
|
|
|
@application_form_signup_field_value = member.application_form_signup_values.build(field_value_param) rescue nil
|
|
|
|
@application_form_signup_field_value.save
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
2022-03-10 02:11:18 +00:00
|
|
|
return @application_form_signup_field_value
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def unset_all_lang_values
|
|
|
|
VALID_LOCALES.each{|t| self.unset t}
|
|
|
|
end
|
|
|
|
|
|
|
|
def data_proc
|
2022-03-10 02:11:18 +00:00
|
|
|
application_form_signup_field = self.application_form_signup_field
|
2016-06-29 06:57:45 +00:00
|
|
|
unless self[:temp_data].nil?
|
2022-03-10 02:11:18 +00:00
|
|
|
case application_form_signup_field.markup
|
2016-06-29 06:57:45 +00:00
|
|
|
when "address"
|
|
|
|
self["val"] = self["temp_data"]
|
|
|
|
when 'text_field','text_area'
|
2022-03-10 02:11:18 +00:00
|
|
|
if application_form_signup_field.add_more
|
2016-06-29 06:57:45 +00:00
|
|
|
self["val"] = self["temp_data"]
|
|
|
|
else # if not add_more
|
2022-03-10 02:11:18 +00:00
|
|
|
if application_form_signup_field.can_muti_lang_input?
|
2016-06-29 06:57:45 +00:00
|
|
|
self[:temp_data].each do |key,val|
|
|
|
|
self[key] = val
|
2022-03-10 02:11:18 +00:00
|
|
|
end if(!application_form_signup_field.get_data[:cross_lang])
|
2016-06-29 06:57:45 +00:00
|
|
|
else
|
|
|
|
self["val"] = self[:temp_data]
|
|
|
|
end
|
2022-03-10 02:11:18 +00:00
|
|
|
end # of self.application_form_signup_field.add_more
|
2016-06-29 06:57:45 +00:00
|
|
|
|
|
|
|
when 'select','date','radio_button'
|
|
|
|
self["val"] = self[:temp_data]
|
|
|
|
when 'checkbox'
|
|
|
|
self["val"] = self[:temp_data].keys
|
2022-03-10 02:11:18 +00:00
|
|
|
end #end of case self.application_form_signup_field.markup
|
2016-06-29 06:57:45 +00:00
|
|
|
end # of self[:temp_data].nil?
|
|
|
|
self.unset('temp_data')
|
|
|
|
self.unset('temp')
|
|
|
|
end #of data_proc
|
|
|
|
|
|
|
|
def check_key
|
2022-03-10 02:11:18 +00:00
|
|
|
if self.application_form_signup_field_id.present? && self.application_form_signup_field.nil?
|
2021-04-03 16:23:52 +00:00
|
|
|
begin
|
2022-03-10 02:11:18 +00:00
|
|
|
self.application_form_signup_field = ApplicationFormSignupField.find(self.application_form_signup_field_id)
|
2021-04-03 16:23:52 +00:00
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2022-03-10 02:11:18 +00:00
|
|
|
self.key = self.application_form_signup_field.key rescue nil
|
2016-06-29 06:57:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(*field)
|
|
|
|
if field.size < 1
|
|
|
|
self[field[0]]
|
|
|
|
else
|
|
|
|
self[(field[0].to_s.delete "=")] = field[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|