58 lines
2.5 KiB
Ruby
58 lines
2.5 KiB
Ruby
class AnnouncementSetting
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
field :carousel_image_type, :type => Integer, :default => 0 # 0: carousel, 1: album
|
|
field :sub_annc_title_trans, :type => String, :default => "", :localize => true
|
|
field :carousel_image_width, type: String, :default => "75%"
|
|
field :top_limit, type: Integer, :default => 0
|
|
field :pro_enabled, type: Boolean, :default => false
|
|
field :approvers, type: Array, :default => []
|
|
field :email_to, type: Array, :default => ["admins","managers","approvers"]
|
|
field :is_display_edit_only, type: Boolean, :default => false
|
|
field :only_manager_can_edit_status, type: Boolean, :default => false
|
|
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
|
|
field :enable_annc_dept, type: Boolean, default: false
|
|
field :annc_depts, type: Array, default: [], localize: true
|
|
has_many :anns_status_settings, :autosave => true, :dependent => :destroy
|
|
accepts_nested_attributes_for :anns_status_settings, :allow_destroy => true
|
|
def self.check_limit_for_user(user_id, b_id = nil)
|
|
limit = self.first.top_limit rescue 0
|
|
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
|
|
|
|
def self.is_pro?
|
|
self.first.pro_enabled rescue false
|
|
end
|
|
|
|
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
|
|
|
|
before_save do
|
|
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
|
|
tmp_hash = {}
|
|
if self.enable_manually_sort_changed? && self.enable_manually_sort
|
|
AnnsCache.all.delete
|
|
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
|
|
tmp_hash[:enable_manually_sort] = self.enable_manually_sort
|
|
end
|
|
if self.annc_depts_changed?
|
|
tmp_hash[:annc_depts_translations] = self.annc_depts_translations
|
|
end
|
|
if can_update_shared_hash
|
|
if tmp_hash.count != 0
|
|
tmp_hash[:enable_manually_sort] = self.enable_manually_sort if tmp_hash[:enable_manually_sort].nil?
|
|
tmp_hash[:annc_depts_translations] = self.annc_depts_translations if tmp_hash[:annc_depts_translations].nil?
|
|
OrbitHelper::SharedHash["announcement"] = ProcesssShareWraper.new(tmp_hash)
|
|
end
|
|
end
|
|
end
|
|
end |