move code to core

This commit is contained in:
邱博亞 2023-09-27 21:09:30 +08:00
parent bbc0266967
commit ac6fb0448a
2 changed files with 1 additions and 313 deletions

View File

@ -1,109 +1,2 @@
module Admin::VenueManagementsValuesHelper
def show_west_calender(from_to=nil)
case from_to
when :to
date = get_date(:to)
when :from
date = get_date(:from)
when nil
date = get_date
end
# case self.member_profile_field["typeC"]["format"]
# when 'format1' # Y/M/D h:m
# date.strftime("%Y/%m/%d %H:%M")
# when 'format2' # Y/M/D
# date.strftime("%Y/%m/%d")
# when 'format3' # Y/M
# date.strftime("%Y/%m")
# when 'format4' # Y
# date.strftime("%Y")
# end # of case west cal format
end
def show_minguo_calendar(from_to=nil)
get_minguo
case from_to
when :to
date = get_date(:to)
when :from
date = get_date(:from)
when nil
date = get_date
end
@date = date.split('/')
date_year = @date[0].to_i
year_str = ""
unless date_year == 1912
m_year = (date_year - 1912).abs.to_s + I18n.t("date.minguo_calendar.year")
year_str = minguo_format_year(m_year)
end
get_minguo_year(from_to) + minguo_m_y_d_time(from_to)
end
def get_minguo_year(from_to=nil)
case from_to
when :to
date = get_date(:to)
when :from
date = get_date(:from)
when nil
date = get_date
end
@date = date.split('/')
date_year = @date[0].to_i
m_year = (date_year - 1911).abs
year_end = I18n.t("date.minguo_calendar.year")
case
when date_year <1912
I18n.t("date.minguo_calendar.before") + (m_year+1).to_s + year_end
when date_year ==1912
I18n.t("date.minguo_calendar.first_year")
when date_year >1912
I18n.t("date.minguo_calendar.after")+ (m_year).to_s + year_end
end # of case tw_calendar year
end
def minguo_m_y_d_time(from_to=nil)
case from_to
when :to
date = get_date(:to)
when :from
date = get_date(:from)
when nil
date = get_date
end
@date = date.split('/')
case self.venue_management_signup_field["typeC"]["format"]
when 'format1' # Y/M/D h:m
"/#{@date[1]}/#{@date[2]}"
when 'format2' # Y/M/D
"/#{@date[1]}/#{@date[2]}"
when 'format3' # Y/M
"/#{@date[1]}#{I18n.t("date.minguo_calendar.month")}"\
when 'format4' # Y
''
end # of case
end
def get_date_by_format(from_to = nil)
case I18n.locale
when :zh_tw
case
when self.venue_management_signup_field["typeC"]["calendar"] == "west_calendar"
show_west_calender(from_to)
when self.venue_management_signup_field["typeC"]["calendar"] == "tw_calendar"
show_minguo_calendar(from_to)
end #case self.venue_management_signup_field["typeC"]["calendar"]
when :en
show_west_calender(from_to)
end
end
end

View File

@ -2,214 +2,9 @@ class VenueManagementSignupValue
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Attributes::Dynamic
belongs_to :venue_management_signup_field #must for FieldParser
include ::AttributeValuesHelper
include ::Admin::VenueManagementsValuesHelper
field :key, type: String
belongs_to :venue_management_signup_field
belongs_to :venue_management_signup
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
result = case self.venue_management_signup_field.markup
when 'text_field','text_area'
if self.venue_management_signup_field.add_more and (self.venue_management_signup_field.markup == "text_field")
index.nil? ? self["val"] : self["val"][index]
else
self.venue_management_signup_field.get_data["cross_lang"] =="true" ? self["val"] : Hash[site.valid_locales.collect{|lang| [lang,self[lang.to_sym]]}]
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"]
end #end of case self.venue_management_signup_field.markup
end
def value=(value)
#save everything to temp_data waiting for futher process
self[:temp_data] = value
end
def get_field_value
if (self.venue_management_signup_field.markup.eql?("text_field") || self.venue_management_signup_field.markup.eql?("text_area"))
field_value = self.value[I18n.locale]
elsif (self.venue_management_signup_field.markup.eql?("select") || self.venue_management_signup_field.markup.eql?("radio_button"))
field_value = self.venue_management_signup_field.markup_value["#{self.value}"][I18n.locale] rescue nil
elsif self.venue_management_signup_field.markup.eql?("address")
field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ')
elsif self.venue_management_signup_field.markup.eql?("date")
case self.venue_management_signup_field.typeC['format']
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
elsif self.venue_management_signup_field.markup.eql?("checkbox")
field_value = self.value.map {|v| self.venue_management_signup_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil
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?
{
"key" => self.venue_management_signup_field.key,
"title" => self.venue_management_signup_field.title,
"value" => field_value,
"val" => field_value = self.value
}
else
{
"key" => self.venue_management_signup_field.key,
"title" => self.venue_management_signup_field.title,
"value" => "",
"val" => field_value = self.value
}
end
end
def get_value_by_locale(locale,add_more_index=nil)
case self.venue_management_signup_field.markup
when "text_field"
case self.venue_management_signup_field.add_more
when true
if self.venue_management_signup_field.locale
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
self.venue_management_signup_field.locale ? self[locale.to_s] : self.value
end
when "select"
markup_values = self.venue_management_signup_field.self_defined_markup_options? ? self.venue_management_signup_field.markup_value : self.venue_management_signup_field.markup_value
markup_values[self.value][locale.to_s] rescue 'NoData'
when "text_area"
self.venue_management_signup_field.locale ? self[locale.to_s] : self.value
when "date"
if self.venue_management_signup_field.date_is_range?
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"
markup_values = self.venue_management_signup_field.markup_value
markup_values[self.value][locale.to_s]
when "checkbox"
markup_values = self.venue_management_signup_field.markup_value
self.value.collect{|key| markup_values["#{key}"][I18n.locale]}.join(",")
when "date_durnation"
self.value
else
self.venue_management_signup_field.locale ? self[locale.to_s] : self.value
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)
@venue_management_signup_field_value = member.venue_management_signup_values.find(field_value_id) rescue nil
if @venue_management_signup_field_value!=nil
@venue_management_signup_field_value.update(field_value_param) rescue nil
@venue_management_signup_field_value.save rescue nil
end
else
@venue_management_signup_field_value = member.venue_management_signup_values.build(field_value_param) rescue nil
@venue_management_signup_field_value.save
end
return @venue_management_signup_field_value
end
protected
def unset_all_lang_values
VALID_LOCALES.each{|t| self.unset t}
end
def data_proc
unless self[:temp_data].nil?
case self.venue_management_signup_field.markup
when "address"
self["val"] = self["temp_data"]
when 'text_field','text_area'
if self.venue_management_signup_field.add_more
self["val"] = self["temp_data"]
else # if not add_more
if self.venue_management_signup_field.can_muti_lang_input?
self[:temp_data].each do |key,val|
self[key] = val
end if(!self.venue_management_signup_field.get_data[:cross_lang])
else
self["val"] = self[:temp_data]
end
end # of self.venue_management_signup_field.add_more
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys
end #end of case self.venue_management_signup_field.markup
end # of self[:temp_data].nil?
self.unset('temp_data')
self.unset('temp')
end #of data_proc
def check_key
self.key = self.venue_management_signup_field.key
end
def method_missing(*field)
if field.size < 1
self[field[0]]
else
self[(field[0].to_s.delete "=")] = field[1]
end
end
end