2014-04-11 07:47:33 +00:00
|
|
|
class Banner
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2014-04-20 12:23:18 +00:00
|
|
|
include OrbitTag::Taggable
|
2014-12-01 10:05:55 +00:00
|
|
|
include OrbitCategory::Categorizable
|
2014-04-20 12:23:18 +00:00
|
|
|
|
2014-04-11 07:47:33 +00:00
|
|
|
field :ad_fx, type: String
|
|
|
|
field :height, type: Integer
|
2015-11-18 09:04:16 +00:00
|
|
|
field :speed, type: Integer, default: 500
|
2014-04-11 07:47:33 +00:00
|
|
|
field :title, type: String
|
2015-10-06 07:30:59 +00:00
|
|
|
field :timeout, type: Integer, default: 5
|
2014-04-11 07:47:33 +00:00
|
|
|
field :width, type: Integer
|
2015-11-12 17:06:56 +00:00
|
|
|
field :base_image, type: Integer, default: 1
|
2014-04-11 07:47:33 +00:00
|
|
|
|
2019-05-05 12:47:11 +00:00
|
|
|
has_many :ad_images , dependent: :destroy
|
2014-04-11 07:47:33 +00:00
|
|
|
|
|
|
|
validates_uniqueness_of :title
|
|
|
|
validates :title, :length => { :minimum => 2 }
|
|
|
|
|
2015-10-12 07:22:51 +00:00
|
|
|
FX_TYPES = %w(fade scrollHorz scrollVert tileSlide tileBlind)
|
2014-04-11 07:47:33 +00:00
|
|
|
|
|
|
|
def size
|
|
|
|
"#{self.width} x #{self.height}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def timeout_millisecond
|
|
|
|
self.timeout*1000 rescue 0
|
|
|
|
end
|
2014-05-09 08:42:23 +00:00
|
|
|
|
|
|
|
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
|
2015-11-12 17:06:56 +00:00
|
|
|
{'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
|
2014-05-09 08:42:23 +00:00
|
|
|
end
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|