2012-04-13 07:24:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
class ArchiveFile
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Mongoid::MultiParameterAttributes
|
2013-06-04 02:53:31 +00:00
|
|
|
include Mongoid::Sortable
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
include OrbitModel::Status
|
|
|
|
include OrbitTag::Taggable
|
|
|
|
|
2013-03-07 09:59:53 +00:00
|
|
|
BelongsToCategory = :archive_file_category
|
2012-04-13 07:24:19 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
PAYMENT_TYPES = @site_valid_locales
|
2012-08-20 09:14:13 +00:00
|
|
|
|
2013-04-26 03:18:57 +00:00
|
|
|
|
2012-08-20 09:14:13 +00:00
|
|
|
field :title, localize: true
|
2012-04-13 07:24:19 +00:00
|
|
|
field :create_user_id
|
|
|
|
field :update_user_id
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2013-03-07 09:59:53 +00:00
|
|
|
# belongs_to :archive_file_category
|
2012-04-13 07:24:19 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
has_many :archive_file_multiples, :autosave => true, :dependent => :destroy
|
2012-04-23 07:53:58 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
accepts_nested_attributes_for :archive_file_multiples, :allow_destroy => true
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2012-11-01 03:45:26 +00:00
|
|
|
validates :title, :at_least_one => true
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
after_save :save_archive_file_multiples
|
2012-04-13 07:24:19 +00:00
|
|
|
|
2013-06-05 10:03:09 +00:00
|
|
|
# searchable do
|
|
|
|
# text :titles do
|
|
|
|
# title_translations.to_a.collect{|t| t[1]}
|
|
|
|
# end
|
|
|
|
# boolean :frontend_search do
|
|
|
|
# !is_hidden
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
2012-04-13 07:24:19 +00:00
|
|
|
def self.search( category_id = nil )
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2012-04-13 07:24:19 +00:00
|
|
|
if category_id.to_s.size > 0
|
2012-04-13 07:24:19 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
find(:all, :conditions => {archive_file_category_id: category_id}).desc( :is_top, :title )
|
2012-04-13 07:24:19 +00:00
|
|
|
|
|
|
|
else
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
find(:all).desc( :is_top, :title)
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2012-04-13 07:24:19 +00:00
|
|
|
end
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2012-04-13 07:24:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.widget_datas
|
2012-04-13 07:24:19 +00:00
|
|
|
|
2013-03-07 09:59:53 +00:00
|
|
|
where( :is_hidden => false ).desc(:is_top, :title)
|
2012-04-13 07:24:19 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-03-07 09:59:53 +00:00
|
|
|
|
|
|
|
def get_file_icon( file_data )
|
2013-03-21 06:38:04 +00:00
|
|
|
file_icon = "<span class=\"o-archives-file-type\">#{file_data.split('.')[-1]}</span>".html_safe
|
2013-03-07 09:59:53 +00:00
|
|
|
end
|
2013-06-04 02:53:31 +00:00
|
|
|
|
2012-04-23 07:53:58 +00:00
|
|
|
def save_archive_file_multiples
|
|
|
|
self.archive_file_multiples.each do |t|
|
|
|
|
if t.should_destroy
|
|
|
|
t.destroy
|
|
|
|
end
|
2012-04-13 07:24:19 +00:00
|
|
|
end
|
|
|
|
end
|
2013-06-04 02:53:31 +00:00
|
|
|
|
|
|
|
end
|