AdBanner is now working

This commit is contained in:
Matthew Kaito Juyuan Fu 2012-02-02 09:55:09 +08:00
parent dddd1f33fd
commit 5cebb638ce
6 changed files with 42 additions and 1 deletions

View File

@ -9,13 +9,15 @@ class AdBanner
field :unpost_date,type: Date field :unpost_date,type: Date
field :context field :context
field :direct_to_after_click,type: Boolean field :direct_to_after_click,type: Boolean
field :ad_style #TODO Design should explain field :ad_fx #TODO Design should explain
before_save :save_or_destroy before_save :save_or_destroy
embeds_many :ad_images, :cascade_callbacks => true embeds_many :ad_images, :cascade_callbacks => true
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 new_ad_images=(*attrs) def new_ad_images=(*attrs)
attrs[0].each do |attr| #Loop by JSs,Themes,Imgs attrs[0].each do |attr| #Loop by JSs,Themes,Imgs
unless attr[:file].nil? unless attr[:file].nil?

View File

@ -34,6 +34,10 @@
<%= f.label :direct_to_after_click, t('admin.direct_to_after_click') %> <%= f.label :direct_to_after_click, t('admin.direct_to_after_click') %>
<%= f.check_box :direct_to_after_click %> <%= f.check_box :direct_to_after_click %>
</p> </p>
<p>
<%= f.label :ad_fx, t('admin.ad_fx') %>
<%= f.select :ad_fx ,AdBanner::FX_TYPES %>
</p>
<p> <p>
<%= f.label :ad_images, t('admin.ad_images') %> <%= f.label :ad_images, t('admin.ad_images') %>
<ul> <ul>

View File

@ -18,6 +18,8 @@
<!-- example --> <!-- example -->
<div id="header_top" class="header"> <div id="header_top" class="header">
This is the first level of header This is the first level of header
<r:adbanner name='banner_1'>
</r:adbanner>
</div> </div>
<div id="header_bottom" class="header"> <div id="header_bottom" class="header">
This is the second level of header This is the second level of header

View File

@ -74,6 +74,25 @@ module ParserBackEnd
end end
res res
end end
c.define_tag 'adbanner' do |tag|
ret = ''
ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]})
ret << "<script type='text/javascript' src='http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js'></script>"
ret << "<script type='text/javascript'> $(document).ready(function() { $('.slideshow').cycle({ fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); }); </script>"
ret << "<div id='#{tag.attr['name']}' ad_banner_id='#{ad_banner.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>"
ret << "<div class='edit_link' style='display:none'>"
ret << " <a href='#{edit_admin_ad_banner_path(ad_banner.id)}' class='nav'>#{t(:edit)}</a>"
ret << '</div>'
#==================================
ret << "<div class='slideshow'>"
ad_banner.ad_images.each do |ad_image|
ret << "<img src='#{ad_image.file}' />"
end
ret << "</div>"
#==================================
ret << "</div>"
end
c.define_tag 'layout_part' do |tag| c.define_tag 'layout_part' do |tag|
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
ret = '' ret = ''

View File

@ -82,6 +82,18 @@ module ParserFrontEnd
end end
res res
end end
c.define_tag 'adbanner' do |tag|
res = ''
ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]})
res << "<script type='text/javascript' src='http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js'></script>"
res << "<script type='text/javascript'> $(document).ready(function() { $('.slideshow').cycle({ fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); }); </script>"
res << "<div class='slideshow'>"
ad_banner.ad_images.each do |ad_image|
res << "<img src='#{ad_image.file}' />"
end
res << "</div>"
end
c.define_tag 'image' do |tag| c.define_tag 'image' do |tag|
image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image

View File

@ -15,6 +15,8 @@ module ParserLayout
end end
c.define_tag 'stylesheets' do |tag| c.define_tag 'stylesheets' do |tag|
end end
c.define_tag 'adbanner' do |tag|
end
c.define_tag 'menu' do |tag| c.define_tag 'menu' do |tag|
layout.build_menu(:levels => 0, :values => {}) unless layout.menu layout.build_menu(:levels => 0, :values => {}) unless layout.menu
layout.menu.levels = i = tag.attr['level'].to_i layout.menu.levels = i = tag.attr['level'].to_i