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,11 +12,13 @@ class AdBannersController < ApplicationController
private
def image_widget(adbanner)
images = adbanner.ad_images.can_display.collect.with_index do |b,i|
images = []
adbanner.ad_images.can_display.each_with_index do |b,i|
if b.language_enabled.include?(I18n.locale.to_s)
image_link = OrbitHelper.is_mobile_view ? b.file.mobile.url : b.file.url
klass = i == 0 ? "active" : ""
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
{
images << {
"image_link" => image_link,
"title" => b.title,
"class" => klass,
@ -27,6 +29,7 @@ class AdBannersController < ApplicationController
"link" => b.out_link || "#"
}
end
end
{
"extras" => {
"ad_fx" => adbanner.ad_fx,
@ -40,7 +43,9 @@ class AdBannersController < ApplicationController
end
def video_widget(adbanner)
images = adbanner.ad_images.can_display.collect.with_index do |ad_b,i|
images = []
adbanner.ad_images.can_display.each_with_index do |ad_b,i|
if ad_b.language_enabled.include?(I18n.locale.to_s)
image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
klass = i == 0 ? "active" : ""
@ -49,10 +54,11 @@ class AdBannersController < ApplicationController
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
{
"extras" => {
"ad_fx" => adbanner.ad_fx,

View File

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

View File

@ -62,7 +62,6 @@
</div>
</div>
<!-- Link -->
<div class="control-group">
<label class="control-label muted"><%= t(:link) %></label>
@ -87,6 +86,18 @@
<%= f.text_field :youtube, placeholder: t(:youtube), class: 'input-block-level' %>
</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-->