42 lines
1.5 KiB
Ruby
42 lines
1.5 KiB
Ruby
class AskTicketStatus
|
|
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["ask"][:last_ticket_key] : AskSetting.pluck(:last_ticket_key)[0].to_i
|
|
self.key = last_ticket_key.to_s
|
|
AskSetting.all.inc({'last_ticket_key'=>1})
|
|
if can_update_shared_hash
|
|
OrbitHelper::SharedHash["ask"][:last_ticket_key] = last_ticket_key + 1
|
|
end
|
|
end
|
|
true
|
|
end
|
|
after_destroy do
|
|
# can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
|
|
# AskSetting.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 |