Application_Form/app/models/application_form_ticket_sta...

42 lines
1.5 KiB
Ruby
Raw Normal View History

2023-05-21 09:16:16 +00:00
class ApplicationFormTicketStatus
include Mongoid::Document
include Mongoid::Timestamps
DefaultKeys = ["is_waiting", "is_processed", "is_referral", "is_published"]
field :title, type: String, localize: true
field :is_default, type: Boolean, default: false # if true => cannot delete
field :key, type: String
before_create do
if self.key.blank?
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
last_ticket_key = can_update_shared_hash ? OrbitHelper::SharedHash["application_form"][:last_ticket_key] : ApplicationFormSetting.pluck(:last_ticket_key)[0].to_i
self.key = last_ticket_key.to_s
ApplicationFormSetting.all.inc({'last_ticket_key'=>1})
if can_update_shared_hash
OrbitHelper::SharedHash["application_form"][:last_ticket_key] = last_ticket_key + 1
end
end
true
end
after_destroy do
# can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
# ApplicationFormSetting.all.inc({'last_ticket_key'=>-1})
# if can_update_shared_hash
# OrbitHelper::SharedHash["ask"][:last_ticket_key] = OrbitHelper::SharedHash["ask"][:last_ticket_key] - 1
# end
end
def title
tmp = super
if self.is_default
tmp = I18n.t("ask.#{self.key}") if tmp.blank?
end
tmp
end
def get_title_translations(locales=nil)
locales = I18n.available_locales if locales.nil?
trans = {}
locales.each do |locale|
trans[locale] = I18n.with_locale(locale){self.title}
end
trans
end
end