64 lines
2.2 KiB
Ruby
64 lines
2.2 KiB
Ruby
class Cancerpredictfields
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
include OrbitModel::Status
|
|
include OrbitModel::Impression
|
|
# encoding: utf-8
|
|
include OrbitTag::Taggable
|
|
include OrbitCategory::Categorizable
|
|
field :font_array , :type => Hash, default:{}
|
|
field :new_add_font, type: String, default:""
|
|
field :delete_font, type: String, default:""
|
|
field :used_font , :type => Array, default:[]
|
|
field :un_used_font , :type => Array, default:[]
|
|
field :title ,type:String ,default:""
|
|
field :subtitle, localize: true
|
|
field :text, localize: true
|
|
# before_destroy :destroy_email
|
|
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])}
|
|
scope :is_approved, ->{where(:approved => true)}
|
|
before_create :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
|
before_update :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
|
before_save :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
|
after_update :set_config
|
|
after_save :set_config
|
|
#before_create :set_expire
|
|
def delete_empty_font
|
|
self.font_array.each do |font,istrue|
|
|
if font.strip == ""
|
|
self.font_array.delete(font)
|
|
end
|
|
end
|
|
end
|
|
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 expired?
|
|
(self.deadline < Time.now) rescue false
|
|
end
|
|
def destroy_email
|
|
mail = Email.find(self.email_id) rescue nil
|
|
mail.destroy if !mail.nil?
|
|
end
|
|
def self.remove_expired_status
|
|
self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |b|
|
|
b.is_top = false
|
|
b.top_end_date = nil
|
|
b.save
|
|
end
|
|
end
|
|
end |