2012-01-31 10:31:31 +00:00
|
|
|
class AdBanner
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Mongoid::MultiParameterAttributes
|
|
|
|
|
|
|
|
field :title
|
2012-04-23 09:03:55 +00:00
|
|
|
field :transition_msec,type: Integer
|
2012-02-02 01:55:09 +00:00
|
|
|
field :ad_fx #TODO Design should explain
|
2012-04-01 15:39:49 +00:00
|
|
|
|
2012-01-31 10:31:31 +00:00
|
|
|
before_save :save_or_destroy
|
2012-04-01 15:39:49 +00:00
|
|
|
validates_uniqueness_of :title
|
2012-04-17 08:03:48 +00:00
|
|
|
validates :title , :length => { :minimum => 2 }
|
2012-04-01 15:39:49 +00:00
|
|
|
has_many :ad_images , dependent: :delete
|
2012-01-31 10:31:31 +00:00
|
|
|
|
2012-02-02 01:55:09 +00:00
|
|
|
FX_TYPES = ["blindX","blindY","blindZ","cover","curtainX","curtainY","fade","fadeZoom","growX","growY","scrollUp","scrollDown","scrollLeft","scrollRight","scrollHorz","scrollVert","shuffle","slideX","slideY","toss","turnUp","turnDown","turnLeft","turnRight","uncover","wipe","zoom"]
|
2012-04-23 09:03:55 +00:00
|
|
|
attr_writer :transition_sec
|
|
|
|
def transition_sec
|
|
|
|
self.transition_msec/1000
|
|
|
|
end
|
|
|
|
|
|
|
|
def transition_sec=(sec)
|
|
|
|
self.transition_msec = sec.to_i*1000
|
|
|
|
end
|
2012-02-02 01:55:09 +00:00
|
|
|
|
2012-04-17 07:21:43 +00:00
|
|
|
def preview_clone
|
|
|
|
preview_banner = self.clone
|
|
|
|
preview_banner.ad_images = self.ad_images
|
|
|
|
preview_banner
|
|
|
|
end
|
2012-04-01 15:39:49 +00:00
|
|
|
# def new_ad_images(*attrs)
|
|
|
|
# debugger
|
|
|
|
# a=1
|
|
|
|
# attrs[0].each do |attr| #Loop by JSs,Themes,Imgs
|
|
|
|
# unless attr[:file].nil?
|
|
|
|
# self.ad_images << AdImage.new(attr)
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
# def existing_ad_images=(*attrs)
|
|
|
|
# attrs[0].each do |attr| #Loop by JSs,Themes,Imgs
|
|
|
|
# ad_image = self.ad_images.find attr[0]
|
|
|
|
# ad_image.update_attributes(attr[1])
|
|
|
|
# end
|
|
|
|
# end
|
2012-01-31 10:31:31 +00:00
|
|
|
|
|
|
|
def save_or_destroy
|
|
|
|
self.ad_images.each do |ad_image|
|
|
|
|
if ad_image.to_save?
|
|
|
|
ad_image.save
|
|
|
|
end
|
|
|
|
if ad_image.to_destroy?
|
|
|
|
ad_image.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|