ad banner preview

This commit is contained in:
Matthew K. Fu JuYuan 2012-04-09 12:44:08 +08:00
parent 0eab9ca8fa
commit d2a3a4d26e
5 changed files with 52 additions and 27 deletions

View File

@ -1,12 +1,5 @@
module Admin::AdBannerHelper
def preview_block(ad_banner)
res =''
#same code as in frontend backend parser
if ad_banner
res << "<script type='text/javascript'>
$(document).ready(function(){ $('#slideshow-#{ad_banner.title.dehumanize}').cycle({delay: -1000, fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}', timeoutFn: getTimeout }); });
</script>"
res << "<div id='slideshow-#{ad_banner.title.dehumanize}'>"
def preview_block_ad_images_helper(ad_banner)
printable_ad_images = []
ad_banner.ad_images.each do |ad_image|
if ad_image.display?
@ -17,18 +10,7 @@ module Admin::AdBannerHelper
end
printable_ad_images.shuffle!
printable_ad_images.each do |ad_image| #TODO Need Reflact
res << "<img src='#{ad_image.file}' "
res << "alt='#{ad_image.title || ' '}' "
res << "time_to_next='#{ad_banner.transition_sec}' "
res << "link_open='#{ad_image.link_open}' "
# res << "link_url='#{(ad_image.direct_to_after_click?? ad_image.out_link : ad_banner.context) || ' '}' "
res << "link_url='#{(ad_image.out_link || ad_banner.context || ' ')}' "
res << "/>"
end
res << "</div>"
res.html_safe
end
end
end
end

View File

@ -15,5 +15,5 @@
<%= link_to 'Add AdImage',new_admin_ad_banner_ad_image_path(ad_banner_tab) %>
</div>
<% end -%>
<%= preview_block ad_banner_tab %>
<%= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %>
</div>

View File

@ -1,5 +1,3 @@
<script type="text/javascript" charset="utf-8">
</script>
<div id="new-a-banner" class="modal fade in tab-pane <%= 'active' if @active.nil? %>">
<%= form_for(:ad_banner,:remote => true, :url => admin_ad_banners_path) do |f| %>
@ -37,4 +35,21 @@
</div>
<% end %>
</div>
<script type="text/javascript" charset="utf-8">
if(window.location.pathname == "/admin/ad_banners/new"){
$('#new-a-banner').modal({show: true});
}
$('#new_ad_banner_tab_but').on('shown', function (e) {
$('#new-a-banner').modal({show: true});
})
$('#new-a-banner').on('shown', function (e) {
alert('show!');
})
$('#new-a-banner').on('hidden', function (e) {
$(".nav.nav-tabs a[id!='new_ad_banner_tab_but']:last").tab('show');
})
</script>

View File

@ -0,0 +1,29 @@
<% if ad_banner -%>
<%= link_to 'Preview',"#slideshow-#{ad_banner.title.dehumanize}",:class=>"btn btn-primary btn-large",:data=>{:toggle=>'modal'} %>
<div class="modal hide fade in" id='slideshow-<%=ad_banner.title.dehumanize%>'>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p class="ad_banner_slideshow">
<% preview_block_ad_images_helper(ad_banner).each do |ad_image| -%>
<%= image_tag ad_image.file,:alt => (ad_image.title[locale] || ' '),:time_to_next => ad_banner.transition_sec,:link_open=> ad_image.link_open, :link_url =>((ad_image.out_link || ad_banner.context || ' ')) %>
<% end -%>
</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
</div>
</div>
<% end -%>
<script type='text/javascript' src='/static/kernel.js'></script>
<script type='text/javascript'>
$('#slideshow-<%=ad_banner.title.dehumanize%>').on('show', function () {
$('#slideshow-banner_1').find(".ad_banner_slideshow").cycle({delay: -1000, fx: '<%= ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx %>', timeoutFn: getTimeout });
});
</script>

View File

@ -1,9 +1,9 @@
<div id="post-body-content" class="clear">
<ul class="nav nav-tabs">
<% @ad_banners.each do |ab| %>
<%= content_tag :li,link_to(ab.title,"##{ab.title}",:data=>{:toggle=>"tab"}),:class => (ab == @active ? 'active' : '' ) %>
<%= content_tag :li,link_to(ab.title,"##{ab.title}",:data=>{:toggle=>"tab"}),:class => (ab == @active ? 'active' : nil ) %>
<% end -%>
<%= content_tag :li,link_to('New',"#new-a-banner",:data=>{:toggle=>"tab"}),:class => (@active.nil? ? 'active' : '' ) %>
<%= content_tag :li,link_to('New',"#new-a-banner",:data=>{:toggle=>"tab"}),:id=>'new_ad_banner_tab_but',:class => (@active.nil? ? 'active' : nil ) %>
</ul>
@ -13,4 +13,3 @@
</div>
</div>