2014-10-14 08:59:15 +00:00
|
|
|
class AnnouncementsController < ApplicationController
|
|
|
|
|
|
|
|
def index
|
|
|
|
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags(OrbitHelper.params['tags'])
|
|
|
|
|
|
|
|
anns = announcements.collect do |a|
|
|
|
|
statuses = a.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
2015-06-02 09:48:53 +00:00
|
|
|
desc = a.image_description
|
|
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
2014-10-14 08:59:15 +00:00
|
|
|
{
|
|
|
|
"title" => a.title,
|
|
|
|
"subtitle" => a.subtitle,
|
|
|
|
"statuses" => statuses,
|
|
|
|
"category" => a.category.title,
|
|
|
|
"postdate" => a.postdate,
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
|
|
|
"img_src" => a.image.thumb.url || "http://placehold.it/100x100",
|
2015-06-02 09:48:53 +00:00
|
|
|
"img_description" => desc,
|
2014-10-14 08:59:15 +00:00
|
|
|
"more" => t(:more_plus)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"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'),
|
|
|
|
"subtitle-head" => t('announcement.table.sub_title'),
|
|
|
|
"category-head" => t('announcement.table.category')
|
|
|
|
},
|
|
|
|
"total_pages" => announcements.total_pages
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget
|
|
|
|
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:created_at=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags)
|
|
|
|
|
|
|
|
anns = announcements.collect do |a|
|
|
|
|
statuses = a.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
2015-06-02 09:48:53 +00:00
|
|
|
desc = a.image_description
|
|
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
2014-10-14 08:59:15 +00:00
|
|
|
{
|
|
|
|
"title" => a.title,
|
|
|
|
"subtitle" => a.subtitle,
|
|
|
|
"statuses" => statuses,
|
|
|
|
"category" => a.category.title,
|
|
|
|
"postdate" => a.postdate,
|
|
|
|
"link_to_show" => OrbitHelper.widget_item_url(a.to_param),
|
|
|
|
"img_src" => a.image.thumb.url || "http://placehold.it/100x100",
|
2015-06-02 09:48:53 +00:00
|
|
|
"img_description" => desc
|
2014-10-14 08:59:15 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"announcements" => anns,
|
|
|
|
"extras" => {
|
|
|
|
"more_url"=>OrbitHelper.widget_more_url,
|
|
|
|
"title-head" => t('announcement.table.title'),
|
|
|
|
"date-head" => t('announcement.table.date'),
|
|
|
|
"status-head" => t('announcement.table.status'),
|
|
|
|
"subtitle-head" => t('announcement.table.sub_title'),
|
|
|
|
"category-head" => t('announcement.table.category')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
announcement = Bulletin.can_display.find_by(:uid=>params[:uid])
|
|
|
|
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
|
|
|
|
|
|
|
|
access_level = OrbitHelper.user_access_level?
|
|
|
|
|
|
|
|
if !announcement.approved && (access_level != "manager" && access_level != "admin")
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
2014-12-11 09:42:26 +00:00
|
|
|
return {} if announcement.category.disable
|
|
|
|
|
2014-10-14 08:59:15 +00:00
|
|
|
tags = announcement.tags.map{|tag| {
|
|
|
|
"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? ? File.basename(file.file.path) : file.title rescue '') } } rescue []
|
|
|
|
|
|
|
|
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 ""
|
2015-06-02 09:48:53 +00:00
|
|
|
desc = announcement.image_description
|
|
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
2014-10-14 08:59:15 +00:00
|
|
|
{
|
|
|
|
"tags" => tags,
|
|
|
|
"bulletin_files" => files,
|
|
|
|
"bulletin_links" => links,
|
|
|
|
"data" => {
|
|
|
|
"title" => announcement.title,
|
|
|
|
"update_user" => update_user,
|
|
|
|
"updated_at" => announcement.updated_at.strftime('%Y-%m-%d %H:%M'),
|
|
|
|
"body" =>announcement.text,
|
2015-06-02 09:48:53 +00:00
|
|
|
"image" => announcement.image.url,
|
|
|
|
"alt_image" => desc
|
2014-10-14 08:59:15 +00:00
|
|
|
},
|
|
|
|
"impressionist" => (announcement.is_preview ? nil : announcement),
|
|
|
|
"url_to_edit"=>url_to_edit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|