2014-05-01 08:41:00 +00:00
|
|
|
# encoding: utf-8
|
2016-04-21 17:28:37 +00:00
|
|
|
require 'rubyXL'
|
2014-05-01 08:41:00 +00:00
|
|
|
class Admin::AnnouncementsController < OrbitAdminController
|
2014-05-28 07:37:56 +00:00
|
|
|
include Admin::AnnouncementsHelper
|
2014-05-02 04:09:44 +00:00
|
|
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
|
|
|
before_action :set_bulletin, only: [:edit, :destroy]
|
2016-08-05 12:00:34 +00:00
|
|
|
before_action :load_access_level, :load_settings
|
2014-05-02 04:09:44 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "announcement"
|
|
|
|
end
|
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def index
|
2015-12-22 11:04:13 +00:00
|
|
|
Bulletin.remove_expired_status
|
2014-05-01 08:41:00 +00:00
|
|
|
@tags = @module_app.tags
|
2014-05-14 02:58:06 +00:00
|
|
|
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
2020-05-16 13:43:37 +00:00
|
|
|
@current_user = current_user
|
2020-05-15 14:25:58 +00:00
|
|
|
if AnnouncementSetting.first.is_display_edit_only && !current_user.is_admin? && !current_user.is_manager?(@module_app)
|
|
|
|
current_user_is_sub_manager = !current_user.is_manager?(@module_app) && (current_user.is_sub_manager?(@module_app) || current_user.is_sub_manager_with_role?(@module_app)) rescue false
|
|
|
|
if current_user_is_sub_manager
|
2020-05-15 14:46:28 +00:00
|
|
|
@categories = current_user.approved_categories.select{|c| c.module_app_id == @module_app.id} rescue []
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
2020-05-15 14:25:58 +00:00
|
|
|
@bulletins = Bulletin.where(:create_user_id=>current_user.id,:title.ne => "",:is_preview.in=>[false,nil])
|
2014-08-07 10:45:21 +00:00
|
|
|
.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_tags(filters("tag"))
|
|
|
|
.with_status(filters("status"))
|
2020-05-15 14:25:58 +00:00
|
|
|
else
|
|
|
|
@bulletins = Bulletin.where(:uid=>nil)
|
2020-05-15 14:46:28 +00:00
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
2020-05-15 14:25:58 +00:00
|
|
|
end
|
|
|
|
else
|
2020-05-15 14:46:28 +00:00
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
2020-05-15 14:25:58 +00:00
|
|
|
@bulletins = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil])
|
|
|
|
.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_tags(filters("tag"))
|
|
|
|
.with_status(filters("status"))
|
|
|
|
end
|
2014-08-07 10:45:21 +00:00
|
|
|
@bulletins = search_data(@bulletins,[:title]).page(params[:page]).per(10)
|
2014-05-02 10:21:51 +00:00
|
|
|
|
2014-05-14 02:58:06 +00:00
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index"
|
2014-05-01 08:41:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-08 10:11:25 +00:00
|
|
|
def feed
|
2017-01-05 06:56:05 +00:00
|
|
|
@table_feed_fields = ["announcement.feed_name", :tags, "announcement.rssfeed", "announcement.jsonfeed"]
|
2015-07-08 10:11:25 +00:00
|
|
|
@feeds = BulletinFeed.all.asc(:created_at)
|
|
|
|
|
|
|
|
end
|
2020-05-19 04:31:57 +00:00
|
|
|
def generate_iframe_url
|
|
|
|
iframe_params = params.require(:iframe).permit!
|
|
|
|
uids = iframe_params['member_ids'].to_a.map{|m_id| MemberProfile.find(m_id).uid rescue nil}.select{|uid| !uid.nil?}
|
|
|
|
url_params = iframe_params.except(:member_ids)
|
|
|
|
url_params['uids'] = uids if uids != []
|
|
|
|
render :text => '/xhr/panel/announcement/widget/sync_data?'+url_params.to_param
|
|
|
|
end
|
2015-12-22 11:04:13 +00:00
|
|
|
def settings
|
2016-08-05 12:00:34 +00:00
|
|
|
@setting = @announcement_setting
|
2020-05-19 04:31:57 +00:00
|
|
|
roles = Role.all
|
|
|
|
@sorted_members = roles.inject({}) do |members,role|
|
|
|
|
members_for_role = role.member_profiles.select{|m| (m.user.nil? ? false : m.user.approved)}
|
|
|
|
members[role] = members_for_role
|
|
|
|
members
|
|
|
|
end
|
|
|
|
@sorted_members['no_role'] = MemberProfile.any_in(:role_ids=>[nil,[]]).select{|m| (m.user.nil? ? false : m.user.approved)}
|
|
|
|
@unapproved_members = User.where(:approved => false).map{|u| u.member_profile}
|
2015-12-22 11:04:13 +00:00
|
|
|
end
|
|
|
|
|
2016-04-21 17:28:37 +00:00
|
|
|
def import
|
|
|
|
end
|
|
|
|
|
|
|
|
def excel_format
|
|
|
|
respond_to do |format|
|
|
|
|
format.xlsx {
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename="announcement_import_format.xlsx"'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-16 07:14:57 +00:00
|
|
|
def export_excel
|
|
|
|
@announcements = Bulletin.all.desc(:created_at)
|
|
|
|
respond_to do |format|
|
|
|
|
format.xlsx {
|
|
|
|
response.headers['Content-Disposition'] = 'attachment; filename="announcement_export.xlsx"'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-04 12:30:35 +00:00
|
|
|
def import_from_xml
|
|
|
|
download_tmp_xml params["import_xml"]
|
|
|
|
import_from_tmp_xml File.read(File.join(Rails.root, "tmp", "ann_cc_ntu.xml"))
|
|
|
|
redirect_to admin_announcements_path
|
|
|
|
end
|
2016-04-21 17:28:37 +00:00
|
|
|
|
2017-01-26 06:30:59 +00:00
|
|
|
def import
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def import_from_wp
|
|
|
|
import_from_wordpress params["import_xml"].tempfile
|
|
|
|
redirect_to admin_announcements_path
|
|
|
|
end
|
|
|
|
|
2016-04-21 17:28:37 +00:00
|
|
|
def importanns
|
|
|
|
workbook = RubyXL::Parser.parse(params["import_file"].tempfile)
|
|
|
|
categories = @module_app.categories.asc(:created_at).to_a
|
|
|
|
tags = @module_app.tags.asc(:created_at).to_a
|
|
|
|
sheet = workbook[0]
|
|
|
|
if sheet.count <= 503
|
|
|
|
sheet.each_with_index do |row, i|
|
|
|
|
next if i < 3
|
|
|
|
v = row.cells.first.value
|
|
|
|
next if v == "" || v.nil?
|
|
|
|
import_this_announcement(row, categories, tags)
|
|
|
|
end
|
|
|
|
redirect_to admin_announcements_path
|
|
|
|
else
|
|
|
|
redirect_to admin_announcements_path(:error => "1")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-22 11:04:13 +00:00
|
|
|
def createsettings
|
|
|
|
setting = AnnouncementSetting.new(settings_params)
|
|
|
|
setting.save
|
|
|
|
redirect_to admin_announcement_settings_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def updatesettings
|
2016-08-05 12:00:34 +00:00
|
|
|
setting = @announcement_setting
|
2020-05-15 14:25:58 +00:00
|
|
|
ids = params['announcement_setting']['anns_status_settings'].to_a.collect do |i,v|
|
2020-03-02 10:09:55 +00:00
|
|
|
v['_id']
|
|
|
|
end.compact
|
|
|
|
AnnsStatusSetting.where(:id.nin=>ids).destroy
|
2015-12-22 11:04:13 +00:00
|
|
|
setting.update_attributes(settings_params)
|
|
|
|
setting.save
|
|
|
|
redirect_to admin_announcement_settings_path
|
|
|
|
end
|
|
|
|
|
2015-07-08 10:11:25 +00:00
|
|
|
def feedform
|
|
|
|
if params[:type] == "new"
|
|
|
|
@announcement_feed = BulletinFeed.new
|
|
|
|
render :partial => "feed_form"
|
|
|
|
else params[:type] == "edit"
|
|
|
|
@announcement_feed = BulletinFeed.find(params[:id])
|
|
|
|
render :partial => "edit_feed_form"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def createfeed
|
|
|
|
announcement_feed = BulletinFeed.new(feed_params)
|
|
|
|
announcement_feed.save
|
|
|
|
feeds = BulletinFeed.all.asc(:created_at)
|
|
|
|
render :partial => "feed", :collection => feeds
|
|
|
|
end
|
|
|
|
|
|
|
|
def updatefeed
|
|
|
|
ann_feed = BulletinFeed.find(params[:id])
|
|
|
|
ann_feed.update_attributes(feed_params)
|
|
|
|
ann_feed.save
|
|
|
|
feeds = BulletinFeed.all.asc(:created_at)
|
|
|
|
render :partial => "feed", :collection => feeds
|
|
|
|
end
|
|
|
|
|
|
|
|
def deletefeed
|
|
|
|
ann_feed = BulletinFeed.find(params[:id])
|
|
|
|
ann_feed.destroy
|
|
|
|
feeds = BulletinFeed.all.asc(:created_at)
|
|
|
|
render :partial => "feed", :collection => feeds
|
|
|
|
end
|
|
|
|
|
2014-04-03 03:18:02 +00:00
|
|
|
def new
|
2014-07-31 09:12:13 +00:00
|
|
|
@tags = @module_app.tags
|
2014-05-01 08:41:00 +00:00
|
|
|
@statuses = []
|
|
|
|
@bulletin = Bulletin.new
|
2014-06-24 09:23:51 +00:00
|
|
|
@bulletin.email_sentdate = Time.now
|
2020-03-02 10:09:55 +00:00
|
|
|
@reach_limit = @bulletin.check_status_limit(current_user,true)
|
2014-04-03 03:18:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-12-22 11:04:13 +00:00
|
|
|
bps = bulletin_params
|
|
|
|
if !bps['bulletin_links_attributes'].nil?
|
|
|
|
bps['bulletin_links_attributes'].each do |idx,link|
|
|
|
|
bps['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
2014-07-21 03:01:53 +00:00
|
|
|
end
|
|
|
|
end
|
2020-05-16 13:43:37 +00:00
|
|
|
if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) )
|
|
|
|
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(bulletin.create_user_id, bulletin.id)
|
|
|
|
bps[:is_top] = "0"
|
|
|
|
bps[:top_end_date] = nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
bps[:is_top] = false
|
|
|
|
bps[:is_hot] = false
|
|
|
|
bps[:is_hidden] = false
|
2015-12-22 11:04:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
bulletin = Bulletin.new(bps)
|
2014-05-01 08:41:00 +00:00
|
|
|
bulletin.create_user_id = current_user.id
|
|
|
|
bulletin.update_user_id = current_user.id
|
2016-07-05 11:34:29 +00:00
|
|
|
if AnnouncementSetting.is_pro?
|
|
|
|
if user_can_approve?
|
|
|
|
bulletin.approved = true
|
2016-07-20 12:35:23 +00:00
|
|
|
else
|
2020-05-04 15:14:02 +00:00
|
|
|
send_notification_mail_to_managers(bulletin,"approval",I18n.locale)
|
2016-07-05 11:34:29 +00:00
|
|
|
end
|
|
|
|
else
|
2014-09-22 08:32:30 +00:00
|
|
|
bulletin.approved = true
|
2016-07-05 11:34:29 +00:00
|
|
|
end
|
2015-12-22 11:04:13 +00:00
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
bulletin.save
|
2020-05-04 15:14:02 +00:00
|
|
|
build_email(bulletin,I18n.locale)
|
2014-08-05 06:37:33 +00:00
|
|
|
redirect_to params['referer_url']
|
2014-04-03 03:18:02 +00:00
|
|
|
end
|
|
|
|
|
2014-09-22 08:32:30 +00:00
|
|
|
def approve_bulletin
|
|
|
|
id = params[:id]
|
|
|
|
bulletin = Bulletin.find(id)
|
2016-07-20 12:35:23 +00:00
|
|
|
if params["approved"] == "true"
|
|
|
|
bulletin.approved = true
|
|
|
|
bulletin.rejected = false
|
|
|
|
bulletin.reapproval = false
|
|
|
|
else
|
|
|
|
bulletin.rejected = true
|
|
|
|
bulletin.reapproval = false
|
|
|
|
bulletin.rejection_reason = params["reason"]
|
2020-05-04 15:14:02 +00:00
|
|
|
send_rejection_email(bulletin,I18n.locale)
|
2016-07-20 12:35:23 +00:00
|
|
|
end
|
2014-09-22 08:32:30 +00:00
|
|
|
bulletin.save
|
|
|
|
redirect_to admin_announcements_path
|
|
|
|
end
|
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def edit
|
2014-07-31 09:12:13 +00:00
|
|
|
if can_edit_or_delete?(@bulletin)
|
2020-03-02 10:09:55 +00:00
|
|
|
@reach_limit = @bulletin.check_status_limit(current_user,true)
|
2014-07-31 09:12:13 +00:00
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@statuses = []
|
|
|
|
@bulletin.email_sentdate = Time.now if @bulletin.email_sent == false
|
2014-08-05 06:37:33 +00:00
|
|
|
else
|
|
|
|
render_401
|
|
|
|
end
|
2014-04-10 03:52:59 +00:00
|
|
|
end
|
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def update
|
|
|
|
uid = params[:id].split('-').last
|
|
|
|
bulletin = Bulletin.find_by(:uid=>uid)
|
2015-12-22 11:04:13 +00:00
|
|
|
bps = bulletin_params
|
|
|
|
bps[:tags] = bps[:tags].blank? ? [] : bps[:tags]
|
|
|
|
bps[:email_member_ids] = bps[:email_member_ids].blank? ? [] : bps[:email_member_ids]
|
2014-07-21 03:01:53 +00:00
|
|
|
|
2015-12-22 11:04:13 +00:00
|
|
|
if !bps['bulletin_links_attributes'].nil?
|
|
|
|
bps['bulletin_links_attributes'].each do |idx,link|
|
|
|
|
bps['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
|
2014-07-21 03:01:53 +00:00
|
|
|
end
|
|
|
|
end
|
2020-05-16 13:43:37 +00:00
|
|
|
if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) )
|
|
|
|
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(bulletin.create_user_id, bulletin.id)
|
|
|
|
bps[:is_top] = "0"
|
|
|
|
bps[:top_end_date] = nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
bps[:is_top] = bulletin.is_top
|
|
|
|
bps[:is_hot] = bulletin.is_hot
|
|
|
|
bps[:is_hidden] = bulletin.is_hidden
|
2015-12-22 11:04:13 +00:00
|
|
|
end
|
|
|
|
bulletin.update_attributes(bps)
|
2020-03-02 10:09:55 +00:00
|
|
|
bulletin.update_user_id = current_user.id
|
2016-07-20 12:35:23 +00:00
|
|
|
if bulletin.rejected
|
|
|
|
bulletin.reapproval = true
|
|
|
|
bulletin.save
|
2020-05-04 15:14:02 +00:00
|
|
|
send_notification_mail_to_managers(bulletin,"reapproval",I18n.locale)
|
2016-07-20 12:35:23 +00:00
|
|
|
else
|
|
|
|
bulletin.save
|
|
|
|
end
|
2020-05-04 15:14:02 +00:00
|
|
|
build_email(bulletin,I18n.locale)
|
2020-03-02 10:09:55 +00:00
|
|
|
now_bulletin_page = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil])
|
|
|
|
.order_by(sort).map(&:id).map.with_index.select{|v,i| v==bulletin.id}[0][1] rescue nil
|
|
|
|
now_bulletin_page = now_bulletin_page.nil? ? 0 : ((now_bulletin_page+1).to_f/10).ceil
|
|
|
|
redirect_to "/zh_tw/admin/announcements?page=#{now_bulletin_page}"
|
2014-05-01 08:41:00 +00:00
|
|
|
end
|
2014-04-03 03:18:02 +00:00
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def destroy
|
2014-05-02 04:09:44 +00:00
|
|
|
@bulletin.destroy
|
2014-05-01 08:41:00 +00:00
|
|
|
redirect_to "/admin/announcements"
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete
|
|
|
|
if params[:ids]
|
2014-06-23 08:36:04 +00:00
|
|
|
Bulletin.any_in(:uid => params[:ids]).destroy_all
|
2014-04-03 03:18:02 +00:00
|
|
|
end
|
2014-05-01 08:41:00 +00:00
|
|
|
redirect_to "/admin/announcements"
|
|
|
|
end
|
|
|
|
|
2014-06-17 10:46:52 +00:00
|
|
|
def preview
|
2014-06-23 08:36:04 +00:00
|
|
|
if params['preview_type'].eql?('edit')
|
|
|
|
bulletin_data = bulletin_params
|
|
|
|
org_bulletin = Bulletin.find(params['bulletin_id'])
|
|
|
|
bulletin = org_bulletin.clone
|
|
|
|
bulletin.generate_uid
|
|
|
|
bulletin.bulletin_files = []
|
|
|
|
bulletin.bulletin_links = []
|
|
|
|
if bulletin_data['image'].blank?
|
|
|
|
bulletin.image = org_bulletin.image
|
|
|
|
end
|
2014-06-17 10:46:52 +00:00
|
|
|
|
2014-06-23 08:36:04 +00:00
|
|
|
if !bulletin_data['bulletin_files_attributes'].blank?
|
|
|
|
bulletin_data['bulletin_files_attributes'].each do |key, bulletin_file|
|
|
|
|
next if !bulletin_file['_destroy'].blank?
|
|
|
|
file = nil
|
|
|
|
if bulletin_file['id'].blank?
|
|
|
|
file = BulletinFile.new(bulletin_file)
|
|
|
|
file.bulletin_id = bulletin.id
|
|
|
|
file.save
|
|
|
|
else
|
2014-06-24 07:57:27 +00:00
|
|
|
org_file = BulletinFile.find(bulletin_file['id'])
|
|
|
|
file = org_file.clone
|
2014-06-23 08:36:04 +00:00
|
|
|
file.bulletin_id = bulletin.id
|
2014-06-24 07:57:27 +00:00
|
|
|
file.file = org_file.file
|
2014-06-23 08:36:04 +00:00
|
|
|
bulletin_file.delete('id')
|
|
|
|
bulletin_file.delete('_destroy')
|
|
|
|
file.update_attributes(bulletin_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
file.save
|
|
|
|
bulletin.bulletin_files << file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if !bulletin_data['bulletin_links_attributes'].blank?
|
|
|
|
bulletin_data['bulletin_links_attributes'].each do |key, bulletin_link|
|
|
|
|
next if !bulletin_link['_destroy'].blank?
|
|
|
|
|
|
|
|
if bulletin_link['id'].blank?
|
|
|
|
link = BulletinLink.new(bulletin_link)
|
|
|
|
link.bulletin_id = bulletin.id
|
|
|
|
else
|
|
|
|
link = BulletinLink.find(bulletin_link['id']).clone
|
|
|
|
link.bulletin_id = bulletin.id
|
|
|
|
bulletin_link.delete('id')
|
|
|
|
bulletin_link.delete('_destroy')
|
|
|
|
link.update_attributes(bulletin_link)
|
|
|
|
end
|
2014-06-17 10:46:52 +00:00
|
|
|
|
2014-06-23 08:36:04 +00:00
|
|
|
link.save
|
|
|
|
bulletin.bulletin_links << link
|
|
|
|
end
|
2014-06-17 10:46:52 +00:00
|
|
|
end
|
2014-06-23 08:36:04 +00:00
|
|
|
|
|
|
|
bulletin_data.delete('bulletin_files_attributes')
|
|
|
|
bulletin_data.delete('bulletin_links_attributes')
|
|
|
|
bulletin.update_attributes(bulletin_data)
|
|
|
|
else
|
|
|
|
bulletin = Bulletin.new(bulletin_params)
|
2014-06-17 10:46:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
bulletin.is_preview = true
|
|
|
|
bulletin.save
|
2015-10-19 08:59:26 +00:00
|
|
|
render :text=>page_for_bulletin(bulletin) + "?preview=true"
|
2014-06-17 10:46:52 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 08:36:04 +00:00
|
|
|
def destroy_preview
|
|
|
|
bulletin = Bulletin.find_by(:uid=>params['uid'])
|
|
|
|
if bulletin.is_preview
|
|
|
|
bulletin.destroy
|
|
|
|
end
|
|
|
|
render :json=>{'destroy'=>bulletin.id.to_s}
|
|
|
|
end
|
|
|
|
|
2020-05-04 15:14:02 +00:00
|
|
|
def build_email(bulletin,locale)
|
2014-05-28 07:37:56 +00:00
|
|
|
if bulletin.email_sent and !bulletin.email_addresses.blank?
|
|
|
|
if bulletin.email.nil?
|
|
|
|
email = Email.new
|
|
|
|
email.save
|
2020-03-22 13:47:21 +00:00
|
|
|
email.deliver rescue nil
|
2014-05-28 07:37:56 +00:00
|
|
|
bulletin.email_id = email.id
|
|
|
|
bulletin.save
|
|
|
|
end
|
|
|
|
|
|
|
|
is_sent = bulletin.email.is_sent
|
|
|
|
is_sent = !params[:resend_mail].eql?("true") if !params[:resend_mail].blank?
|
2020-05-04 15:14:02 +00:00
|
|
|
doc = Nokogiri::HTML(bulletin.title_translations[locale])
|
2020-02-06 04:46:38 +00:00
|
|
|
title = doc.text.empty? ? 'no content' : doc.text
|
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
bulletin.email.update_attributes(
|
|
|
|
:create_user=>current_user,
|
|
|
|
:mail_sentdate=>bulletin.email_sentdate,
|
|
|
|
:module_app=>@module_app,
|
2020-05-04 15:14:02 +00:00
|
|
|
:mail_lang => locale,
|
2014-05-28 07:37:56 +00:00
|
|
|
:mail_to=>bulletin.email_addresses,
|
2020-02-06 04:46:38 +00:00
|
|
|
:mail_subject=>title,
|
2014-05-28 07:37:56 +00:00
|
|
|
:template=>'announcements/email',
|
|
|
|
:template_data=>{
|
|
|
|
"host" => request.host_with_port,
|
2020-02-06 04:46:38 +00:00
|
|
|
"title" => title,
|
2014-05-28 07:37:56 +00:00
|
|
|
"url" => page_for_bulletin(bulletin)
|
|
|
|
},
|
|
|
|
:is_sent=>is_sent
|
|
|
|
)
|
2020-03-22 13:58:26 +00:00
|
|
|
bulletin.email.deliver
|
2014-05-28 07:37:56 +00:00
|
|
|
else
|
|
|
|
bulletin.email.destroy if !bulletin.email.nil?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
private
|
|
|
|
|
2016-08-05 12:00:34 +00:00
|
|
|
def load_settings
|
|
|
|
@announcement_setting = AnnouncementSetting.first rescue nil
|
|
|
|
if @announcement_setting.nil?
|
|
|
|
@announcement_setting = AnnouncementSetting.create
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-02 04:09:44 +00:00
|
|
|
def set_bulletin
|
|
|
|
@bulletin = Bulletin.find(params[:id])
|
2014-05-01 08:41:00 +00:00
|
|
|
end
|
|
|
|
|
2014-05-02 04:09:44 +00:00
|
|
|
def bulletin_params
|
2014-05-28 07:37:56 +00:00
|
|
|
params[:bulletin][:email_sent] = params[:bulletin][:email_sent].nil? ? 0 : params[:bulletin][:email_sent]
|
2014-05-02 04:09:44 +00:00
|
|
|
params.require(:bulletin).permit!
|
2014-05-01 08:41:00 +00:00
|
|
|
end
|
2015-07-08 10:11:25 +00:00
|
|
|
|
|
|
|
def feed_params
|
|
|
|
params.require(:bulletin_feed).permit!
|
|
|
|
end
|
2015-12-22 11:04:13 +00:00
|
|
|
|
|
|
|
def settings_params
|
|
|
|
params.require(:announcement_setting).permit!
|
|
|
|
end
|
2014-04-03 03:18:02 +00:00
|
|
|
end
|