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 private
def image_widget(adbanner) 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 image_link = OrbitHelper.is_mobile_view ? b.file.mobile.url : b.file.url
klass = i == 0 ? "active" : "" klass = i == 0 ? "active" : ""
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : "" caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
{ images << {
"image_link" => image_link, "image_link" => image_link,
"title" => b.title, "title" => b.title,
"class" => klass, "class" => klass,
@ -27,6 +29,7 @@ class AdBannersController < ApplicationController
"link" => b.out_link || "#" "link" => b.out_link || "#"
} }
end end
end
{ {
"extras" => { "extras" => {
"ad_fx" => adbanner.ad_fx, "ad_fx" => adbanner.ad_fx,
@ -40,7 +43,9 @@ class AdBannersController < ApplicationController
end end
def video_widget(adbanner) 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 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>' : "" caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
klass = i == 0 ? "active" : "" klass = i == 0 ? "active" : ""
@ -49,10 +54,11 @@ class AdBannersController < ApplicationController
else ad_b.exchange_item == "2" 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>" 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 end
{ images << {
"html" => image_html "html" => image_html
} }
end end
end
{ {
"extras" => { "extras" => {
"ad_fx" => adbanner.ad_fx, "ad_fx" => adbanner.ad_fx,

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>
@ -87,6 +86,18 @@
<%= f.text_field :youtube, placeholder: t(:youtube), class: 'input-block-level' %> <%= f.text_field :youtube, placeholder: t(:youtube), class: 'input-block-level' %>
</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> </div>
<!-- Title--> <!-- Title-->