added file selection for announcement

This commit is contained in:
Harry Bomrah 2016-05-09 18:11:18 +08:00
parent 1d4ddef575
commit 3d1e7a1ad0
3 changed files with 33 additions and 4 deletions

View File

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

View File

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

View File

@ -39,6 +39,20 @@
</span>
<% 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][0][choose_lang][]', '' %>
</span>
<% if form_file.new_record? %>
<span class="delete_file add-on btn" title="<%= t(:delete_) %>">