44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
class EmailEntry
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :mail_subject #not optional
|
|
field :mail_content #not optional
|
|
field :create_user_id
|
|
field :email_member_ids, type: Array
|
|
field :other_mailaddress
|
|
field :email_sentdate, type: DateTime
|
|
|
|
field :approved, type: Boolean, default: false
|
|
field :is_sent, type: Boolean, default: false
|
|
|
|
has_many :email_entry_files, :autosave => true, :dependent => :destroy
|
|
accepts_nested_attributes_for :email_entry_files, :allow_destroy => true
|
|
|
|
def email_members
|
|
MemberProfile.find(self.email_member_ids) rescue []
|
|
end
|
|
|
|
def recipients
|
|
ids = self.email_members.collect{|member| member.email}
|
|
ids.delete(nil)
|
|
ids.concat(self.other_mailaddress.split(";"))
|
|
ids
|
|
end
|
|
|
|
def status_for_table
|
|
status = ""
|
|
t = self.email_sentdate.nil? ? self.created_at : self.email_sentdate
|
|
if self.approved && t < Time.now
|
|
status = "Sent"
|
|
elsif !self.approved
|
|
status = "Waiting for approval"
|
|
elsif self.approved && t > Time.now
|
|
status = "Mail ready to be send"
|
|
elsif self.approved && t == Time.now
|
|
status = "Sending"
|
|
end
|
|
status
|
|
end
|
|
|
|
end |