orbit-eremail/app/models/email_er.rb

89 lines
2.4 KiB
Ruby
Raw Normal View History

2014-02-19 03:22:48 +00:00
# encoding: utf-8
class EmailEr
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
include OrbitCategory::Categorizable
include OrbitCoreLib::Preview
include OrbitModel::LanguageRestrict
include OrbitModel::Status
include OrbitModel::TimeFrame
include Tire::Model::Search
include Tire::Model::Callbacks
field :mail_subject
field :mail_sentdate , :type => DateTime
field :mail_content
2014-03-07 02:44:24 +00:00
field :email_user_ids
field :other_mailaddress
2014-02-19 03:22:48 +00:00
field :create_user_id
field :update_user_id
field :is_checked, :type => Boolean, :default => false
field :is_pending, :type => Boolean, :default => true
field :is_rejected, :type => Boolean, :default => false
field :not_checked_reason
scope :can_display,where(is_hidden: false)
has_many :email_er_files, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :email_er_files, :allow_destroy => true
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 proc_check(check,not_pass_info = "")
self.is_checked = true
if check =="true"
self.is_rejected = false
elsif check == "false"
self.is_rejected = true
self.not_checked_reason = not_pass_info
end
end
def de_pending
self.is_pending = false
end
def de_pending!
de_pending
self.save!
end
def is_checked?
!self.is_pending && self.is_checked && (self.is_rejected == false)
end
def is_pending?
self.is_pending
end
def is_rejected?
!self.is_pending && self.is_rejected && (self.is_rejected == true)
end
def to_preview
preview_object = Preview.new(:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_er_email_back_end_email_er_path",:object_class_type=>"EmailEr")
self.email_er["email_er_files_attributes"].each_with_index do |atr,idx|
preview_object.preview_files.build(:file=>self.email_er["email_er_files_attributes"][idx.to_s],:field_name_for_rebuild=>'email_er_files',:file_in_array=>true)
end unless self.email_er["email_er_files_attributes"].nil?
preview_object.object = self.email_er.except("email_er_files_attributes")
preview_object
end
2014-03-07 02:44:24 +00:00
def get_email_users
User.find(self.email_user_ids) rescue []
2014-02-19 03:22:48 +00:00
end
end