The new AdBanner.

This commit is contained in:
Matthew K. Fu JuYuan authored and Christophe Vilayphiou committed 2012-04-02 03:04:38 +08:00
1 parent b17cd7570f
commit 8f28d45379
32 files changed
+1763 -240

No files matched your search

+20 -29
View File
@@ -4,41 +4,32 @@ class AdBanner
include Mongoid::MultiParameterAttributes
field :title
field :picture_position
field :post_date,type: Date
field :unpost_date,type: Date
field :context
field :direct_to_after_click,type: Boolean
field :transition_sec,type: Integer
field :ad_fx #TODO Design should explain
before_save :save_or_destroy
embeds_many :ad_images, :cascade_callbacks => true
validates_uniqueness_of :title
has_many :ad_images , dependent: :delete
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"]
def display?
if (self.post_date <= Date.today && (self.unpost_date.nil? || self.unpost_date>= Date.today))
return true
end
return false
end
# 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 new_ad_images=(*attrs)
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
# 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
def save_or_destroy
self.ad_images.each do |ad_image|
+34 -7
View File
@@ -3,19 +3,46 @@ class AdImage
include Mongoid::Timestamps
mount_uploader :file, ImageUploader
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :context, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :time_to_next #Weight
field :picture_intro
field :out_link
field :link_open
field :direct_to_after_click,type: Boolean
field :weight ,type: Integer ,default: 1
field :out_link #the link itself
field :link_open #how will the link be opened
LINK_OPEN_TYPES = ["new_window","local"]
field :post_date,type: Date
field :unpost_date,type: Date
field :to_save, :type => Boolean
field :to_destroy, :type => Boolean
LINK_OPEN_TYPES = ["new_window","local"]
belongs_to :ad_banner
# validates_numericality_of :weight, greater_than_or_equal_to: 1,less_than_or_equal_to: 10
# validates_format_of :out_link, with: /(http:\/\/.*|)/ ,:message => 'Need a valid URL'
# validates_presence_of :post_date,:message => 'Need a valid post date'
attr_reader :parse_post_date,:parse_unpost_date
def parse_post_date=(att)
self.post_date = (Date.parse att rescue nil)
end
embedded_in :ad_banner
def parse_unpost_date=(att)
self.unpost_date = (Date.parse att rescue nil)
end
def display?
if (self.post_date <= Date.today && (self.unpost_date.nil? || self.unpost_date>= Date.today) rescue false)
return true
end
return false
end
def get_delay_time
time = ''