diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 6b8fb50..5ea0170 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -3,6 +3,7 @@ class AnnouncementsController < ApplicationController def index Bulletin.remove_expired_status params = OrbitHelper.params + locale = OrbitHelper.get_site_locale.to_s feeds_anns = [] top_anns = [] if !params['tags'].blank? @@ -58,7 +59,8 @@ class AnnouncementsController < ApplicationController "status-class" => "status-#{status['classname']}" } end - files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } } rescue [] + files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] + files.delete(nil) links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] author = User.find(a.create_user_id).member_profile.name rescue "" desc = a.image_description @@ -193,7 +195,8 @@ class AnnouncementsController < ApplicationController "status-class" => "status-#{status['classname']}" } end - files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } } rescue [] + files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] + files.delete(nil) links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] author = User.find(a.create_user_id).member_profile.name rescue "" desc = a.image_description @@ -241,6 +244,7 @@ class AnnouncementsController < ApplicationController end def show_local_announcement(uid, is_preview) + locale = OrbitHelper.get_site_locale.to_s if is_preview announcement = Bulletin.where(:uid => uid).first else @@ -260,8 +264,9 @@ class AnnouncementsController < ApplicationController "tag" => tag.name , "url" => OrbitHelper.page_for_tag(tag) } } rescue [] - files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } } rescue [] - + files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] + files.delete(nil) + links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] update_user = announcement.update_user.member_profile.name rescue "" desc = announcement.image_description diff --git a/app/models/bulletin_file.rb b/app/models/bulletin_file.rb index dabe73a..5585035 100644 --- a/app/models/bulletin_file.rb +++ b/app/models/bulletin_file.rb @@ -8,7 +8,17 @@ class BulletinFile field :description, localize: true field :title, localize: true + field :choose_lang, :type => Array, :default => ["en","zh_tw"] belongs_to :bulletin + + def enabled_for?(lang) + if lang.nil? + return true + else + return self.choose_lang.include?(lang) + end + end + end diff --git a/app/views/admin/announcements/_form_file.html.erb b/app/views/admin/announcements/_form_file.html.erb index 8628623..981ddf4 100644 --- a/app/views/admin/announcements/_form_file.html.erb +++ b/app/views/admin/announcements/_form_file.html.erb @@ -39,6 +39,20 @@ <% end %> + + + + + <%= hidden_field_tag 'bulletin[bulletin_files_attributes][0][choose_lang][]', '' %> <% if form_file.new_record? %>