38 lines
1.2 KiB
Ruby
38 lines
1.2 KiB
Ruby
class Banner
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
include OrbitTag::Taggable
|
|
include OrbitCategory::Categorizable
|
|
|
|
field :ad_fx, type: String
|
|
field :height, type: Integer
|
|
field :speed, type: Integer, default: 500
|
|
field :title, type: String
|
|
field :timeout, type: Integer, default: 5
|
|
field :width, type: Integer
|
|
field :base_image, type: Integer, default: 1
|
|
|
|
has_many :ad_images , dependent: :destroy
|
|
|
|
validates_uniqueness_of :title
|
|
validates :title, :length => { :minimum => 2 }
|
|
|
|
FX_TYPES = %w(fade scrollHorz scrollVert tileSlide tileBlind)
|
|
|
|
def size
|
|
"#{self.width} x #{self.height}"
|
|
end
|
|
|
|
def timeout_millisecond
|
|
self.timeout*1000 rescue 0
|
|
end
|
|
|
|
def preview_link
|
|
"<a data-w='#{self.width}' data-time='#{self.timeout_millisecond}' data-speed='#{self.speed}' data-name='#{self.title}' data-h='#{self.height}' data-fx='#{self.ad_fx}' class='btn btn-success open-modal' href='#'>Preview</a>".html_safe
|
|
end
|
|
|
|
def data_attribute_hash
|
|
{'width'=> self.width,'height'=> self.height,'ad_fx'=> self.ad_fx,'name'=>self.title,'timeout'=>self.timeout,'speed'=>self.speed, 'base_image' => self.base_image}.to_json
|
|
end
|
|
end
|