Project

General

Profile

Download (1.21 KB) Statistics
| Branch: | Tag: | Revision:
b689e231 Marc Dequènes (Duck)
class ArtworkStepImage < ArtworkStep
has_many :artwork_step_thumbnails, :foreign_key => 'parent_id'

has_attachment :content_type => :image,
:max_size => MyCyma::Config.instance.max_uploaded_image_size_mb.megabyte,
:storage => :file_system,
:path_prefix => base_upload_path(),
:thumbnails => MyCyma::Config.instance.thumbnail_param_list,
:thumbnail_class => ArtworkStepThumbnail

validates_presence_of :filename, :date, :artwork_id #, :void
validates_uniqueness_of :filename, :scope => :artwork_id
ba788eca Marc Dequènes (Duck)
validates_numericality_of :position, :only_integer => true, :greater_than_or_equal_to => 0
b689e231 Marc Dequènes (Duck)
validates_as_attachment

public :after_process_attachment
attr_accessor :saved_attachment
5c004100 Marc Dequènes (Duck)
def thumbnail(size)
4ef5bacc Marc Dequènes (Duck)
return self if size.nil?

40d327d8 Marc Dequènes (Duck)
thumb = self.artwork_step_thumbnails.find_by_thumbnail(size.to_s)
if thumb.nil?
regen_thumbnail(size)
else
thumb
end
end

def regen_thumbnail(size_name)
return unless self.exists?
4ef5bacc Marc Dequènes (Duck)
return if size_name.nil?
40d327d8 Marc Dequènes (Duck)
size = attachment_options[:thumbnails][size_name]
temp_file = create_temp_file
create_or_update_thumbnail(temp_file, size_name, size)
5c004100 Marc Dequènes (Duck)
end
6fed455d Marc Dequènes (Duck)
def exists?
File.exists?(self.full_filename)
end
b689e231 Marc Dequènes (Duck)
end