2020-07-04 13:36:32 +00:00
|
|
|
class AskCategorySetting
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
after_initialize do
|
|
|
|
if !self.new_record?
|
|
|
|
if self.default_setting.class != Hash && self.default_setting.class != BSON::Document
|
|
|
|
self.default_setting = {}
|
|
|
|
end
|
|
|
|
if self.default_setting[:agree_show].nil?
|
|
|
|
self.default_setting[:agree_show] = true
|
|
|
|
end
|
|
|
|
if self.default_setting[:agree_usage].nil?
|
|
|
|
self.default_setting[:agree_usage] = false
|
|
|
|
end
|
|
|
|
if self.custom_fields.class != Hash && self.custom_fields.class != BSON::Document
|
|
|
|
self.custom_fields = {}
|
|
|
|
end
|
|
|
|
self.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def custom_fields
|
|
|
|
tmp = super
|
|
|
|
tmp.select{|k,v| v['delete'] != true}
|
|
|
|
end
|
2022-03-09 17:00:05 +00:00
|
|
|
def field_name(k,locale=I18n.locale.to_s)
|
|
|
|
(self.default_setting_field_name[k]&&self.default_setting_field_name[k][locale]) ? self.default_setting_field_name[k][locale] : self.default_field_name(k,locale)
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_field_name(k,locale=I18n.locale.to_s)
|
|
|
|
I18n.with_locale(locale){(['agree_show','agree_usage'].include?(k.to_s) ? I18n.t("ask.#{k}_checkbox") : I18n.t("mongoid.attributes.ask_question.#{k}"))}
|
|
|
|
end
|
|
|
|
|
|
|
|
def field_name_translations(k)
|
|
|
|
I18n.available_locales.map{|v| [v.to_s,self.field_name(k,v.to_s)]}.to_h
|
|
|
|
end
|
2022-03-18 03:49:11 +00:00
|
|
|
field :sort_number, type: Hash, default: {}
|
2022-07-07 08:54:09 +00:00
|
|
|
field :default_setting, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: true,appointment: true,recaptcha: true,agree_show: true,agree_usage: true}
|
|
|
|
field :default_setting_required, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: false,appointment: false,recaptcha: true,agree_show: true,agree_usage: true}
|
2022-03-09 17:00:05 +00:00
|
|
|
field :default_setting_field_name, type: Hash,default: {}
|
2022-07-07 08:54:09 +00:00
|
|
|
field :use_default, type: Boolean, default: false
|
2020-07-04 13:36:32 +00:00
|
|
|
field :custom_fields, type: Hash,default: {}
|
|
|
|
field :usage_rule
|
|
|
|
field :category_id
|
2022-05-21 13:47:42 +00:00
|
|
|
field :title_layout, type: Integer
|
2022-05-25 06:19:05 +00:00
|
|
|
field :email_regex_enable, type: Boolean, default: false
|
|
|
|
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
|
2022-07-07 08:54:09 +00:00
|
|
|
scope :enabled, ->{where(:use_default.ne=>true)}
|
2020-07-04 13:36:32 +00:00
|
|
|
end
|