From d107d54a822a95240070c5acf972eef3397b0a40 Mon Sep 17 00:00:00 2001 From: Matthew Kaito Juyuan Fu Date: Fri, 3 Feb 2012 15:14:42 +0800 Subject: [PATCH] Ad banner close complete,need validation --- app/assets/javascripts/ad_banner.js | 2 +- app/models/ad_banner.rb | 7 +++++ app/models/ad_image.rb | 13 ++++++++ app/views/admin/ad_banners/_ad_image.html.erb | 9 +++--- .../admin/ad_banners/_ad_image_form.html.erb | 2 ++ app/views/admin/ad_banners/_form.html.erb | 3 +- app/views/admin/ad_banners/index.html.erb | 6 ++-- lib/parsers/parser_front_end.rb | 30 ++++++++++++++----- 8 files changed, 55 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/ad_banner.js b/app/assets/javascripts/ad_banner.js index 57176a1c..bab55a67 100644 --- a/app/assets/javascripts/ad_banner.js +++ b/app/assets/javascripts/ad_banner.js @@ -15,4 +15,4 @@ $('a.remove_mark').live("click",function(){ $(this).next().remove(); $(this).remove(); return false; -}); \ No newline at end of file +}); diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb index 4fcfea9b..0a2928b3 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -18,6 +18,13 @@ class AdBanner 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) attrs[0].each do |attr| #Loop by JSs,Themes,Imgs unless attr[:file].nil? diff --git a/app/models/ad_image.rb b/app/models/ad_image.rb index dc8eab8b..5d06d798 100644 --- a/app/models/ad_image.rb +++ b/app/models/ad_image.rb @@ -7,10 +7,23 @@ class AdImage field :time_to_next #Weight field :picture_intro field :out_link + field :link_open field :to_save, :type => Boolean field :to_destroy, :type => Boolean + LINK_OPEN_TYPES = ["new_window","local"] + + embedded_in :ad_banner + def get_delay_time + time = '' + if self.time_to_next.nil? + time = '1000' + else + time = (self.time_to_next.to_i * 1000).to_s + end + time + end end diff --git a/app/views/admin/ad_banners/_ad_image.html.erb b/app/views/admin/ad_banners/_ad_image.html.erb index 7ecdaa3b..e724a47f 100644 --- a/app/views/admin/ad_banners/_ad_image.html.erb +++ b/app/views/admin/ad_banners/_ad_image.html.erb @@ -1,7 +1,8 @@
<%= image_tag ad_image.file %> - Time to next: <%= ad_image.time_to_next %> - Intro: <%= ad_image.picture_intro %> - Out Link <%= link_to ad_image.out_link %> - <%= render :partial => "ad_image_update", :locals => { :ad_image => ad_image } %> +

+ Time to next: <%= ad_image.time_to_next %> + Intro: <%= ad_image.picture_intro %> + Out Link <%= link_to ad_image.out_link %> by <%= ad_image.link_open %> +

diff --git a/app/views/admin/ad_banners/_ad_image_form.html.erb b/app/views/admin/ad_banners/_ad_image_form.html.erb index 43d817a5..3a153d47 100644 --- a/app/views/admin/ad_banners/_ad_image_form.html.erb +++ b/app/views/admin/ad_banners/_ad_image_form.html.erb @@ -1,3 +1,5 @@ Time: <%= f.text_field :time_to_next ,:class=> 'ad_time'%> Link:<%= f.text_field :out_link ,:class=> 'ad_out_link'%> +Open Type <%= f.select :link_open ,AdImage::LINK_OPEN_TYPES %> + <%= f.hidden_field :to_save %> \ No newline at end of file diff --git a/app/views/admin/ad_banners/_form.html.erb b/app/views/admin/ad_banners/_form.html.erb index ff522794..619bed11 100644 --- a/app/views/admin/ad_banners/_form.html.erb +++ b/app/views/admin/ad_banners/_form.html.erb @@ -22,8 +22,7 @@

<%= f.label :unpost_date, t('admin.unpost_date') %> - <%= f.date_select :unpost_date, :order => [:year, :month, :day], :use_month_numbers => true %> - + <%= f.date_select :unpost_date, :order => [:year, :month, :day], :use_month_numbers => true,:prompt => { :day => t('form.date_unlimited'), :month => t('form.date_unlimited'), :year => t('form.date_unlimited') } %>

<%= f.label :context, t('admin.context') %> diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index 54217140..e109830e 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -20,6 +20,7 @@ <%= t('admin.unpost_date') %> <%= t('admin.context') %> <%= t('admin.direct_to_after_click') %> + <%= t('admin.now_display?') %> <% @ad_banners.each do |ad_banner| %> @@ -27,10 +28,11 @@ <%= ad_banner.title %> <%= ad_banner.picture_position %> <%= ad_banner.post_date %> - <%= ad_banner.unpost_date %> + <%= ad_banner.unpost_date.nil?? t('form.date_unlimited'): ad_banner.unpost_date %> <%= ad_banner.context %> <%= ad_banner.direct_to_after_click %> - + <%= ad_banner.display? %> + <%= link_to t(:show), admin_ad_banner_path(ad_banner), :class => 'show' %> <%= link_to t(:edit), edit_admin_ad_banner_path(ad_banner), :class => 'edit' %> <%= link_to t(:delete), admin_ad_banner_path(ad_banner), :confirm => t('sure?'), :method => :delete, :class => 'delete' %> diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 35481829..be288612 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -85,14 +85,28 @@ module ParserFrontEnd c.define_tag 'adbanner' do |tag| res = '' ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]}) - res << "" - res << "" - - res << "

" - ad_banner.ad_images.each do |ad_image| - res << "" - end - res << "
" + if ad_banner.display? + res << "" + res << "" + + res << "
" + ad_banner.ad_images.each do |ad_image| + res << "" + end + res << "
" + end + res end c.define_tag 'image' do |tag| image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }