2014-04-01 07:12:43 +00:00
|
|
|
class AnnouncementsController < ApplicationController
|
2023-05-06 08:24:25 +00:00
|
|
|
ViewRootDir = File.expand_path("../../views", __FILE__)
|
2020-02-01 03:47:52 +00:00
|
|
|
include AnnouncementsHelper
|
2023-02-02 08:10:39 +00:00
|
|
|
DefaultImgSrc = "/assets/announcement-default.jpg\" onerror=\"this.src="/assets/announcement-default-2.jpg";this.onerror='';"
|
2022-03-29 06:25:10 +00:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = 'announcement'
|
|
|
|
#self.request = OrbitHelper.request
|
|
|
|
end
|
2022-04-18 15:32:19 +00:00
|
|
|
def annc_depts_translations
|
|
|
|
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
|
|
|
OrbitHelper::SharedHash['announcement'][:annc_depts_translations] rescue AnnouncementSetting.first.annc_depts_translations
|
|
|
|
else
|
|
|
|
AnnouncementSetting.first.annc_depts_translations rescue {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def enable_annc_dept
|
|
|
|
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
|
|
|
OrbitHelper::SharedHash['announcement'][:enable_annc_dept] rescue AnnouncementSetting.first.enable_annc_dept
|
|
|
|
else
|
|
|
|
AnnouncementSetting.first.enable_annc_dept rescue false
|
|
|
|
end
|
|
|
|
end
|
2023-05-06 08:24:25 +00:00
|
|
|
def render_400
|
|
|
|
render(:file => "#{ViewRootDir}/announcements/400.html", :layout => false, :status => 400, :formats => [:html])
|
|
|
|
end
|
|
|
|
def render_404
|
|
|
|
render(:file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => 404, :formats => [:html])
|
|
|
|
end
|
2020-07-30 14:12:21 +00:00
|
|
|
def comment
|
|
|
|
@bulletin = Bulletin.where(:uid=>params[:uid]).first
|
|
|
|
comment_val = params['comment']
|
|
|
|
if !@bulletin.nil? && @bulletin.open_comment_for_user(OrbitHelper.current_user) && !comment_val.blank?
|
|
|
|
account_id = OrbitHelper.current_user.member_profile.id.to_s rescue 'visitor'
|
|
|
|
b = BulletinComment.new(ip: request.remote_ip,comment: comment_val,account_id: account_id)
|
|
|
|
b.bulletin_id = @bulletin.id
|
|
|
|
b.save
|
|
|
|
render :json => {}
|
2023-05-06 08:24:25 +00:00
|
|
|
else
|
|
|
|
render_404
|
2020-07-30 14:12:21 +00:00
|
|
|
end
|
|
|
|
end
|
2014-04-01 07:12:43 +00:00
|
|
|
def index
|
2021-12-28 08:01:33 +00:00
|
|
|
@type = 'index'
|
2015-12-22 11:04:13 +00:00
|
|
|
Bulletin.remove_expired_status
|
2022-02-27 04:58:52 +00:00
|
|
|
params = @params = OrbitHelper.params
|
|
|
|
page = @page || Page.where(url: params['url']).first
|
|
|
|
@enable_search_flag = false
|
2022-02-27 05:12:50 +00:00
|
|
|
@image_version = 'thumb'
|
2022-10-22 08:23:42 +00:00
|
|
|
if page.respond_to?(:select_option_items)
|
2024-10-13 13:42:37 +00:00
|
|
|
module_app = ModuleApp.where(key: 'announcement').first
|
|
|
|
@show_option_items = nil
|
|
|
|
if module_app && page.respond_to?(:select_option_items)
|
|
|
|
@show_option_items = module_app.show_option_items
|
2022-02-27 04:58:52 +00:00
|
|
|
end
|
|
|
|
I18n.with_locale(:en) do
|
|
|
|
page.select_option_items.each do |select_option_item|
|
|
|
|
if !(@show_option_items.nil?)
|
|
|
|
case select_option_item.field_name
|
|
|
|
when @show_option_items.keys[1].to_s
|
|
|
|
value = YAML.load(select_option_item.value)
|
|
|
|
if value[:en] == t('announcement.yes')
|
|
|
|
@enable_search_flag = true
|
|
|
|
end
|
|
|
|
when @show_option_items.keys[2].to_s
|
2022-03-01 08:44:05 +00:00
|
|
|
value = YAML.load(select_option_item.value)
|
|
|
|
tmp = value[:en]
|
2022-02-27 04:58:52 +00:00
|
|
|
if tmp == t('announcement.small_size')
|
|
|
|
@image_version = 'thumb'
|
|
|
|
elsif tmp == t('announcement.medium_size')
|
|
|
|
@image_version = 'mobile'
|
|
|
|
elsif tmp == t('announcement.orignal_size')
|
|
|
|
@image_version = 'orignal'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-01 07:49:01 +00:00
|
|
|
sorted,total_pages = get_sorted_annc
|
2021-10-09 14:28:55 +00:00
|
|
|
if sorted.nil?
|
|
|
|
sorted = []
|
|
|
|
total_pages = 0
|
|
|
|
end
|
2022-04-18 15:32:19 +00:00
|
|
|
annc_depts = []
|
|
|
|
tmp_enable_annc_dept = (enable_annc_dept rescue false)
|
|
|
|
if tmp_enable_annc_dept
|
|
|
|
annc_depts = annc_depts_translations[locale] rescue []
|
|
|
|
end
|
2020-03-01 07:49:01 +00:00
|
|
|
anns = sorted.collect do |a|
|
2020-03-17 01:26:34 +00:00
|
|
|
if a["source-site"].blank?
|
2016-04-11 08:32:15 +00:00
|
|
|
statuses = a.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
2020-03-11 10:56:39 +00:00
|
|
|
locale = OrbitHelper.get_site_locale.to_s
|
2021-09-16 09:15:44 +00:00
|
|
|
files = a.bulletin_files.to_fronted(locale)
|
2019-10-29 06:45:45 +00:00
|
|
|
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
2022-06-21 03:11:33 +00:00
|
|
|
author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.update_user_id).member_name rescue (User.find(a.update_user_id).member_profile.name rescue "")
|
2016-04-11 08:32:15 +00:00
|
|
|
desc = a.image_description
|
2020-03-17 01:26:34 +00:00
|
|
|
desc = (desc.blank? ? "announcement image" : desc)
|
2017-06-20 07:04:05 +00:00
|
|
|
link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)
|
|
|
|
target = a.is_external_link ? "_blank" : "_self"
|
2024-10-13 13:42:37 +00:00
|
|
|
title = a.title_plain_text
|
|
|
|
title = 'no content' if title.blank?
|
2022-02-27 04:58:52 +00:00
|
|
|
if @image_version == 'thumb'
|
|
|
|
image_url = a.image.thumb.url
|
|
|
|
elsif @image_version == 'mobile'
|
|
|
|
image_url = a.image.mobile.url
|
|
|
|
else
|
|
|
|
image_url = a.image.url
|
|
|
|
end
|
2020-03-01 07:49:01 +00:00
|
|
|
{
|
2020-05-19 04:31:57 +00:00
|
|
|
"department" => author,
|
2016-04-11 08:32:15 +00:00
|
|
|
"bulletin_links" => links,
|
|
|
|
"bulletin_files" => files,
|
|
|
|
"title" => a.title,
|
|
|
|
"source-site" => "",
|
|
|
|
"source-site-title" => "",
|
|
|
|
"source-site-link" => "",
|
|
|
|
"subtitle" => a.subtitle,
|
|
|
|
"statuses" => statuses,
|
2021-09-01 09:51:22 +00:00
|
|
|
"category" => (a.category.title rescue ""),
|
2016-04-11 08:32:15 +00:00
|
|
|
"postdate" => a.postdate,
|
|
|
|
"author" => author,
|
|
|
|
"is_top" => (a.is_top? ? 1 : 0),
|
2021-11-12 07:44:55 +00:00
|
|
|
"link_to_show" => link_to_show+"\" #{(link_to_show[0] == '/' rescue true) ? '' : 'target="_blank"'} title=\"#{title}",
|
2017-06-20 07:04:05 +00:00
|
|
|
"target" => target,
|
2023-02-02 08:10:39 +00:00
|
|
|
"img_src" => image_url || DefaultImgSrc,
|
2016-04-11 08:32:15 +00:00
|
|
|
"img_description" => desc,
|
2022-01-21 02:14:57 +00:00
|
|
|
"more" => t("announcement.more"),
|
2016-04-11 08:32:15 +00:00
|
|
|
"view_count" => a.view_count
|
2014-06-06 09:48:33 +00:00
|
|
|
}
|
2016-04-11 08:32:15 +00:00
|
|
|
else
|
2020-03-01 07:49:01 +00:00
|
|
|
a
|
2014-06-06 09:48:33 +00:00
|
|
|
end
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|
2021-08-05 10:19:42 +00:00
|
|
|
if anns.count == 0 && params.any?{|k,v| v.class==Array ? v.any?{|v1| v1.to_s.match(/\*|\(|\)/)} : v.to_s.match(/\*|\(|\)/)}
|
|
|
|
return nil
|
|
|
|
end
|
2015-02-25 02:58:51 +00:00
|
|
|
#If no data , hide title&table
|
2020-03-01 07:49:01 +00:00
|
|
|
if sorted.count == 0
|
2015-02-25 02:58:51 +00:00
|
|
|
display = "hide"
|
|
|
|
end
|
2016-04-11 08:32:15 +00:00
|
|
|
# anns = anns.concat(feeds_anns)
|
|
|
|
# total_pages = announcements.total_pages
|
2021-04-07 08:12:42 +00:00
|
|
|
page = Page.where(url:params['url']).first
|
|
|
|
@annc_page_title = nil
|
2021-04-08 03:46:02 +00:00
|
|
|
if (params['category'] != page.categories rescue true)
|
2021-04-07 08:12:42 +00:00
|
|
|
@annc_page_title = Category.find(Array(params['category']).first).title rescue nil
|
|
|
|
end
|
2021-05-17 04:01:50 +00:00
|
|
|
if (params["tags"] != page.tags && !params["tags"].blank? && params["tags"].count == 1 && params["tags"][0] != "all" rescue true)
|
2021-04-09 09:54:11 +00:00
|
|
|
@annc_page_title = Tag.find(Array(params['tags']).first).name rescue nil
|
|
|
|
end
|
2014-04-02 06:44:36 +00:00
|
|
|
{
|
2015-10-08 09:17:13 +00:00
|
|
|
"announcements" => anns,
|
2014-07-11 10:30:52 +00:00
|
|
|
"extras" => {
|
2014-09-19 07:28:17 +00:00
|
|
|
"widget-title" =>t('announcement.announcement'),
|
2014-09-19 07:54:41 +00:00
|
|
|
"title-head" => t('announcement.table.title'),
|
|
|
|
"date-head" => t('announcement.table.date'),
|
|
|
|
"status-head" => t('announcement.table.status'),
|
2019-10-29 06:45:45 +00:00
|
|
|
"author-head" => t('announcement.table.author'),
|
2014-09-19 07:54:41 +00:00
|
|
|
"subtitle-head" => t('announcement.table.sub_title'),
|
2015-01-16 09:01:33 +00:00
|
|
|
"category-head" => t('announcement.table.category'),
|
|
|
|
"link-head" => t('announcement.table.link'),
|
2015-02-25 02:58:51 +00:00
|
|
|
"file-head" => t('announcement.table.file'),
|
2015-03-16 08:56:53 +00:00
|
|
|
"view-count-head" => t('announcement.table.view_count'),
|
2020-05-19 04:31:57 +00:00
|
|
|
"display" => display,
|
2021-04-07 08:12:42 +00:00
|
|
|
"department-head" => t('announcement.table.department'),
|
2022-04-19 04:39:31 +00:00
|
|
|
"annc-dept-head" => t("announcement.annc_dept"),
|
2021-04-07 08:12:42 +00:00
|
|
|
"page-title" => @annc_page_title
|
2014-07-11 10:30:52 +00:00
|
|
|
},
|
2016-04-11 08:32:15 +00:00
|
|
|
"total_pages" => total_pages
|
2014-11-19 09:50:08 +00:00
|
|
|
}
|
2014-04-01 07:12:43 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-10-29 08:42:42 +00:00
|
|
|
def random_announcement_widget
|
2020-03-01 07:49:01 +00:00
|
|
|
pack_data(true)
|
2015-10-29 08:42:42 +00:00
|
|
|
end
|
|
|
|
|
2014-04-01 07:12:43 +00:00
|
|
|
def widget
|
2020-03-01 07:49:01 +00:00
|
|
|
pack_data()
|
2015-10-29 08:42:42 +00:00
|
|
|
end
|
|
|
|
|
2017-06-29 08:03:39 +00:00
|
|
|
def tag_cloud
|
|
|
|
ma = ModuleApp.where(:key => "announcement").first
|
|
|
|
temp = []
|
|
|
|
ma.tags.each do |tag|
|
|
|
|
t1 = tag.taggings.collect{|t| t.taggable_id.to_s}
|
2020-03-01 07:49:01 +00:00
|
|
|
count = Bulletin.where(:id.in => t1).can_display_and_sorted.count
|
2017-06-29 08:03:39 +00:00
|
|
|
temp << {
|
|
|
|
"tag-name" => tag.name,
|
|
|
|
"count" => count,
|
|
|
|
"tag-url" => OrbitHelper.widget_more_url + "?tags[]=" + tag.id.to_s
|
|
|
|
}
|
|
|
|
end
|
|
|
|
max = temp.max_by{|t| t["count"]}["count"]
|
|
|
|
tags = []
|
|
|
|
temp.each do |tag|
|
|
|
|
if tag["count"] > 0
|
|
|
|
percent = (tag["count"] * 100) / max
|
2017-06-29 08:43:57 +00:00
|
|
|
font_size = ((percent / 10).round) + 16
|
2017-06-29 08:03:39 +00:00
|
|
|
tag["font-size"] = font_size
|
|
|
|
tags << tag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"tags" => tags,
|
|
|
|
"extras" => {}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-03-01 07:49:01 +00:00
|
|
|
def pack_data(is_random=false)
|
|
|
|
cats = OrbitHelper.widget_categories || []
|
2021-04-09 07:59:01 +00:00
|
|
|
tags = OrbitHelper.widget_tags || []
|
2021-09-15 12:50:30 +00:00
|
|
|
tags = ['all'] if tags.blank?
|
2020-01-21 14:31:59 +00:00
|
|
|
subpart = OrbitHelper.get_current_widget
|
2021-04-07 08:12:42 +00:00
|
|
|
get_tabs_option
|
|
|
|
anns = []
|
2021-04-09 07:59:01 +00:00
|
|
|
use_tag = false
|
2022-04-19 09:46:07 +00:00
|
|
|
@annc_depts = []
|
|
|
|
@tmp_enable_annc_dept = (enable_annc_dept rescue false)
|
|
|
|
if @tmp_enable_annc_dept
|
|
|
|
@annc_depts = annc_depts_translations[locale] rescue []
|
|
|
|
end
|
2021-04-07 08:12:42 +00:00
|
|
|
if @tab_option == 0
|
2021-04-09 09:45:58 +00:00
|
|
|
anns = get_anncs_for_pack_data(cats,tags,nil,is_random)
|
2021-04-07 08:12:42 +00:00
|
|
|
else
|
2021-04-09 07:59:01 +00:00
|
|
|
if cats.count != 1 || tags == ["all"]
|
|
|
|
cats.each do |cat|
|
2021-09-15 12:50:30 +00:00
|
|
|
anns = anns + get_anncs_for_pack_data([cat],tags,'',is_random)
|
2021-04-09 07:59:01 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
tags.each do |tag|
|
2021-09-15 12:50:30 +00:00
|
|
|
anns = anns + get_anncs_for_pack_data(cats,[tag],tag,is_random)
|
2021-04-09 07:59:01 +00:00
|
|
|
end
|
|
|
|
use_tag = true
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
mp = (anns[0]["img_src"] rescue "")
|
|
|
|
mpd = (anns[0]["img_description"] rescue "")
|
|
|
|
if @tab_option == 1
|
2021-04-09 07:59:01 +00:00
|
|
|
if use_tag
|
|
|
|
tags = ["all"] + tags
|
|
|
|
else
|
|
|
|
cats = ["all"] + cats
|
|
|
|
end
|
2024-10-13 13:42:37 +00:00
|
|
|
anns = sort_announcements(anns)
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
|
|
|
cats = cats.uniq
|
2021-04-09 07:59:01 +00:00
|
|
|
tags = tags.uniq
|
2021-10-11 05:57:17 +00:00
|
|
|
tags_translations = (subpart.get_tags_translations(false,false) rescue nil)
|
|
|
|
tags_translations = Tag.where(:id.in=>tags).map{|t| [t.id.to_s,t.name]} if tags_translations.nil?
|
2021-10-10 09:35:14 +00:00
|
|
|
if tags.include?("all")
|
2021-10-10 10:42:15 +00:00
|
|
|
tags_translations = [["all",I18n.t(:all)]] + tags_translations
|
2021-10-10 09:35:14 +00:00
|
|
|
end
|
|
|
|
tags_translations = tags_translations.to_h
|
2021-10-11 05:57:17 +00:00
|
|
|
cats_translations = (subpart.get_cats_translations(false,false) rescue nil)
|
|
|
|
cats_translations = Category.where(:id.in=>cats).map{|c| [c.id.to_s,c.title]} if cats_translations.nil?
|
2021-10-10 09:35:14 +00:00
|
|
|
if cats.include?("all")
|
2021-10-10 10:42:15 +00:00
|
|
|
cats_translations = [["all",I18n.t(:all)]] + cats_translations
|
2021-10-10 09:35:14 +00:00
|
|
|
end
|
|
|
|
cats_translations = cats_translations.to_h
|
2021-11-07 04:22:45 +00:00
|
|
|
if cats.include?("all")
|
|
|
|
cats_relations = cats_translations.clone
|
|
|
|
cats_relations['all'] = 'all'
|
|
|
|
else
|
|
|
|
cats_relations = cats_translations
|
|
|
|
end
|
2021-10-10 09:35:14 +00:00
|
|
|
page_url = (subpart.get_read_more_page_url rescue nil)
|
2021-08-20 01:21:25 +00:00
|
|
|
locale = I18n.locale.to_s
|
2021-10-10 09:35:14 +00:00
|
|
|
if page_url.nil?
|
2021-11-07 04:22:45 +00:00
|
|
|
home_page = subpart.page_part.page rescue Page.first
|
2021-10-10 09:35:14 +00:00
|
|
|
page = nil
|
|
|
|
if home_page.respond_to?(:find_page)
|
|
|
|
page = home_page.find_page(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
|
|
|
|
page = home_page.find_page(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
|
|
|
|
else
|
|
|
|
page = Page.where(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
|
|
|
|
page = Page.where(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
|
|
|
|
end
|
2021-11-17 10:01:33 +00:00
|
|
|
page_url = "/#{locale}#{(page.get_url rescue page.url)}"
|
2021-08-20 01:21:25 +00:00
|
|
|
end
|
2021-04-08 03:46:02 +00:00
|
|
|
all_cats = cats.dup
|
|
|
|
all_cats.delete "all"
|
|
|
|
if all_cats.count == 0
|
|
|
|
all_cats = ["all"]
|
|
|
|
end
|
2021-04-09 07:59:01 +00:00
|
|
|
all_tags = tags.dup
|
|
|
|
all_tags.delete "all"
|
|
|
|
if all_tags.count == 0
|
|
|
|
all_tags = ["all"]
|
|
|
|
end
|
2021-04-08 05:20:01 +00:00
|
|
|
max_all_count = [OrbitHelper.widget_data_count,anns.count].min
|
2021-04-07 08:12:42 +00:00
|
|
|
if @tab_option != 0
|
|
|
|
OrbitHelper.set_widget_title(OrbitHelper.widget_title +
|
|
|
|
"<div style=\"clear: both;\"></div>" +
|
|
|
|
"<ul class=\"nav_tabs_filter\">" +
|
2021-04-09 07:59:01 +00:00
|
|
|
(use_tag ? tags.map.with_index{|tag,i|
|
2021-11-17 09:07:08 +00:00
|
|
|
read_more_url = "#{page_url}" rescue ""
|
2021-04-09 07:59:01 +00:00
|
|
|
read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>(tag == 'all' ? all_tags : [tag])}.to_param if read_more_url != ""
|
|
|
|
read_more_text = I18n.t("announcement.more")
|
|
|
|
if tag != "all"
|
|
|
|
begin
|
|
|
|
read_more_text = I18n.t("announcement.more_") + tags_translations[tag]
|
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2021-04-09 09:45:58 +00:00
|
|
|
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(tag == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-tags=\"#{tag}\">#{tags_translations[tag]}</li>"
|
2021-04-09 07:59:01 +00:00
|
|
|
}.join("") : cats.map.with_index{|cat,i|
|
2021-11-17 09:07:08 +00:00
|
|
|
read_more_url = "#{page_url}" rescue ""
|
2021-04-08 03:46:02 +00:00
|
|
|
read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != ""
|
|
|
|
read_more_text = I18n.t("announcement.more")
|
|
|
|
if cat != "all"
|
|
|
|
begin
|
|
|
|
read_more_text = I18n.t("announcement.more_") + cats_translations[cat]
|
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2021-04-08 05:20:01 +00:00
|
|
|
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(cat == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-category=\"#{cats_relations[cat]}\">#{cats_translations[cat]}</li>"
|
2021-04-09 07:59:01 +00:00
|
|
|
}.join("")) +
|
2021-04-07 08:12:42 +00:00
|
|
|
"</ul>"
|
|
|
|
)
|
2021-04-09 07:59:01 +00:00
|
|
|
filter_attr = (use_tag ? 'data-tags' : 'data-category')
|
2021-04-07 08:12:42 +00:00
|
|
|
extra_html = '
|
2021-11-12 07:17:47 +00:00
|
|
|
<script style="display:none">
|
2021-04-07 08:12:42 +00:00
|
|
|
if(typeof(wpexAnimsition) == "undefined"){
|
|
|
|
var wpexAnimsition = {
|
|
|
|
"loading":"1",
|
|
|
|
"inDuration":"400",
|
|
|
|
"outDuration":"400",
|
|
|
|
"inClass":"fade-in",
|
|
|
|
"outClass":"fade-out",
|
2021-05-20 05:40:14 +00:00
|
|
|
"need_fix_containers":".widget-announcement-4,.widget-announcement-15",
|
2021-04-07 08:12:42 +00:00
|
|
|
"linkElement": "[data-list=\"announcements\"] > *",
|
|
|
|
"children_text_block": ".w-annc__content-wrap",
|
2021-04-07 10:47:22 +00:00
|
|
|
"container_block": "[data-subpart-id=\"'+subpart.id.to_s+'\"] [data-list=\"announcements\"]:not(tbody)",
|
2021-04-07 08:12:42 +00:00
|
|
|
"parent_block": "[data-subpart-id=\"'+subpart.id.to_s+'\"]",
|
|
|
|
"filter_bar": ".nav_tabs_filter",
|
|
|
|
"filter_option": "li.filter_tab",
|
2021-04-09 07:59:01 +00:00
|
|
|
"filter_attr": "'+filter_attr+'",
|
2021-04-07 08:12:42 +00:00
|
|
|
"filter_target_attr": "class",
|
|
|
|
"use_attr_filter": true,
|
|
|
|
"equal_height": false
|
|
|
|
};
|
|
|
|
}else{
|
2021-04-09 07:59:01 +00:00
|
|
|
var filter_attr = "'+filter_attr+'";
|
2023-07-07 03:48:08 +00:00
|
|
|
wpexAnimsition.parent_block = wpexAnimsition.parent_block + ",[data-subpart-id=\"'+subpart.id.to_s+'\"]";
|
|
|
|
wpexAnimsition.container_block = wpexAnimsition.container_block + ",[data-subpart-id=\"'+subpart.id.to_s+'\"] [data-list=\"announcements\"]:not(tbody)";
|
2021-04-09 07:59:01 +00:00
|
|
|
if( wpexAnimsition.filter_attr.indexOf(filter_attr) == -1 ){
|
|
|
|
wpexAnimsition.filter_attr += ("," + filter_attr);
|
|
|
|
}
|
2021-04-07 08:12:42 +00:00
|
|
|
}
|
|
|
|
var wpexLocalize = {
|
|
|
|
"lightboxType": "iLightbox",
|
|
|
|
"iLightbox": { "auto": false, "skin": "minimal", "path": "horizontal",
|
|
|
|
"infinite": false, "maxScale": 1, "minScale": 0, "width": 1400, "height": "",
|
|
|
|
"slideshow": { "pauseTime": 3000, "startPaused": true },
|
|
|
|
"effects": { "reposition": true, "repositionSpeed": 200, "switchSpeed": 300,
|
|
|
|
"loadedFadeSpeed": 50, "fadeSpeed": 500
|
|
|
|
},
|
|
|
|
"show": { "title": true, "speed": 200 },
|
|
|
|
"hide": { "speed": 200 },
|
|
|
|
"overlay": { "blur": true, "opacity": "0.9" },
|
|
|
|
"slideShow": "Slideshow", "next": "Next", "previous": "Previous" ,
|
|
|
|
"thumbnails": { "maxWidth": 120, "maxHeight": 80 }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$(document).ready(function(){
|
|
|
|
var first_filter_tab = $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .filter_tab").eq(0);
|
|
|
|
var read_more_url = first_filter_tab.data("read_more");
|
2021-04-07 12:00:15 +00:00
|
|
|
if(read_more_url.length != 0){
|
|
|
|
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").attr("href",read_more_url);
|
2021-04-08 03:46:02 +00:00
|
|
|
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text(first_filter_tab.data("read_more_text"));
|
2021-04-07 12:00:15 +00:00
|
|
|
}
|
2021-04-07 08:12:42 +00:00
|
|
|
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .filter_tab").click(function(){
|
|
|
|
var read_more_url = $(this).data("read_more");
|
2021-04-07 12:00:15 +00:00
|
|
|
if(read_more_url.length != 0){
|
|
|
|
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").attr("href",read_more_url);
|
2021-04-08 03:46:02 +00:00
|
|
|
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text($(this).data("read_more_text"));
|
2021-04-07 12:00:15 +00:00
|
|
|
}
|
2021-04-07 08:12:42 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
<script src="/assets/bulletin/wpex.min.js"></script>
|
|
|
|
<style>
|
|
|
|
[data-list="announcements"] {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
'
|
|
|
|
else
|
2021-04-07 12:00:15 +00:00
|
|
|
read_more_text = I18n.t("announcement.more")
|
|
|
|
if cats.count == 1 && cats[0] != "all"
|
|
|
|
begin
|
2021-04-09 10:04:53 +00:00
|
|
|
read_more_text = I18n.t("announcement.more_") + ((all_tags.count == 1 && all_tags[0] != 'all') ? tags_translations[tags[0]] : cats_translations[cats[0]])
|
2021-04-07 12:00:15 +00:00
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
extra_html = "
|
2021-11-08 06:11:00 +00:00
|
|
|
<script style=\"display:none\">
|
2021-04-07 12:00:15 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] .w-annc__more\").text(\"#{read_more_text}\");
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
"
|
|
|
|
end
|
|
|
|
if (@read_more_option != 0 rescue false)
|
|
|
|
extra_html += "
|
2021-11-08 06:11:00 +00:00
|
|
|
<script style=\"display:none\">
|
2021-04-07 12:00:15 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
var read_more_position = #{@read_more_option};
|
|
|
|
var read_more_block = $(\"[data-subpart-id=\\\"#{subpart.id}\\\"] .w-annc__more\");
|
2023-02-18 00:19:42 +00:00
|
|
|
if(read_more_position == 5){
|
|
|
|
read_more_block.css('display', 'none');
|
2021-04-07 12:00:15 +00:00
|
|
|
}else{
|
2023-02-18 00:19:42 +00:00
|
|
|
if(read_more_position == 1 || read_more_position == 2){
|
|
|
|
read_more_block.addClass(\"pull-left\");
|
2021-04-07 12:00:15 +00:00
|
|
|
}else{
|
2023-02-18 00:19:42 +00:00
|
|
|
read_more_block.addClass(\"pull-right\");
|
2021-04-07 12:00:15 +00:00
|
|
|
}
|
2023-02-18 00:19:42 +00:00
|
|
|
if(read_more_position == 1 || read_more_position == 3){
|
|
|
|
var first_element = $(\"[data-subpart-id=\\\"#{subpart.id}\\\"] > *:eq(0)\");
|
|
|
|
var div_clearfix = $('<div class=\"clearfix\"></div>')
|
|
|
|
if(first_element.height() == 0){
|
|
|
|
read_more_block.appendTo(div_clearfix);
|
|
|
|
}else{
|
|
|
|
div_clearfix = read_more_block;
|
|
|
|
}
|
|
|
|
first_element.before(div_clearfix);
|
|
|
|
var annc_title = $(\"[data-subpart-id=\\\"#{subpart.id}\\\"] .w-annc__widget-title\").eq(0);
|
|
|
|
if(annc_title.length != 0){
|
|
|
|
read_more_block.appendTo(\"[data-subpart-id=\\\"#{subpart.id}\\\"] .w-annc__widget-title:eq(0)\");
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
var div_clearfix = $('<div class=\"clearfix\"></div>');
|
|
|
|
read_more_block.appendTo(div_clearfix);
|
|
|
|
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] > *:eq(-1)\").after(div_clearfix);
|
2021-08-05 03:49:35 +00:00
|
|
|
}
|
2021-04-07 12:00:15 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
"
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
2021-04-08 03:46:02 +00:00
|
|
|
extra_after_html = ""
|
|
|
|
if @all_setting_option == 0 && @tab_option == 1
|
|
|
|
extra_after_html = "
|
2021-11-08 06:11:00 +00:00
|
|
|
<script style=\"display:none\">
|
2021-04-08 03:46:02 +00:00
|
|
|
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] [data-list] [data-category]\").css(\"display\",\"none\");
|
|
|
|
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] [data-list] [data-category]:lt(#{max_all_count})\").css(\"display\",\"\");
|
|
|
|
</script>
|
|
|
|
"
|
|
|
|
end
|
|
|
|
if @tab_option == 0
|
2021-11-17 09:07:08 +00:00
|
|
|
read_more_url = "#{page_url}" rescue ""
|
2021-04-09 10:04:53 +00:00
|
|
|
read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>all_tags}.to_param if read_more_url != ""
|
2021-04-08 03:46:02 +00:00
|
|
|
extra_after_html += "
|
2021-11-08 06:11:00 +00:00
|
|
|
<script style=\"display:none\">
|
2021-04-08 03:46:02 +00:00
|
|
|
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] .w-annc__more\").attr(\"href\",\"#{read_more_url}\");
|
|
|
|
</script>
|
|
|
|
"
|
|
|
|
end
|
2021-04-07 08:12:42 +00:00
|
|
|
{
|
|
|
|
"announcements" => anns,
|
|
|
|
"extras" => {
|
2021-08-20 01:21:25 +00:00
|
|
|
"more_url"=>read_more_url,
|
2021-04-07 08:12:42 +00:00
|
|
|
"main_picture" => mp,
|
|
|
|
"main_picture_description" => mpd,
|
|
|
|
"title-head" => t('announcement.table.title'),
|
|
|
|
"date-head" => t('announcement.table.date'),
|
|
|
|
"author-head" => t('announcement.table.author'),
|
2022-04-19 04:39:31 +00:00
|
|
|
"annc-dept-head" => t("announcement.annc_dept"),
|
2021-04-07 08:12:42 +00:00
|
|
|
"status-head" => t('announcement.table.status'),
|
|
|
|
"subtitle-head" => t('announcement.table.sub_title'),
|
|
|
|
"category-head" => t('announcement.table.category'),
|
|
|
|
"link-head" => t('announcement.table.link'),
|
|
|
|
"file-head" => t('announcement.table.file'),
|
2021-04-08 03:46:02 +00:00
|
|
|
"read_more" => read_more_url,
|
2021-04-07 08:12:42 +00:00
|
|
|
"read_more_text" => "read more",
|
2021-04-08 03:46:02 +00:00
|
|
|
"extra_brefore_html" => extra_html,
|
|
|
|
"extra_after_html" => extra_after_html
|
2021-04-07 08:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
def get_tabs_option
|
|
|
|
subpart = OrbitHelper.get_current_widget
|
|
|
|
tab_options = ["not_enable_tabs","enable_tabs_with_categories_include_all","enable_tabs_with_categories"]
|
2023-02-18 00:19:42 +00:00
|
|
|
read_more_options = ['default','upper_left','lower_left','upper_right','lower_right', 'display_none']
|
2021-04-08 03:46:02 +00:00
|
|
|
all_setting_options = ['the_same_as_data_count','display_all_in_other_tabs']
|
2021-04-07 08:12:42 +00:00
|
|
|
@tab_option = 0
|
2021-04-07 12:00:15 +00:00
|
|
|
@read_more_option = 0
|
2021-04-08 03:46:02 +00:00
|
|
|
@all_setting_option = 0
|
2021-09-19 13:47:39 +00:00
|
|
|
@image_version = 'thumb'
|
2024-10-13 13:42:37 +00:00
|
|
|
@show_options = nil
|
2021-04-07 08:12:42 +00:00
|
|
|
if subpart.methods.include? 'select_options'.to_sym
|
2024-10-13 13:42:37 +00:00
|
|
|
module_app = ModuleApp.where(key: 'announcement').first
|
|
|
|
if module_app
|
|
|
|
@show_options = module_app.show_options
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
2022-02-27 04:58:52 +00:00
|
|
|
I18n.with_locale(:en) do
|
|
|
|
subpart.select_options.each do |select_option|
|
|
|
|
if !(@show_options.nil?)
|
|
|
|
value = YAML.load(select_option.value)
|
|
|
|
tmp = value[:en]
|
2021-09-17 09:23:32 +00:00
|
|
|
case select_option.field_name
|
|
|
|
when @show_options.keys[0].to_s
|
|
|
|
if tmp == t('announcement.small_size')
|
|
|
|
@image_version = 'thumb'
|
|
|
|
elsif tmp == t('announcement.medium_size')
|
|
|
|
@image_version = 'mobile'
|
|
|
|
elsif tmp == t('announcement.orignal_size')
|
|
|
|
@image_version = 'orignal'
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
2021-09-17 09:23:32 +00:00
|
|
|
when @show_options.keys[1].to_s
|
|
|
|
tab_options.each_with_index do |option,i|
|
|
|
|
if tmp == t("announcement.#{option}")
|
|
|
|
@tab_option = i
|
|
|
|
break
|
|
|
|
end
|
2021-04-07 12:00:15 +00:00
|
|
|
end
|
2021-09-17 09:23:32 +00:00
|
|
|
when @show_options.keys[2].to_s
|
|
|
|
read_more_options.each_with_index do |option,i|
|
|
|
|
if tmp == t("announcement.#{option}")
|
|
|
|
@read_more_option = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
when @show_options.keys[3].to_s
|
|
|
|
all_setting_options.each_with_index do |option,i|
|
|
|
|
if tmp == t("announcement.#{option}")
|
|
|
|
@all_setting_option = i
|
|
|
|
break
|
|
|
|
end
|
2021-04-08 03:46:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-09 09:45:58 +00:00
|
|
|
def get_anncs_for_pack_data(cats,tags,set_tags=nil,is_random = false)
|
2022-04-19 09:46:07 +00:00
|
|
|
if @annc_depts.nil?
|
|
|
|
@annc_depts = []
|
|
|
|
@tmp_enable_annc_dept = (enable_annc_dept rescue false)
|
|
|
|
if @tmp_enable_annc_dept
|
|
|
|
@annc_depts = annc_depts_translations[locale] rescue []
|
|
|
|
end
|
|
|
|
end
|
2021-09-16 09:15:44 +00:00
|
|
|
if tags.blank?
|
|
|
|
tags = ["all"]
|
|
|
|
end
|
2021-04-07 08:12:42 +00:00
|
|
|
subpart = OrbitHelper.get_current_widget
|
2020-03-01 07:49:01 +00:00
|
|
|
widget_data_count = OrbitHelper.widget_data_count
|
2021-04-09 07:59:01 +00:00
|
|
|
anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s)
|
2022-06-04 06:55:30 +00:00
|
|
|
devide_flag = (!(defined? SiteFeed).nil?) && (SiteFeed.count != 0)
|
2022-03-17 07:36:31 +00:00
|
|
|
anns_cache.all_of([{:invalid_date.ne=>nil},{:invalid_date.lte => Time.now}]).destroy
|
2021-08-13 04:42:14 +00:00
|
|
|
count = anns_cache.count
|
|
|
|
if count > 1
|
|
|
|
anns_cache.limit(count-1).destroy
|
2021-08-05 10:19:42 +00:00
|
|
|
end
|
|
|
|
if anns_cache.count == 0 || is_random
|
2020-03-01 07:49:01 +00:00
|
|
|
Bulletin.remove_expired_status
|
|
|
|
uid = OrbitHelper.params[:uid] rescue ""
|
2021-08-13 04:42:14 +00:00
|
|
|
anns_for_locale = Bulletin.where(:title.nin => ["",nil], :uid.ne => uid).is_approved_and_show.filter_cats_and_tags(cats,tags)
|
2021-08-05 10:19:42 +00:00
|
|
|
sorted_anns = anns_for_locale.can_display_and_sorted
|
2020-03-01 07:49:01 +00:00
|
|
|
if !is_random
|
|
|
|
sorted_anns = sorted_anns.limit(widget_data_count)
|
2021-08-05 10:19:42 +00:00
|
|
|
first_deadline = sorted_anns.pluck(:deadline).compact.sort[0]
|
|
|
|
first_postdate = anns_for_locale.open_in_future.limit(1).pluck(:postdate)[0]
|
|
|
|
invalid_date = [first_postdate,first_deadline].compact.sort[0]
|
|
|
|
|
2020-05-06 11:30:09 +00:00
|
|
|
if devide_flag
|
|
|
|
now_anns = sorted_anns.to_a
|
2021-04-09 09:45:58 +00:00
|
|
|
top_anns = now_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)}
|
|
|
|
not_top_anns = now_anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)}
|
2021-08-05 10:19:42 +00:00
|
|
|
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_anns,not_top: not_top_anns},invalid_date: invalid_date)
|
2020-05-06 11:30:09 +00:00
|
|
|
else
|
2021-04-09 09:45:58 +00:00
|
|
|
anns = sorted_anns.map{|v| data_to_human_type(v,set_tags)}
|
2021-08-05 10:19:42 +00:00
|
|
|
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: anns,invalid_date: invalid_date)
|
2020-05-06 11:30:09 +00:00
|
|
|
end
|
2020-03-01 07:49:01 +00:00
|
|
|
else
|
2022-03-17 07:36:31 +00:00
|
|
|
invalid_date = Time.now + 3.second
|
2020-05-28 07:30:16 +00:00
|
|
|
if devide_flag
|
2020-05-28 07:33:56 +00:00
|
|
|
anns = sorted_anns.sample(widget_data_count)
|
2021-04-09 09:45:58 +00:00
|
|
|
top_anns = anns.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)}
|
|
|
|
not_top_anns = anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)}
|
2020-05-28 07:30:16 +00:00
|
|
|
else
|
2021-04-09 09:45:58 +00:00
|
|
|
anns = sorted_anns.sample(widget_data_count).map{|v| data_to_human_type(v,set_tags)}
|
2020-05-28 07:30:16 +00:00
|
|
|
end
|
2020-01-21 14:31:59 +00:00
|
|
|
end
|
2020-05-06 11:30:09 +00:00
|
|
|
elsif devide_flag
|
2022-03-17 07:36:31 +00:00
|
|
|
c = anns_cache.first
|
|
|
|
now_anns = c.filter_result
|
|
|
|
invalid_date = c.invalid_date
|
2020-05-06 11:30:09 +00:00
|
|
|
top_anns = now_anns[:top]
|
|
|
|
not_top_anns = now_anns[:not_top]
|
2019-10-29 07:51:02 +00:00
|
|
|
else
|
2022-03-17 07:36:31 +00:00
|
|
|
c = anns_cache.first
|
|
|
|
invalid_date = c.invalid_date
|
|
|
|
anns = c.filter_result
|
|
|
|
end
|
|
|
|
if @page_invalid_time.nil?
|
|
|
|
@page_invalid_time = invalid_date
|
|
|
|
elsif !invalid_date.nil? && @page_invalid_time>invalid_date
|
|
|
|
@page_invalid_time = invalid_date
|
2016-04-11 08:32:15 +00:00
|
|
|
end
|
2020-05-06 11:30:09 +00:00
|
|
|
if devide_flag
|
2024-10-13 13:42:37 +00:00
|
|
|
feeds_anns, _ = get_feed_announcements("widget",nil,cats,widget_data_count - top_anns.count)
|
|
|
|
top_anns += feeds_anns.select{|v| v['is_top'] == true}
|
|
|
|
top_anns = sort_announcements(top_anns)
|
2020-03-01 07:49:01 +00:00
|
|
|
rest_count = widget_data_count - top_anns.count
|
|
|
|
if rest_count <= 0
|
2021-09-08 04:42:25 +00:00
|
|
|
anns = top_anns.take(widget_data_count)
|
2019-10-29 06:45:45 +00:00
|
|
|
else
|
2020-05-06 11:30:09 +00:00
|
|
|
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + not_top_anns.take(rest_count)
|
2024-10-13 13:42:37 +00:00
|
|
|
rest_anns = sort_announcements(rest_all_anns).take(rest_count)
|
2021-09-08 04:42:25 +00:00
|
|
|
anns = top_anns + rest_anns
|
2019-10-29 06:45:45 +00:00
|
|
|
end
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|
2024-04-25 13:41:54 +00:00
|
|
|
anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') if a["postdate"] }
|
2021-04-07 08:12:42 +00:00
|
|
|
anns
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|
2021-09-16 09:15:44 +00:00
|
|
|
|
2020-12-22 05:24:03 +00:00
|
|
|
def get_file
|
|
|
|
@url = request.path
|
2021-08-04 12:17:56 +00:00
|
|
|
begin
|
|
|
|
if @url.match(/\/\.\./)
|
2021-08-04 12:14:32 +00:00
|
|
|
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :content_type => 'text/html'
|
|
|
|
return
|
2021-08-04 12:17:56 +00:00
|
|
|
end
|
2020-12-22 05:24:03 +00:00
|
|
|
file = BulletinFile.find(params[:id])
|
2021-07-20 11:54:13 +00:00
|
|
|
if File.basename(file.file.path) != URI.decode(params[:f_name])
|
|
|
|
render :file => "#{Rails.root}/app/views/errors/403.html", :layout => false, :status => :not_found, :content_type => 'text/html'
|
|
|
|
return
|
|
|
|
end
|
2020-12-22 05:24:03 +00:00
|
|
|
@url = file.file.url
|
|
|
|
if file.can_access?(OrbitHelper.current_user)
|
|
|
|
@path = file.file.path rescue ""
|
|
|
|
@filename = @path.split("/").last
|
|
|
|
@ext = @path.split("/").last.to_s.split(".").last
|
|
|
|
if @ext == "png" || @ext == "jpg" || @ext == "bmp" || @ext == "pdf"
|
|
|
|
render "archives/download_file.html",:layout=>false
|
|
|
|
else
|
2021-06-21 10:15:33 +00:00
|
|
|
if (current_site.accessibility_mode rescue false)
|
2021-06-26 04:17:27 +00:00
|
|
|
render "archives/redirect_to_file.html",:layout=>false
|
2021-08-04 12:17:56 +00:00
|
|
|
return
|
2021-06-21 10:15:33 +00:00
|
|
|
else
|
2023-05-19 13:05:00 +00:00
|
|
|
user_agent = request.user_agent.downcase
|
2023-05-19 13:13:13 +00:00
|
|
|
@escaped_file_name = user_agent.match(/(msie|trident)/) ? CGI::escape(@filename) : @filename
|
2023-05-19 13:05:00 +00:00
|
|
|
send_file(@path, :type=>"application/octet-stream", :filename => @escaped_file_name, :x_sendfile=> true)
|
2021-08-04 12:17:56 +00:00
|
|
|
return
|
2021-06-21 10:15:33 +00:00
|
|
|
end
|
2020-12-22 05:24:03 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
render :file => "#{Rails.root}/app/views/errors/403.html", :layout => false, :status => :not_found, :content_type => 'text/html'
|
2021-08-04 12:17:56 +00:00
|
|
|
return
|
2020-12-22 05:24:03 +00:00
|
|
|
end
|
2023-05-19 13:10:48 +00:00
|
|
|
rescue => e
|
|
|
|
puts [e, e.backtrace]
|
2020-12-22 05:24:03 +00:00
|
|
|
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :content_type => 'text/html'
|
2021-08-04 12:17:56 +00:00
|
|
|
return
|
2020-12-22 05:24:03 +00:00
|
|
|
end
|
|
|
|
end
|
2021-09-16 09:15:44 +00:00
|
|
|
|
2015-10-19 08:59:26 +00:00
|
|
|
def show_local_announcement(uid, is_preview)
|
2016-05-09 10:11:18 +00:00
|
|
|
locale = OrbitHelper.get_site_locale.to_s
|
2015-10-19 08:59:26 +00:00
|
|
|
if is_preview
|
2016-05-02 09:36:21 +00:00
|
|
|
announcement = Bulletin.where(:uid => uid).first
|
2015-10-19 08:59:26 +00:00
|
|
|
else
|
2020-03-01 07:49:01 +00:00
|
|
|
announcement = Bulletin.can_display_and_sorted.where(:uid => uid).first
|
2015-10-19 08:59:26 +00:00
|
|
|
end
|
2020-05-17 13:24:56 +00:00
|
|
|
announcement = Bulletin.where(:uid => uid).first if announcement.nil?
|
2022-11-24 16:13:30 +00:00
|
|
|
return nil if announcement.nil?
|
2022-04-26 03:35:11 +00:00
|
|
|
@bulletin = announcement
|
|
|
|
|
2014-08-05 06:37:33 +00:00
|
|
|
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
|
|
|
|
|
2014-09-22 08:32:30 +00:00
|
|
|
access_level = OrbitHelper.user_access_level?
|
|
|
|
|
|
|
|
if !announcement.approved && (access_level != "manager" && access_level != "admin")
|
2017-08-24 12:31:51 +00:00
|
|
|
if AnnouncementSetting.is_pro?
|
|
|
|
if !(access_level == "sub_manager" && AnnouncementSetting.first.approvers.include?(OrbitHelper.current_user.id.to_s))
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
elsif access_level != "sub_manager"
|
2016-08-05 12:00:34 +00:00
|
|
|
return {}
|
|
|
|
end
|
2014-09-22 08:32:30 +00:00
|
|
|
end
|
|
|
|
|
2021-09-01 09:51:22 +00:00
|
|
|
return {} if (announcement.category.disable rescue false)
|
2014-12-11 09:41:42 +00:00
|
|
|
|
2022-04-26 03:35:11 +00:00
|
|
|
if !announcement.deadline.nil? && announcement.deadline < Time.now
|
|
|
|
return {
|
|
|
|
"tags" => [],
|
|
|
|
"bulletin_files" => [],
|
|
|
|
"bulletin_links" => [],
|
|
|
|
"data" => {
|
|
|
|
"title" => announcement.title,
|
2022-04-26 03:43:59 +00:00
|
|
|
"subtitle_ann" => '',
|
|
|
|
"update_user" => '',
|
|
|
|
"updated_at" => '',
|
|
|
|
"image" => '',
|
|
|
|
"img_src" => '',
|
|
|
|
"img_description" => '',
|
|
|
|
"hide_class" => ' hide',
|
|
|
|
"alt_title" => '',
|
|
|
|
"carousel_html" => '',
|
|
|
|
"sub_anncs_text" => '',
|
|
|
|
"body" => "<b class='announcement_expired'>#{I18n.t('announcement.expired')}</b><br><a class='announcement_go_back_list' href='./' title='#{I18n.t('announcement.go_back')}'>#{I18n.t('announcement.go_back')}</a>".html_safe
|
2022-04-26 03:47:24 +00:00
|
|
|
},
|
|
|
|
"comments" => [],
|
|
|
|
"show_comment_flag" => '',
|
|
|
|
"impressionist" => nil,
|
2022-04-26 03:51:44 +00:00
|
|
|
"url_to_edit"=> '',
|
2022-04-26 03:53:46 +00:00
|
|
|
"redirect_to" => (announcement.is_external_link && !announcement.external_link.blank? ? announcement.external_link : nil)
|
2022-04-26 03:35:11 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-07-11 10:30:52 +00:00
|
|
|
tags = announcement.tags.map{|tag| {
|
|
|
|
"tag" => tag.name ,
|
|
|
|
"url" => OrbitHelper.page_for_tag(tag)
|
|
|
|
} } rescue []
|
2021-09-16 09:15:44 +00:00
|
|
|
files = announcement.bulletin_files.to_fronted(locale)
|
2014-06-17 04:06:40 +00:00
|
|
|
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
2022-04-18 15:32:19 +00:00
|
|
|
update_user = ""
|
|
|
|
if enable_annc_dept
|
|
|
|
update_user = annc_depts_translations[locale][announcement.annc_dept] rescue ""
|
|
|
|
else
|
|
|
|
update_user = announcement.update_user.member_profile.name rescue ""
|
|
|
|
end
|
2015-06-02 09:48:18 +00:00
|
|
|
desc = announcement.image_description
|
|
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
2019-10-29 06:45:45 +00:00
|
|
|
|
2015-07-03 11:53:24 +00:00
|
|
|
request = OrbitHelper.request
|
2022-10-01 05:25:01 +00:00
|
|
|
meta_desc = announcement.subtitle.nil? || announcement.subtitle == "" ? announcement.text.to_s[0..200] : announcement.subtitle
|
2024-06-12 16:09:52 +00:00
|
|
|
metas = [{"property" => "og:title", "content" => announcement.title},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url.split("?").first},{"property" => "og:description", "content" => meta_desc},{"property" => "og:type", "content" => "Article"}]
|
|
|
|
if announcement.image.present?
|
|
|
|
metas << {"property" => "og:image", "content" => URI.join(request.base_url, URI.encode(announcement.image.url)).to_s}
|
|
|
|
img_src_path = announcement.image.path
|
|
|
|
if File.exist?(img_src_path)
|
|
|
|
image = MiniMagick::Image.open(img_src_path)
|
|
|
|
if image[:width]
|
|
|
|
metas << {"property" => "og:image:width", "content" => image[:width].to_s}
|
|
|
|
end
|
|
|
|
if image[:height]
|
|
|
|
metas << {"property" => "og:image:height", "content" => image[:height].to_s}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
OrbitHelper.render_meta_tags(metas)
|
2015-07-03 11:53:24 +00:00
|
|
|
|
2020-01-13 07:16:46 +00:00
|
|
|
subtitle_ann = nil
|
|
|
|
img_src = nil
|
2020-01-14 05:13:13 +00:00
|
|
|
img_description = nil
|
2020-01-13 07:16:46 +00:00
|
|
|
subtitle_ann = announcement.subtitle if announcement.display_subtitle?
|
2023-02-02 08:10:39 +00:00
|
|
|
img_src = (announcement.image.url || DefaultImgSrc) if announcement.display_img?
|
2020-01-14 05:13:13 +00:00
|
|
|
img_description = announcement.image_description if (announcement.image_description.present?) && (announcement.display_img?)
|
2020-07-30 14:12:21 +00:00
|
|
|
show_comment_flag = announcement.open_comment_for_user(OrbitHelper.current_user)
|
2021-04-10 16:28:00 +00:00
|
|
|
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"
|
2021-09-25 11:26:13 +00:00
|
|
|
sub_anncs_text = ""
|
|
|
|
sub_annc_list = announcement.sub_annc_list
|
|
|
|
if announcement.enable_sub_annc && sub_annc_list.count != 0
|
|
|
|
params = OrbitHelper.params
|
|
|
|
page = OrbitHelper.page rescue Page.where(:url=>params[:url]).first
|
|
|
|
page_url = page.get_url rescue page.url
|
|
|
|
sub_anncs = announcement.get_sub_annc_list
|
|
|
|
display_sub_annc_date = announcement.display_sub_annc_date
|
|
|
|
sub_anncs_text = "<style type=\"text/css\">.dataTables_paginate {float: right;margin: 4px 0 0;}.dataTables_wrapper .dataTables_paginate a.paginate_button{display: inline;}</style>"
|
|
|
|
sub_anncs_text += "<div class=\"i-annc\"><table class=\"sub_anncs_table i-annc__table table table-striped\">
|
|
|
|
<thead><tr>
|
|
|
|
<th class=\"i-annc__th i-annc__th--title\">#{announcement.get_sub_annc_title_trans}</th>
|
|
|
|
#{display_sub_annc_date ? "<th class=\"i-annc__th i-annc__th--date\">#{I18n.t("announcement.table.date")}</th>" : ''}
|
|
|
|
</tr></thead>
|
|
|
|
<tbody>"
|
|
|
|
sub_anncs.each do |sub_annc|
|
|
|
|
sub_anncs_text += "<tr><td><a href=\"#{page_url}/#{sub_annc.to_param}\" title=\"#{sub_annc.title}\" target=\"_blank\">#{sub_annc.title}</a></td>#{(display_sub_annc_date ? ('<td class="i-annc__postdate">'+sub_annc.display_postdate+'</td>') : '')}</tr>"
|
|
|
|
end
|
|
|
|
sub_anncs_text += "</tbody></table></div>"
|
2021-11-12 07:17:47 +00:00
|
|
|
sub_anncs_text += '<script style="display:none">
|
2021-09-25 11:26:13 +00:00
|
|
|
var DataTables_language = {};
|
|
|
|
DataTables_language["zh_tw"] = {"info":"本頁為第 _START_ 項至第 _END_ 項,共有 _TOTAL_ 項","infoEmpty":"本頁為第 0 至第 0 項,共有 0 項","infoFiltered":"(來自總共 _MAX_ 項中的符合項目)","infoPostFix":"","lengthMenu":"每頁顯示 _MENU_ 個項目","processing":"處理中...","search":"快速搜尋:","zeroRecords":"沒有找到符合的項目","paginate": {"first":"第一頁","previous":"上一頁","next":"下一頁","last":"最後一頁"},"decimal":"","thousands":","};
|
|
|
|
$(".sub_anncs_table").dataTable({"language":DataTables_language["'+I18n.locale.to_s+'"],"order":[],"orderClasses":false,"stripeClasses":["even","odd"],"pagingType":"simple"});
|
|
|
|
</script>'
|
|
|
|
end
|
|
|
|
carousel_data = {
|
|
|
|
"bulletin_carousel_images" => bulletin_carousel_images,
|
|
|
|
"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' : "width: #{announcement.carousel_image_width};margin: auto;"),
|
|
|
|
"carousel_count" => bulletin_carousel_images.count}
|
|
|
|
carousel_html = ""
|
|
|
|
if carousel_data["carousel_count"] != 0
|
|
|
|
carousel_image_type = announcement.carousel_image_type
|
|
|
|
ac = ActionController::Base.new()
|
|
|
|
carousel_html = ac.render_to_string(:partial=>'announcements/bulletin_carousels',:locals=>{:data=>carousel_data,:carousel_image_type=>carousel_image_type})
|
|
|
|
end
|
2014-05-05 07:48:49 +00:00
|
|
|
{
|
2014-05-05 08:30:18 +00:00
|
|
|
"tags" => tags,
|
2014-05-05 07:48:49 +00:00
|
|
|
"bulletin_files" => files,
|
|
|
|
"bulletin_links" => links,
|
|
|
|
"data" => {
|
2014-05-02 10:21:51 +00:00
|
|
|
"title" => announcement.title,
|
2020-01-13 07:16:46 +00:00
|
|
|
"subtitle_ann" => subtitle_ann,
|
2014-05-14 11:51:17 +00:00
|
|
|
"update_user" => update_user,
|
2024-04-25 13:41:54 +00:00
|
|
|
"updated_at" => (announcement.postdate ? announcement.postdate.in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') : ""),
|
2014-05-05 07:48:49 +00:00
|
|
|
"body" =>announcement.text,
|
2015-06-02 09:48:18 +00:00
|
|
|
"image" => announcement.image.url,
|
2020-01-13 07:16:46 +00:00
|
|
|
"img_src" => img_src,
|
2020-01-13 09:24:21 +00:00
|
|
|
"img_description" => img_description,
|
2021-05-21 07:48:40 +00:00
|
|
|
"hide_class" => announcement.display_img? ? announcement.image_display_class : ' hide',
|
2021-04-10 16:28:00 +00:00
|
|
|
"alt_title" => desc,
|
2021-09-25 11:26:13 +00:00
|
|
|
"carousel_html" => carousel_html,
|
|
|
|
"sub_anncs_text" => sub_anncs_text
|
2014-05-15 11:27:05 +00:00
|
|
|
},
|
2020-07-30 14:12:21 +00:00
|
|
|
"comments" => announcement.comments,
|
|
|
|
"show_comment_flag" => show_comment_flag,
|
2014-08-05 06:37:33 +00:00
|
|
|
"impressionist" => (announcement.is_preview ? nil : announcement),
|
2022-04-26 03:51:44 +00:00
|
|
|
"url_to_edit"=>url_to_edit,
|
2022-04-26 03:53:46 +00:00
|
|
|
"redirect_to" => (announcement.is_external_link && !announcement.external_link.blank? ? announcement.external_link : nil)
|
2014-11-19 09:50:08 +00:00
|
|
|
}
|
2014-06-17 10:46:52 +00:00
|
|
|
end
|
2014-11-19 09:50:08 +00:00
|
|
|
|
2015-07-08 10:11:25 +00:00
|
|
|
def show_feed_announcement(uid)
|
|
|
|
announcement = OrbitHelper.get_from_feed(uid)
|
|
|
|
locale = OrbitHelper.get_site_locale.to_s
|
|
|
|
url_to_edit = "#"
|
2022-11-24 16:13:30 +00:00
|
|
|
return nil if announcement.blank?
|
2015-07-08 10:11:25 +00:00
|
|
|
tags = []
|
|
|
|
|
2019-10-29 07:51:02 +00:00
|
|
|
announcement["tags"].each{|tag|
|
2015-07-08 10:11:25 +00:00
|
|
|
t = Tag.where(:name => tag["name_translations"][locale]).first rescue nil
|
|
|
|
if t.nil?
|
|
|
|
I18n.locale = (locale == "en" ? :zh_tw : :en)
|
|
|
|
t = Tag.where(:name => tag["name_translations"][locale]).first rescue nil
|
|
|
|
I18n.locale = locale.to_sym
|
|
|
|
end
|
|
|
|
tags << {
|
2019-10-29 06:45:45 +00:00
|
|
|
"tag" => tag["name_translations"][locale],
|
|
|
|
"url" => (t.nil? ? "#" : OrbitHelper.page_for_tag(t))
|
|
|
|
}
|
|
|
|
}
|
2015-07-08 10:11:25 +00:00
|
|
|
|
2016-04-12 10:14:17 +00:00
|
|
|
files = announcement["bulletin_files"].map{|file| { "file_url" => file["url"], "file_title" => (file["title_translations"][locale] == "" ? URI.unescape(File.basename(file["url"])) : file["title_translations"][locale] rescue '') } } rescue []
|
2015-07-08 10:11:25 +00:00
|
|
|
|
2019-09-15 06:35:23 +00:00
|
|
|
files.each do |file|
|
2019-10-29 06:45:45 +00:00
|
|
|
if file["file_url"] =="" || file["file_url"] == nil
|
|
|
|
files.delete(file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
links = announcement["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale] == "" ? link["url"] : link["title_translations"][locale]) } } rescue []
|
2015-07-08 10:11:25 +00:00
|
|
|
|
|
|
|
update_user = announcement["author"]
|
2016-04-12 09:38:16 +00:00
|
|
|
desc = announcement["image_description_translations"][locale] rescue ""
|
2015-07-08 10:11:25 +00:00
|
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
2020-07-23 13:01:31 +00:00
|
|
|
img_description = nil
|
|
|
|
img_description = announcement["image_description_translations"][I18n.locale] if announcement['display_img']
|
|
|
|
img_src = nil
|
2023-02-02 08:10:39 +00:00
|
|
|
img_src = (announcement['image']['original'] || DefaultImgSrc) if announcement['display_img']
|
2020-07-23 13:01:31 +00:00
|
|
|
subtitle_ann = announcement['subtitle_ann']
|
2015-07-08 10:11:25 +00:00
|
|
|
request = OrbitHelper.request
|
2016-04-12 09:52:50 +00:00
|
|
|
if announcement["subtitle_translations"].present?
|
2016-04-12 09:55:50 +00:00
|
|
|
meta_desc = announcement["subtitle_translations"][locale] != "" ? announcement["subtitle_translations"][locale] : announcement["text_translations"][locale][0..200] rescue ""
|
2016-04-12 09:52:50 +00:00
|
|
|
else
|
|
|
|
meta_desc = ""
|
|
|
|
end
|
|
|
|
|
2024-06-12 16:09:52 +00:00
|
|
|
metas = [{"property" => "og:title", "content" => announcement["title_translations"][locale]},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url.split("?").first},{"property" => "og:description", "content" => meta_desc},{"property" => "og:type", "content" => "Article"}]
|
|
|
|
if announcement["image"]["original"].present?
|
|
|
|
image = announcement["image"]
|
|
|
|
metas << {"property" => "og:image", "content" => image["original"]}
|
|
|
|
if image["width"]
|
|
|
|
metas << {"property" => "og:image:width", "content" => image["width"].to_s}
|
|
|
|
end
|
|
|
|
if image["height"]
|
|
|
|
metas << {"property" => "og:image:height", "content" => image["height"].to_s}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
OrbitHelper.render_meta_tags(metas)
|
2015-07-08 10:11:25 +00:00
|
|
|
|
2024-04-25 13:41:54 +00:00
|
|
|
datetime = announcement["postdate"] ? DateTime.parse(announcement["postdate"]) : nil
|
2015-07-08 10:11:25 +00:00
|
|
|
|
2021-04-11 03:29:54 +00:00
|
|
|
bulletin_carousel_images = Array(announcement["bulletin_carousel_images"])
|
|
|
|
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"
|
2021-09-25 11:26:13 +00:00
|
|
|
carousel_data = {
|
|
|
|
"bulletin_carousel_images" => bulletin_carousel_images,
|
|
|
|
"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' : "width: #{AnnouncementSetting.last.carousel_image_width};margin: auto;"),
|
|
|
|
"carousel_count" => bulletin_carousel_images.count}
|
|
|
|
carousel_html = ""
|
|
|
|
if carousel_data["carousel_count"] != 0
|
|
|
|
carousel_image_type = announcement["carousel_image_type"].to_i
|
|
|
|
carousel_html = render(:partial=>'bulletin_carousels',:locals=>{:data=>carousel_data,:carousel_image_type=>carousel_image_type})
|
|
|
|
end
|
2015-07-08 10:11:25 +00:00
|
|
|
{
|
|
|
|
"tags" => tags,
|
|
|
|
"bulletin_files" => files,
|
|
|
|
"bulletin_links" => links,
|
|
|
|
"data" => {
|
|
|
|
"title" => announcement["title_translations"][locale],
|
2020-07-23 13:01:31 +00:00
|
|
|
"subtitle_ann" => subtitle_ann,
|
2015-07-08 10:11:25 +00:00
|
|
|
"update_user" => update_user,
|
2021-04-11 14:08:27 +00:00
|
|
|
"updated_at" => (datetime.in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue ""),
|
2015-07-08 10:11:25 +00:00
|
|
|
"body" => announcement["text_translations"][locale],
|
|
|
|
"image" => announcement["image"]["original"],
|
2020-07-23 13:01:31 +00:00
|
|
|
"img_src" => img_src,
|
|
|
|
"img_description" => img_description,
|
|
|
|
"hide_class" => announcement["display_img"] ? '' : ' hide',
|
2021-04-10 16:28:00 +00:00
|
|
|
"alt_title" => desc,
|
2021-09-25 11:26:13 +00:00
|
|
|
"carousel_html" => carousel_html,
|
|
|
|
"sub_anncs_text" => ""
|
2015-07-08 10:11:25 +00:00
|
|
|
},
|
2020-07-30 14:12:21 +00:00
|
|
|
"comments" => [],
|
|
|
|
"show_comment_flag" => false,
|
2015-07-08 10:11:25 +00:00
|
|
|
"impressionist" => nil,
|
|
|
|
"url_to_edit" => url_to_edit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
uid = params[:uid]
|
|
|
|
if OrbitHelper.is_object_from_feed?(uid)
|
|
|
|
show_feed_announcement(uid)
|
|
|
|
else
|
2015-10-19 08:59:26 +00:00
|
|
|
show_local_announcement(uid, (params["preview"] == "true" ? true : false))
|
2015-07-08 10:11:25 +00:00
|
|
|
end
|
|
|
|
end
|
2020-05-19 04:31:57 +00:00
|
|
|
def show_widget
|
|
|
|
@type = "show_widget"
|
|
|
|
@show_page = params[:show_page]
|
|
|
|
if params[:tags].nil?
|
2020-05-19 08:06:20 +00:00
|
|
|
@tags = ['all']
|
2020-05-19 04:31:57 +00:00
|
|
|
else
|
|
|
|
@tags = params[:tags]
|
|
|
|
end
|
|
|
|
if params[:categories].nil?
|
2020-05-19 08:06:20 +00:00
|
|
|
@categories = ['all']
|
2020-05-19 04:31:57 +00:00
|
|
|
else
|
|
|
|
@categories = params[:categories]
|
|
|
|
end
|
2024-04-17 13:48:24 +00:00
|
|
|
root_page = Page.root
|
|
|
|
annc_params = {:module=>"announcement", :enabled_for=>I18n.locale.to_s}
|
|
|
|
annc_page = (root_page.respond_to?(:find_page) ? root_page.find_page(annc_params).first : Page.where(annc_params).first)
|
|
|
|
OrbitHelper.set_page(annc_page) if OrbitHelper.respond_to?(:set_page)
|
|
|
|
params[:url] = (annc_page ? annc_page.url : nil)
|
2020-08-03 09:11:20 +00:00
|
|
|
OrbitHelper.set_site_locale(I18n.locale)
|
2020-05-19 04:31:57 +00:00
|
|
|
OrbitHelper.set_current_widget_module("announcement")
|
|
|
|
OrbitHelper.set_params(params,current_user)
|
|
|
|
Bulletin.remove_expired_status
|
|
|
|
OrbitHelper.set_page_number(params[:page_no].to_i)
|
|
|
|
OrbitHelper.set_page_data_count((params[:data_count].blank? ? 10 : params[:data_count].to_i))
|
2020-05-19 06:20:02 +00:00
|
|
|
sorted,total_pages = get_sorted_annc
|
2022-04-18 15:32:19 +00:00
|
|
|
annc_depts = []
|
|
|
|
tmp_enable_annc_dept = (enable_annc_dept rescue false)
|
|
|
|
if tmp_enable_annc_dept
|
|
|
|
annc_depts = annc_depts_translations[locale] rescue []
|
|
|
|
end
|
2020-05-19 04:31:57 +00:00
|
|
|
anns = sorted.collect do |a|
|
|
|
|
if a["source-site"].blank?
|
|
|
|
statuses = a.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
locale = I18n.locale.to_s
|
2021-09-16 09:15:44 +00:00
|
|
|
files = a.bulletin_files.to_fronted(locale)
|
2020-05-19 04:31:57 +00:00
|
|
|
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
2022-06-21 03:11:33 +00:00
|
|
|
author = tmp_enable_annc_dept ? annc_depts[a.annc_dept] : User.find(a.update_user_id).member_profile.name rescue ""
|
2020-05-19 04:31:57 +00:00
|
|
|
desc = a.image_description
|
|
|
|
desc = (desc.blank? ? "announcement image" : desc)
|
|
|
|
link_to_show = (a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)) rescue ""
|
|
|
|
target = a.is_external_link ? "_blank" : "_self"
|
2024-10-13 13:42:37 +00:00
|
|
|
title = a.title_plain_text
|
|
|
|
title = 'no content' if title.blank?
|
2020-05-19 04:31:57 +00:00
|
|
|
{
|
|
|
|
"department" => author,
|
|
|
|
"bulletin_links" => links,
|
|
|
|
"bulletin_files" => files,
|
|
|
|
"title" => a.title,
|
|
|
|
"source-site" => "",
|
|
|
|
"source-site-title" => "",
|
|
|
|
"source-site-link" => "",
|
|
|
|
"subtitle" => a.subtitle,
|
|
|
|
"statuses" => statuses,
|
2021-09-01 09:51:22 +00:00
|
|
|
"category" => (a.category.title rescue ""),
|
2020-05-19 04:31:57 +00:00
|
|
|
"postdate" => a.postdate,
|
|
|
|
"author" => author,
|
|
|
|
"is_top" => (a.is_top? ? 1 : 0),
|
2021-11-12 07:44:55 +00:00
|
|
|
"link_to_show" => link_to_show+"\" #{(link_to_show[0] == '/' rescue true) ? '' : 'target="_blank"'} title=\"#{title}",
|
2020-05-19 04:31:57 +00:00
|
|
|
"target" => target,
|
2023-02-02 08:10:39 +00:00
|
|
|
"img_src" => a.image.thumb.url || DefaultImgSrc,
|
2020-05-19 04:31:57 +00:00
|
|
|
"img_description" => desc,
|
2022-01-21 02:14:57 +00:00
|
|
|
"more" => t("announcement.more"),
|
2020-05-19 04:31:57 +00:00
|
|
|
"view_count" => a.view_count
|
|
|
|
}
|
|
|
|
else
|
|
|
|
a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#If no data , hide title&table
|
|
|
|
if sorted.count == 0
|
|
|
|
display = "hide"
|
|
|
|
end
|
|
|
|
# anns = anns.concat(feeds_anns)
|
|
|
|
# total_pages = announcements.total_pages
|
2015-07-08 10:11:25 +00:00
|
|
|
|
2015-12-22 11:04:13 +00:00
|
|
|
|
2020-05-19 04:31:57 +00:00
|
|
|
@data = {
|
|
|
|
"announcements" => anns,
|
|
|
|
"extras" => {
|
|
|
|
"widget-title" =>t('announcement.announcement'),
|
|
|
|
"title-head" => t('announcement.table.title'),
|
|
|
|
"date-head" => t('announcement.table.date'),
|
|
|
|
"status-head" => t('announcement.table.status'),
|
|
|
|
"author-head" => t('announcement.table.author'),
|
|
|
|
"subtitle-head" => t('announcement.table.sub_title'),
|
|
|
|
"category-head" => t('announcement.table.category'),
|
|
|
|
"link-head" => t('announcement.table.link'),
|
|
|
|
"file-head" => t('announcement.table.file'),
|
|
|
|
"view-count-head" => t('announcement.table.view_count'),
|
|
|
|
"display" => display,
|
|
|
|
"department-head" => t('announcement.table.department')
|
|
|
|
},
|
|
|
|
"total_pages" => total_pages
|
|
|
|
}
|
2023-05-06 08:24:25 +00:00
|
|
|
@layout_type = params[:layout_type]
|
|
|
|
if @layout_type.blank?
|
|
|
|
@layout_type = 'annc_index1'
|
|
|
|
else
|
|
|
|
@layout_type = @layout_type.to_s
|
|
|
|
if File.dirname(@layout_type) != '.'
|
|
|
|
render_400 and return
|
|
|
|
end
|
|
|
|
end
|
2020-05-19 04:31:57 +00:00
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
2021-09-16 09:15:44 +00:00
|
|
|
def agenda
|
|
|
|
I18n.with_locale(params[:locale]||I18n.locale) do
|
|
|
|
if !params[:subpart_id].nil?
|
|
|
|
subpartid = params[:subpart_id]
|
|
|
|
subpart = SubPart.find(subpartid)
|
|
|
|
all_cats = subpart.categories
|
|
|
|
all_cats = ['all'] if all_cats.length==0
|
|
|
|
all_tags = subpart.tags
|
|
|
|
all_tags = ['all'] if all_tags.length==0
|
|
|
|
page = Page.where(:page_id=> subpart.read_more_page_id).first rescue nil
|
|
|
|
page = Page.where(:module => "announcement").first rescue nil if page.nil?
|
|
|
|
read_more_url_root = "/#{I18n.locale.to_s + page.url}" rescue ""
|
|
|
|
read_more_url = read_more_url_root + "?" + {"category"=>all_cats,"tags"=> all_tags}.to_param if read_more_url != ""
|
|
|
|
else
|
|
|
|
page = Page.where(:module => "announcement").first
|
|
|
|
read_more_url_root = "/#{I18n.locale.to_s + page.url}" rescue ""
|
|
|
|
end
|
|
|
|
if params[:unix_start].present? && params[:unix_end].present?
|
|
|
|
agenda_start = Time.at(params[:unix_start].to_i).utc.to_s
|
|
|
|
agenda_end = Time.at(params[:unix_end].to_i).utc.to_s
|
|
|
|
events = Bulletin.agenda_events(agenda_start,agenda_end,read_more_url_root)
|
|
|
|
end
|
|
|
|
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_calendar_title(now_date=nil)
|
|
|
|
now_date = Time.now.utc if now_date.nil?
|
|
|
|
month_name = I18n.locale.to_s=='zh_tw' ? now_date.month : I18n.t("announcement.month_name.#{now_date.month}")
|
|
|
|
I18n.t("announcement.calendar_title",year: now_date.year,month: month_name)
|
|
|
|
end
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|