digital-archive/app/models/digital_content_archive.rb

52 lines
1.5 KiB
Ruby
Raw Normal View History

2015-08-11 08:39:31 +00:00
# encoding: utf-8
class DigitalContentArchive
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCategory::Categorizable
include OrbitModel::Status
include OrbitTag::Taggable
include Slug
field :title, as: :slug_title, localize: true
field :create_user_id
field :update_user_id
field :postdate , :type => DateTime, :default => Time.now
field :uid, type: String
field :sort_number, type: Integer
field :location , localize: true
field :department , localize: true
field :character , localize: true
field :description , localize: true
field :detail_description , localize: true
field :material , localize: true
field :size
field :item_id
field :item_date ,:type => Date
field :item_from , localize: true
field :item_status , localize: true
field :album_content , localize: true
scope :can_display, ->{where(is_hidden: false).order_by(:is_top=>-1, :sort_number=>1, :title=>1)}
has_many :digital_content_archive_files, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :digital_content_archive_files, :allow_destroy => true
after_save :save_digital_content_archive_files
def self.find_by_param(input)
self.find_by(uid: input)
end
def get_file_icon( file_data )
file_icon = "<span class=\"o-archives-file-type\">#{file_data.split('.')[-1]}</span>".html_safe
end
def save_digital_content_archive_files
self.digital_content_archive_files.each do |t|
if t.should_destroy
t.destroy
end
end
end
end