2014-04-01 07:12:43 +00:00
|
|
|
class Bulletin
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2014-05-01 08:41:00 +00:00
|
|
|
|
|
|
|
include OrbitModel::Status
|
2014-05-15 11:27:05 +00:00
|
|
|
include OrbitModel::Impression
|
2014-04-20 12:23:52 +00:00
|
|
|
include OrbitTag::Taggable
|
|
|
|
include OrbitCategory::Categorizable
|
2014-04-03 03:18:02 +00:00
|
|
|
include Slug
|
2014-04-01 07:12:43 +00:00
|
|
|
|
2014-04-11 09:20:07 +00:00
|
|
|
field :title, as: :slug_title, type: String, localize: true
|
2014-05-01 08:41:00 +00:00
|
|
|
field :subtitle, localize: true
|
|
|
|
field :text, localize: true
|
|
|
|
field :create_user_id
|
|
|
|
field :update_user_id
|
|
|
|
field :public, :type => Boolean, :default => true
|
|
|
|
field :postdate , :type => DateTime, :default => Time.now
|
|
|
|
field :deadline , :type => DateTime
|
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
field :email_id
|
2014-05-01 08:41:00 +00:00
|
|
|
field :email_sent, :type => Boolean, :default => false
|
2014-05-28 07:37:56 +00:00
|
|
|
field :email_sentdate , :type => DateTime, :default => Time.now+1.day
|
|
|
|
field :email_member_ids
|
2014-05-01 08:41:00 +00:00
|
|
|
field :other_mailaddress
|
|
|
|
|
|
|
|
mount_uploader :image, ImageUploader
|
|
|
|
|
|
|
|
has_many :bulletin_links, :autosave => true, :dependent => :destroy
|
|
|
|
has_many :bulletin_files, :autosave => true, :dependent => :destroy
|
|
|
|
|
|
|
|
accepts_nested_attributes_for :bulletin_files, :allow_destroy => true
|
|
|
|
accepts_nested_attributes_for :bulletin_links, :allow_destroy => true
|
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
before_destroy :destroy_email
|
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def update_user
|
|
|
|
User.find(update_user_id) rescue nil
|
|
|
|
end
|
2014-04-01 07:12:43 +00:00
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def update_user=(user)
|
|
|
|
self.update_user_id = user.id
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|
2014-04-21 07:39:13 +00:00
|
|
|
|
2014-05-02 10:21:51 +00:00
|
|
|
def self.can_display()
|
|
|
|
self.any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil})
|
|
|
|
end
|
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
def email_members
|
|
|
|
MemberProfile.find(self.email_member_ids) rescue []
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_addresses
|
|
|
|
addresses = self.email_members.collect{|member| member.email} rescue []
|
|
|
|
addresses = addresses +[self.other_mailaddress] if !self.other_mailaddress.blank?
|
|
|
|
addresses.flatten
|
|
|
|
end
|
|
|
|
|
|
|
|
def email
|
|
|
|
mail = Email.find(self.email_id) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_email
|
|
|
|
mail = Email.find(self.email_id) rescue nil
|
|
|
|
mail.destroy if !mail.nil?
|
|
|
|
end
|
|
|
|
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|