bilingual function added to banner

This commit is contained in:
Harry Bomrah 2015-05-08 15:47:29 +08:00
parent 636b51d080
commit 0b0669fe96
3 changed files with 55 additions and 37 deletions

View File

@ -12,46 +12,52 @@ class AdBannersController < ApplicationController
private private
def image_widget(adbanner) def image_widget(adbanner)
images = adbanner.ad_images.can_display.collect.with_index do |b,i| images = []
image_link = OrbitHelper.is_mobile_view ? b.file.mobile.url : b.file.url adbanner.ad_images.can_display.each_with_index do |b,i|
klass = i == 0 ? "active" : "" if b.language_enabled.include?(I18n.locale.to_s)
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : "" image_link = OrbitHelper.is_mobile_view ? b.file.mobile.url : b.file.url
{ klass = i == 0 ? "active" : ""
"image_link" => image_link, caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
"title" => b.title, images << {
"class" => klass, "image_link" => image_link,
"height" => adbanner.height, "title" => b.title,
"width" => adbanner.width, "class" => klass,
"caption" => caption, "height" => adbanner.height,
"context" => b.context, "width" => adbanner.width,
"link" => b.out_link || "#" "caption" => caption,
} "context" => b.context,
"link" => b.out_link || "#"
}
end
end end
{ {
"extras" => { "extras" => {
"ad_fx" => adbanner.ad_fx, "ad_fx" => adbanner.ad_fx,
"speed" => adbanner.speed, "speed" => adbanner.speed,
"title" => adbanner.title, "title" => adbanner.title,
"timeout" => adbanner.timeout, "timeout" => adbanner.timeout,
"more" => "More" "more" => "More"
}, },
"images" => images "images" => images
} }
end end
def video_widget(adbanner) def video_widget(adbanner)
images = adbanner.ad_images.can_display.collect.with_index do |ad_b,i| images = []
image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url adbanner.ad_images.can_display.each_with_index do |ad_b,i|
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : "" if ad_b.language_enabled.include?(I18n.locale.to_s)
klass = i == 0 ? "active" : "" image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url
if ad_b.exchange_item == "1" caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
image_html = "<div class='w-ad-banner__slide #{klass}' data-link='#{ad_b.out_link || "#"}''><img class='w-ad-banner__image' src='#{image_link}'><div class='w-ad-banner__caption_text'>#{ad_b.title}</div></div>" klass = i == 0 ? "active" : ""
else ad_b.exchange_item == "2" if ad_b.exchange_item == "1"
image_html = "<div class='w-ad-banner__slide youtube #{klass}' data-yt-binded='0' data-youtube-id='ytplayer#{i}'><a class='w-ad-banner__slide' href='#{format_url(ad_b.youtube,i)}'>#{ad_b.title}</a><div class='w-ad-banner__caption_text'>#{ad_b.title}</div></div>" image_html = "<div class='w-ad-banner__slide #{klass}' data-link='#{ad_b.out_link || "#"}''><img class='w-ad-banner__image' src='#{image_link}'><div class='w-ad-banner__caption_text'>#{ad_b.title}</div></div>"
else ad_b.exchange_item == "2"
image_html = "<div class='w-ad-banner__slide youtube #{klass}' data-yt-binded='0' data-youtube-id='ytplayer#{i}'><a class='w-ad-banner__slide' href='#{format_url(ad_b.youtube,i)}'>#{ad_b.title}</a><div class='w-ad-banner__caption_text'>#{ad_b.title}</div></div>"
end
images << {
"html" => image_html
}
end end
{
"html" => image_html
}
end end
{ {
"extras" => { "extras" => {

View File

@ -14,6 +14,7 @@ class AdImage
field :postdate , :type => DateTime, :default => Time.now field :postdate , :type => DateTime, :default => Time.now
field :deadline , :type => DateTime field :deadline , :type => DateTime
field :youtube , :type => String field :youtube , :type => String
field :language_enabled, :type => Array, :default => ["en","zh_tw"]
field :exchange_item field :exchange_item
LINK_OPEN_TYPES = ["local", "new_window"] LINK_OPEN_TYPES = ["local", "new_window"]

View File

@ -62,7 +62,6 @@
</div> </div>
</div> </div>
<!-- Link --> <!-- Link -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t(:link) %></label> <label class="control-label muted"><%= t(:link) %></label>
@ -88,6 +87,18 @@
</div> </div>
</div> </div>
</div> </div>
<!-- language-selection -->
<div class="control-group">
<label class="control-label muted"><%= t(:select_language) %></label>
<div class="controls">
<% @site_in_use_locales.each do |locale| %>
<label class="checkbox">
<%= check_box_tag "ad_image[language_enabled][]", locale, (@ad_image.language_enabled.include?(locale.to_s) rescue false) %>
<%= t(locale.to_s) %>
</label>
<% end %>
</div>
</div>
<!-- Title--> <!-- Title-->
<div class="control-group"> <div class="control-group">