2015-12-22 11:04:13 +00:00
|
|
|
class AnnouncementSetting
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2021-09-25 11:26:13 +00:00
|
|
|
field :carousel_image_type, :type => Integer, :default => 0 # 0: carousel, 1: album
|
|
|
|
field :sub_annc_title_trans, :type => String, :default => "", :localize => true
|
2021-06-11 09:15:51 +00:00
|
|
|
field :carousel_image_width, type: String, :default => "75%"
|
2015-12-22 11:04:13 +00:00
|
|
|
field :top_limit, type: Integer, :default => 0
|
2016-07-05 11:34:29 +00:00
|
|
|
field :pro_enabled, type: Boolean, :default => false
|
2016-08-05 12:00:34 +00:00
|
|
|
field :approvers, type: Array, :default => []
|
|
|
|
field :email_to, type: Array, :default => ["admins","managers","approvers"]
|
2020-05-15 14:25:58 +00:00
|
|
|
field :is_display_edit_only, type: Boolean, :default => false
|
2020-05-16 13:43:37 +00:00
|
|
|
field :only_manager_can_edit_status, type: Boolean, :default => false
|
2022-03-29 06:25:10 +00:00
|
|
|
field :top_text , type: String , localize: true
|
|
|
|
field :hot_text , type: String , localize: true
|
|
|
|
field :hidden_text , type: String , localize: true
|
|
|
|
field :enable_manually_sort, type: Boolean, default: false
|
2022-04-18 15:32:19 +00:00
|
|
|
field :enable_annc_dept, type: Boolean, default: false
|
|
|
|
field :annc_depts, type: Array, default: [], localize: true
|
2020-03-02 10:09:55 +00:00
|
|
|
has_many :anns_status_settings, :autosave => true, :dependent => :destroy
|
|
|
|
accepts_nested_attributes_for :anns_status_settings, :allow_destroy => true
|
2024-10-13 13:42:37 +00:00
|
|
|
|
|
|
|
field :migrate_flag, type: Array, default: []
|
|
|
|
|
2015-12-22 11:04:13 +00:00
|
|
|
def self.check_limit_for_user(user_id, b_id = nil)
|
2015-12-22 11:52:35 +00:00
|
|
|
limit = self.first.top_limit rescue 0
|
2015-12-22 11:04:13 +00:00
|
|
|
return true if limit == 0
|
|
|
|
count = Bulletin.where(:is_top => true, :create_user_id => user_id, :id.ne => b_id).count
|
|
|
|
return count < limit
|
|
|
|
end
|
2016-07-05 11:34:29 +00:00
|
|
|
|
|
|
|
def self.is_pro?
|
2016-07-06 08:43:09 +00:00
|
|
|
self.first.pro_enabled rescue false
|
2016-07-05 11:34:29 +00:00
|
|
|
end
|
2021-09-25 11:26:13 +00:00
|
|
|
|
|
|
|
def get_sub_annc_title_trans(locale=I18n.locale)
|
|
|
|
I18n.with_locale(locale) do
|
|
|
|
self.sub_annc_title_trans.blank? ? I18n.t("announcement.table.title") : self.sub_annc_title_trans
|
|
|
|
end
|
|
|
|
end
|
2022-03-29 06:25:10 +00:00
|
|
|
|
|
|
|
before_save do
|
2022-04-18 15:32:19 +00:00
|
|
|
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
|
2022-03-29 06:25:10 +00:00
|
|
|
if self.enable_manually_sort_changed? && self.enable_manually_sort
|
|
|
|
Bulletin.index({approved: -1,is_hidden: 1,is_preview: 1, is_top: -1,sort_number: 1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true })
|
|
|
|
Bulletin.create_indexes
|
2023-01-31 10:08:00 +00:00
|
|
|
if can_update_shared_hash
|
|
|
|
OrbitHelper::SharedMutex.synchronize do
|
|
|
|
OrbitHelper::SharedHash["announcement"][:enable_manually_sort] = self.enable_manually_sort
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@need_update_bulletin = true
|
2022-06-21 03:11:33 +00:00
|
|
|
end
|
|
|
|
@need_update_bulletin = false
|
|
|
|
if self.enable_annc_dept_changed?
|
2023-01-31 10:08:00 +00:00
|
|
|
if can_update_shared_hash
|
|
|
|
OrbitHelper::SharedMutex.synchronize do
|
|
|
|
OrbitHelper::SharedHash["announcement"][:enable_annc_dept] = self.enable_annc_dept
|
|
|
|
end
|
|
|
|
end
|
2022-06-21 03:11:33 +00:00
|
|
|
@need_update_bulletin = true
|
2022-04-18 15:32:19 +00:00
|
|
|
end
|
|
|
|
if self.annc_depts_changed?
|
2023-01-31 10:08:00 +00:00
|
|
|
if can_update_shared_hash
|
|
|
|
OrbitHelper::SharedMutex.synchronize do
|
|
|
|
OrbitHelper::SharedHash["announcement"][:annc_depts_translations] = self.annc_depts_translations
|
|
|
|
end
|
|
|
|
end
|
2022-06-21 03:11:33 +00:00
|
|
|
@need_update_bulletin = true
|
2022-04-18 15:32:19 +00:00
|
|
|
end
|
2022-06-21 03:11:33 +00:00
|
|
|
end
|
|
|
|
after_save do
|
|
|
|
if @need_update_bulletin
|
|
|
|
Thread.new do
|
|
|
|
AnnsCache.all.delete
|
|
|
|
Bulletin.notify_all_feed(true)
|
2022-04-18 15:32:19 +00:00
|
|
|
end
|
2022-03-29 06:25:10 +00:00
|
|
|
end
|
|
|
|
end
|
2015-12-22 11:04:13 +00:00
|
|
|
end
|