diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index a95a659..d81fdfb 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -590,10 +590,16 @@ class AnnouncementsController < ApplicationController img_src = (announcement.image.thumb.url || "/assets/announcement-default.jpg") if announcement.display_img? img_description = announcement.image_description if (announcement.image_description.present?) && (announcement.display_img?) show_comment_flag = announcement.open_comment_for_user(OrbitHelper.current_user) + bulletin_carousel_images = announcement.bulletin_carousel_images.map{|image| {"src"=>image.file.url,"description"=>image.description.to_s,"description_text"=>image.description_text }} + resume_btn_title = (I18n.locale.to_s =="zh_tw") ? "繼續播放" : "resume" + pause_btn_title = (I18n.locale.to_s =="zh_tw") ? "暫停播放" : "pause" + prev_btn_title = (I18n.locale.to_s =="zh_tw") ? "上一張" : "prev" + next_btn_title = (I18n.locale.to_s =="zh_tw") ? "下一張" : "next" { "tags" => tags, "bulletin_files" => files, "bulletin_links" => links, + "bulletin_carousel_images" => bulletin_carousel_images, "data" => { "title" => announcement.title, "subtitle_ann" => subtitle_ann, @@ -604,7 +610,13 @@ class AnnouncementsController < ApplicationController "img_src" => img_src, "img_description" => img_description, "hide_class" => announcement.display_img? ? '' : ' hide', - "alt_title" => desc + "alt_title" => desc, + "resume_btn_title" => resume_btn_title, + "pause_btn_title" => pause_btn_title, + "prev_btn_title" => prev_btn_title, + "next_btn_title" => next_btn_title, + "carousel_display_style" => (bulletin_carousel_images.count == 0 ? 'display: none' : ''), + "carousel_count" => bulletin_carousel_images.count }, "comments" => announcement.comments, "show_comment_flag" => show_comment_flag, @@ -665,6 +677,7 @@ class AnnouncementsController < ApplicationController "tags" => tags, "bulletin_files" => files, "bulletin_links" => links, + "bulletin_carousel_images" => [], "data" => { "title" => announcement["title_translations"][locale], "subtitle_ann" => subtitle_ann, @@ -675,7 +688,8 @@ class AnnouncementsController < ApplicationController "img_src" => img_src, "img_description" => img_description, "hide_class" => announcement["display_img"] ? '' : ' hide', - "alt_title" => desc + "alt_title" => desc, + "carousel_display_style" => 'display: none' }, "comments" => [], "show_comment_flag" => false, diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 9456b8a..42993a3 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -69,8 +69,10 @@ class Bulletin has_many :bulletin_links, :autosave => true, :dependent => :destroy has_many :bulletin_files, :autosave => true, :dependent => :destroy has_many :bulletin_comments, :autosave => true, :dependent => :destroy + has_many :bulletin_carousel_images, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :bulletin_files, :allow_destroy => true accepts_nested_attributes_for :bulletin_links, :allow_destroy => true + accepts_nested_attributes_for :bulletin_carousel_images, :allow_destroy => true before_destroy :destroy_email diff --git a/app/models/bulletin_carousel_image.rb b/app/models/bulletin_carousel_image.rb new file mode 100644 index 0000000..47e6c93 --- /dev/null +++ b/app/models/bulletin_carousel_image.rb @@ -0,0 +1,15 @@ +# encoding: utf-8 +class BulletinCarouselImage + + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :file, AssetUploader + + field :description, localize: true + + belongs_to :bulletin + def description_text + Nokogiri::HTML(self.description.to_s).css("body").text() rescue "" + end +end diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index 91f9af2..5c4c563 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -52,6 +52,7 @@ <% end %>
+ <%= hidden_field_tag 'bulletin_carousel_image_count', @bulletin.bulletin_carousel_images.count %> + <%= t(:add) %> +
+