66 lines
1.6 KiB
Ruby
66 lines
1.6 KiB
Ruby
class EmailEr
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
include OrbitModel::Status
|
|
include OrbitModel::Impression
|
|
# encoding: utf-8
|
|
include OrbitTag::Taggable
|
|
include OrbitCategory::Categorizable
|
|
include Slug
|
|
|
|
field :mail_subject
|
|
field :mail_sentdate , :type => DateTime
|
|
field :mail_content
|
|
|
|
field :email_member_ids
|
|
field :other_mailaddress
|
|
|
|
field :create_user_id
|
|
field :update_user_id
|
|
|
|
field :email_id
|
|
field :email_confirm, :type => Boolean, :default => false
|
|
|
|
field :is_preview, :type => Boolean, :default => false
|
|
|
|
has_many :email_er_files, :autosave => true, :dependent => :destroy
|
|
accepts_nested_attributes_for :email_er_files, :allow_destroy => true
|
|
|
|
before_destroy :destroy_email
|
|
|
|
scope :can_display,->{where(is_hidden: false)}
|
|
|
|
validates :mail_subject,presence:{message:'blank is not allowed'}
|
|
validates :other_mailaddress,
|
|
:length => {:maximum => 1000, :message => I18n.t("er_email.other_mailaddress_note_limit")}
|
|
|
|
def update_user
|
|
User.find(update_user_id) rescue nil
|
|
end
|
|
|
|
def update_user=(user)
|
|
self.update_user_id = user.id
|
|
end
|
|
|
|
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
|
|
|
|
end
|