diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb
index 79db80b..7a78ed0 100644
--- a/app/controllers/faqs_controller.rb
+++ b/app/controllers/faqs_controller.rb
@@ -1,6 +1,7 @@
class FaqsController < ApplicationController
def index
faqs = Qa.can_display.order_by(:order_position => "asc").filter_by_categories
+ locale = I18n.locale.to_s
f = faqs.collect do |qa|
statuses = qa.statuses_with_classname.collect do |status|
{
@@ -9,11 +10,12 @@ class FaqsController < ApplicationController
}
end
qa_files = qa.qa_files.map do |qa_file|
+ next if !qa_file.enabled_for?(locale)
{
"file_url" => qa_file.file.url + "\" title=\"#{qa_file.file_title}",
"file_title" => (qa_file.title.blank? ? File.basename(qa_file["file"]) : qa_file.title)
}
- end
+ end.compact
{
"link_to_show" => OrbitHelper.url_to_show(qa.to_param),
"question" => qa.title,
@@ -36,8 +38,10 @@ class FaqsController < ApplicationController
url_to_edit = OrbitHelper.user_can_edit?(faq) ? "/admin/faqs/#{faq.id.to_s}/edit" : ""
return {} if (faq.category.disable rescue false)
-
+ locale = I18n.locale.to_s
+
faqs_files = faq.qa_files.collect do |f|
+ next if !qa_file.enabled_for?(locale)
{
"file_url" => f.file.url + "\" title=\"#{f.file_title}",
"file_title" => f.title
diff --git a/app/models/qa_file.rb b/app/models/qa_file.rb
index f248259..d09e114 100644
--- a/app/models/qa_file.rb
+++ b/app/models/qa_file.rb
@@ -8,7 +8,7 @@ class QaFile
field :description, localize: true
field :should_destroy, :type => Boolean
field :title, localize: true
-
+ field :choose_lang, :type => Array, :default => ["en","zh_tw"]
belongs_to :qa
def file_title
if self.description.present?
@@ -19,4 +19,11 @@ class QaFile
return File.basename(self.file.path)
end
end
+ 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/faqs/_form_qa_file.html.erb b/app/views/admin/faqs/_form_qa_file.html.erb
index 785605c..7d70f48 100644
--- a/app/views/admin/faqs/_form_qa_file.html.erb
+++ b/app/views/admin/faqs/_form_qa_file.html.erb
@@ -40,6 +40,20 @@
<% end %>
+
+
+
+ <%= hidden_field_tag "bulletin[bulletin_files_attributes][#{( form_file.new_record? ? 'new_bulletin_files' : "#{i}" )}][choose_lang][]", '' %>
+
<% if form_qa_file.new_record? %>