add choose_lang for qa_file

This commit is contained in:
邱博亞 2021-11-15 12:35:23 +08:00
parent 2e1f9e3558
commit fff3b11cdb
3 changed files with 28 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -40,6 +40,20 @@
<% end %>
</span>
</span>
<span class="add-on btn-group btn" title="<%= t('archive.show_lang') %>">
<i class="icons-earth"></i> <span class="caret"></span>
<ul class="dropdown-menu">
<% @site_in_use_locales.each do |locale| %>
<li>
<label class="checkbox">
<%= check_box_tag "bulletin[bulletin_files_attributes][#{( form_file.new_record? ? 'new_bulletin_files' : "#{i}" )}][choose_lang][]", locale, form_file.choose_lang.include?(locale.to_s) %>
<%= t(locale.to_s) %>
</label>
</li>
<% end %>
</ul>
<%= hidden_field_tag "bulletin[bulletin_files_attributes][#{( form_file.new_record? ? 'new_bulletin_files' : "#{i}" )}][choose_lang][]", '' %>
</span>
<% if form_qa_file.new_record? %>
<span class="delete_file add-on btn" title="<%= t(:delete_) %>">
<a class="icon-trash"></a>