Basic function for AdBanner

This commit is contained in:
Matthew Kaito Juyuan Fu authored and Christophe Vilayphiou committed 2012-02-01 14:27:51 +08:00
1 parent 3287b68354
commit a980847eb3
15 files changed
+298

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
class AdBanner
include Mongoid::Document
include Mongoid::Timestamps
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 :ad_style #TODO Design should explain
before_save :save_or_destroy
embeds_many :ad_images, :cascade_callbacks => true
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 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
+16
View File
@@ -0,0 +1,16 @@
class AdImage
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, ImageUploader
field :time_to_next #Weight
field :picture_intro
field :out_link
field :to_save, :type => Boolean
field :to_destroy, :type => Boolean
embedded_in :ad_banner
end