2012-03-06 08:41:06 +00:00
|
|
|
class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
|
|
|
include AdminHelper
|
2012-07-06 10:11:55 +00:00
|
|
|
include OrbitControllerLib::DivisionForDisable
|
|
|
|
|
2012-02-13 05:02:52 +00:00
|
|
|
layout 'new_admin'
|
2012-01-11 12:31:52 +00:00
|
|
|
|
2012-01-12 10:38:50 +00:00
|
|
|
before_filter :authenticate_user!
|
2012-07-30 08:38:02 +00:00
|
|
|
before_filter :only => [ :new,:create,:edit,:update,:create] do |controller|
|
2012-07-06 10:11:55 +00:00
|
|
|
controller.get_categorys('BulletinCategory')
|
|
|
|
end
|
2012-04-29 19:14:15 +00:00
|
|
|
# before_filter :for_admin_only,:only => [:]
|
|
|
|
# before_filter :for_app_manager,:only => [:index,:show,]
|
|
|
|
before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins]
|
2012-01-11 12:31:52 +00:00
|
|
|
def index
|
|
|
|
# @bulletins = Bulletin.all
|
|
|
|
# @bulletins = Bulletin.desc("postdate desc")
|
2012-08-03 04:45:47 +00:00
|
|
|
get_categorys('BulletinCategory',params[:bulletin_category_id])
|
|
|
|
get_tags
|
2012-03-28 11:40:12 +00:00
|
|
|
|
2012-04-11 22:50:36 +00:00
|
|
|
@filter = params[:filter]
|
|
|
|
new_filter = params[:new_filter]
|
|
|
|
|
|
|
|
if @filter && params[:clear]
|
|
|
|
@filter.delete(params[:type])
|
|
|
|
elsif @filter && new_filter
|
|
|
|
if @filter.has_key?(new_filter[:type]) && @filter[new_filter[:type]].include?(new_filter[:id].to_s)
|
|
|
|
@filter[new_filter[:type]].delete(new_filter[:id].to_s)
|
|
|
|
elsif @filter.has_key?(new_filter[:type])
|
|
|
|
@filter[new_filter[:type]] << new_filter[:id].to_s
|
|
|
|
else
|
|
|
|
@filter.merge!({new_filter[:type] => [new_filter[:id].to_s]})
|
|
|
|
end
|
|
|
|
elsif new_filter
|
|
|
|
@filter = {new_filter[:type] => [new_filter[:id].to_s]}
|
|
|
|
end
|
|
|
|
|
2012-07-06 10:11:55 +00:00
|
|
|
@bulletin_categories = get_categories_for_index("BulletinCategory")
|
|
|
|
@bulletin_category_ids = @bulletin_categories.collect{|t| t.id.to_s} + [nil]
|
|
|
|
|
|
|
|
@bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin",:bulletin_category_id.in => @bulletin_category_ids) : get_viewable("bulletin",:bulletin_category_id.in => @bulletin_category_ids)
|
2012-01-11 12:31:52 +00:00
|
|
|
|
2012-03-23 10:04:11 +00:00
|
|
|
@bulletin_link = BulletinLink.new
|
2012-03-28 11:40:12 +00:00
|
|
|
@link_url = panel_announcement_back_end_bulletins_path
|
2012-03-23 10:04:11 +00:00
|
|
|
|
|
|
|
@bulletin_file = BulletinFile.new
|
2012-03-28 11:40:12 +00:00
|
|
|
@file_url = panel_announcement_back_end_bulletins_path
|
2012-05-11 09:07:21 +00:00
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
2012-04-11 22:50:36 +00:00
|
|
|
format.js { }
|
2012-01-11 12:31:52 +00:00
|
|
|
format.xml { render :xml => @bulletins }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /bulletins/1
|
|
|
|
# GET /bulletins/1.xml
|
|
|
|
def show
|
2012-01-12 10:38:50 +00:00
|
|
|
@bulletin = Bulletin.find(params[:id])
|
2012-08-03 04:45:47 +00:00
|
|
|
get_tags
|
2012-01-11 12:31:52 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.xml { render :xml => @bulletin }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /bulletins/new
|
|
|
|
# GET /bulletins/new.xml
|
|
|
|
def new
|
2012-06-28 07:19:51 +00:00
|
|
|
@bulletin = Bulletin.new(:postdate => DateTime.now)
|
2012-03-14 12:05:03 +00:00
|
|
|
|
2012-08-03 04:45:47 +00:00
|
|
|
@link_url = panel_announcement_back_end_bulletins_path
|
|
|
|
get_tags
|
|
|
|
respond_to do |format|
|
2012-04-29 19:14:15 +00:00
|
|
|
format.html # new.html.erb
|
|
|
|
format.xml { render :xml => @bulletin }
|
|
|
|
end
|
2012-01-11 12:31:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /bulletins/1/edit
|
|
|
|
def edit
|
|
|
|
@bulletin = Bulletin.find(params[:id])
|
2012-04-24 07:27:46 +00:00
|
|
|
if !current_user.admin? && (@bulletin.is_rejected? || @bulletin.is_checked?)
|
2012-04-23 16:58:56 +00:00
|
|
|
redirect_to :action => :index
|
|
|
|
else
|
|
|
|
# @summary_variable = @bulletin.summary_variable
|
|
|
|
|
|
|
|
@link_url = panel_announcement_back_end_bulletin_path(@bulletin)
|
|
|
|
|
|
|
|
get_tags
|
|
|
|
end
|
2012-01-11 12:31:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /bulletins
|
|
|
|
# POST /bulletins.xml
|
|
|
|
def create
|
2012-07-17 02:21:46 +00:00
|
|
|
get_tags
|
2012-03-23 10:04:11 +00:00
|
|
|
if params[:bulletin_link]
|
|
|
|
|
|
|
|
@bulletin_link = BulletinLink.new(params[:bulletin_link])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @bulletin_link.save
|
|
|
|
format.js { render 'create_bulletin_link' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif params[:bulletin_file]
|
|
|
|
|
|
|
|
@bulletin_file = BulletinFile.new(params[:bulletin_file])
|
|
|
|
|
2012-08-08 02:24:44 +00:00
|
|
|
respond_to do |format|
|
2012-03-23 10:04:11 +00:00
|
|
|
if @bulletin_file.save
|
2012-08-08 02:24:44 +00:00
|
|
|
format.js { render 'create_bulletin_file' }
|
2012-03-23 10:04:11 +00:00
|
|
|
end
|
2012-08-08 02:24:44 +00:00
|
|
|
end
|
2012-03-23 10:04:11 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@bulletin = Bulletin.new(params[:bulletin])
|
2012-06-28 07:19:51 +00:00
|
|
|
@bulletin.deadline = nil if (@bulletin.deadline < @bulletin.postdate rescue nil)
|
2012-03-23 10:04:11 +00:00
|
|
|
|
|
|
|
@bulletin.create_user_id = current_user.id
|
|
|
|
@bulletin.update_user_id = current_user.id
|
2012-08-03 04:45:47 +00:00
|
|
|
if(is_manager? || is_admin?)
|
|
|
|
@bulletin.de_pending
|
|
|
|
end
|
2012-01-11 12:31:52 +00:00
|
|
|
|
2012-03-23 10:04:11 +00:00
|
|
|
respond_to do |format|
|
|
|
|
if @bulletin.save
|
2012-07-13 07:36:10 +00:00
|
|
|
|
2012-07-11 09:56:31 +00:00
|
|
|
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.create_bulletin_success')) }
|
2012-03-23 10:04:11 +00:00
|
|
|
format.xml { render :xml => @bulletin, :status => :created, :location => @bulletin }
|
|
|
|
format.js
|
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-01-11 12:31:52 +00:00
|
|
|
|
2012-08-03 04:45:47 +00:00
|
|
|
def link_quick_add
|
2012-03-23 10:04:11 +00:00
|
|
|
@bulletin_link = BulletinLink.new
|
2012-08-03 04:45:47 +00:00
|
|
|
@link_url = panel_announcement_back_end_bulletins_path
|
|
|
|
@bulletin_link.bulletin_id = params[:bulletin_id]
|
2012-03-23 10:04:11 +00:00
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
respond_to do |format|
|
2012-03-23 10:04:11 +00:00
|
|
|
format.js
|
2012-01-11 12:31:52 +00:00
|
|
|
end
|
2012-03-23 10:04:11 +00:00
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
end
|
|
|
|
|
2012-03-23 10:04:11 +00:00
|
|
|
def link_quick_edit
|
|
|
|
@bulletin_link = BulletinLink.find(params[:bulletin_id])
|
2012-08-03 04:45:47 +00:00
|
|
|
@link_url = panel_announcement_back_end_bulletin_path(@bulletin_link)
|
2012-03-14 12:05:03 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
2012-01-11 12:31:52 +00:00
|
|
|
|
2012-08-03 04:45:47 +00:00
|
|
|
def file_quick_add
|
2012-03-23 10:04:11 +00:00
|
|
|
@bulletin_file = BulletinFile.new
|
2012-03-22 06:33:59 +00:00
|
|
|
@file_url = panel_announcement_back_end_bulletins_path
|
|
|
|
@bulletin_file.bulletin_id = params[:bulletin_id]
|
2012-01-11 12:31:52 +00:00
|
|
|
respond_to do |format|
|
2012-03-23 10:04:11 +00:00
|
|
|
format.js
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_quick_edit
|
|
|
|
@bulletin_file = BulletinFile.find(params[:bulletin_id])
|
2012-03-22 06:33:59 +00:00
|
|
|
@file_url = panel_announcement_back_end_bulletin_path(@bulletin_file)
|
2012-03-14 12:05:03 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
# PUT /bulletins/1
|
|
|
|
# PUT /bulletins/1.xml
|
2012-08-03 04:45:47 +00:00
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
def update
|
2012-08-13 10:35:47 +00:00
|
|
|
if params[:bulletin_link]
|
2012-03-22 06:33:59 +00:00
|
|
|
|
|
|
|
@bulletin_link = BulletinLink.find(params[:id])
|
2012-07-17 02:21:46 +00:00
|
|
|
|
2012-03-22 06:33:59 +00:00
|
|
|
@link_url = panel_announcement_back_end_bulletin_path(@bulletin_link)
|
|
|
|
|
|
|
|
respond_to do |format|
|
2012-07-13 07:36:10 +00:00
|
|
|
|
2012-03-22 06:33:59 +00:00
|
|
|
if @bulletin_link.update_attributes(params[:bulletin_link])
|
|
|
|
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
|
|
|
|
format.js { render 'update_bulletin_link' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif params[:bulletin_file]
|
|
|
|
|
|
|
|
@bulletin_file = BulletinFile.find(params[:id])
|
|
|
|
|
|
|
|
@file_url = panel_announcement_back_end_bulletin_path(@bulletin_file)
|
|
|
|
|
|
|
|
respond_to do |format|
|
2012-07-13 07:36:10 +00:00
|
|
|
|
2012-03-22 06:33:59 +00:00
|
|
|
if @bulletin_file.update_attributes(params[:bulletin_file])
|
|
|
|
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
|
|
|
|
format.js { render 'update_bulletin_file' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@bulletin = Bulletin.find(params[:id])
|
|
|
|
|
|
|
|
# @bulletin.image.clear if params[:bulletin][:image_del] == '1'
|
|
|
|
# if params[:bulletin][:image_del] == '1'
|
|
|
|
# @bulletin.remove_image!
|
|
|
|
# @bulletin.image_del = nil
|
|
|
|
# params[:bulletin][:image_del] = nil
|
|
|
|
# end
|
2012-07-17 02:21:46 +00:00
|
|
|
|
|
|
|
|
2012-06-28 07:19:51 +00:00
|
|
|
delete_out_invalid_date_from_params
|
2012-03-22 06:33:59 +00:00
|
|
|
respond_to do |format|
|
2012-07-13 07:36:10 +00:00
|
|
|
|
2012-04-23 16:46:34 +00:00
|
|
|
if @bulletin.update_attributes(params[:bulletin])
|
2012-08-03 04:45:47 +00:00
|
|
|
if(is_manager? || is_admin?)
|
|
|
|
@bulletin.is_checked = true
|
|
|
|
@bulletin.is_rejected = false
|
|
|
|
@bulletin.de_pending!
|
|
|
|
end
|
2012-07-17 02:21:46 +00:00
|
|
|
# if (params[:bulletin][:is_checked] == "false")
|
|
|
|
# @bulletin.is_rejected = true
|
|
|
|
# @bulletin.save!
|
|
|
|
# end
|
2012-06-28 07:19:51 +00:00
|
|
|
# if (@bulletin.deadline < @bulletin.postdate rescue nil)
|
|
|
|
# @bulletin.deadline = nil
|
|
|
|
# @bulletin.update_user_id = current_user.id
|
|
|
|
# @bulletin.save!
|
|
|
|
# end
|
2012-03-22 06:33:59 +00:00
|
|
|
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
|
|
|
|
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
|
|
|
|
format.js { render 'toggle_enable' }
|
|
|
|
format.xml { head :ok }
|
|
|
|
else
|
2012-08-03 04:45:47 +00:00
|
|
|
get_tags
|
2012-03-22 06:33:59 +00:00
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
2012-03-23 10:04:11 +00:00
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /bulletins/1
|
|
|
|
# DELETE /bulletins/1.xml
|
|
|
|
def destroy
|
|
|
|
@bulletin = Bulletin.find(params[:id])
|
2012-01-12 10:38:50 +00:00
|
|
|
# @bulletin.bulletin_files.destroy
|
2012-01-11 12:31:52 +00:00
|
|
|
@bulletin.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
2012-07-13 07:36:10 +00:00
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
|
2012-02-06 07:23:27 +00:00
|
|
|
# format.xml { head :ok }
|
|
|
|
format.js
|
2012-01-11 12:31:52 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-13 11:15:03 +00:00
|
|
|
|
2012-02-06 07:23:27 +00:00
|
|
|
# def top_edit
|
2012-01-13 11:15:03 +00:00
|
|
|
|
2012-02-06 07:23:27 +00:00
|
|
|
# Bulletin.where(id: params[:id]).update_all( is_top: true )
|
|
|
|
# respond_to do |format|
|
|
|
|
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
|
|
|
|
# format.xml { head :ok }
|
|
|
|
# end
|
2012-01-13 11:15:03 +00:00
|
|
|
|
2012-02-06 07:23:27 +00:00
|
|
|
# end
|
2012-01-11 12:31:52 +00:00
|
|
|
|
2012-03-23 09:32:59 +00:00
|
|
|
|
|
|
|
def load_quick_edit
|
|
|
|
@bulletin = Bulletin.find(params[:id])
|
|
|
|
@type = params[:type]
|
|
|
|
@bulletin_categories = BulletinCategory.all
|
2012-07-05 08:00:45 +00:00
|
|
|
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
|
|
|
|
|
2012-03-23 09:32:59 +00:00
|
|
|
get_tags
|
|
|
|
end
|
|
|
|
|
2012-04-11 22:50:36 +00:00
|
|
|
def delete
|
2012-08-13 16:59:01 +00:00
|
|
|
if params[:ids]
|
|
|
|
bulletins = Bulletin.any_in(:_id => params[:ids]).delete_all
|
2012-04-11 22:50:36 +00:00
|
|
|
end
|
2012-04-29 15:39:28 +00:00
|
|
|
redirect_to panel_announcement_back_end_bulletins_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
|
2012-04-11 22:50:36 +00:00
|
|
|
end
|
|
|
|
|
2012-01-11 12:31:52 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2012-08-14 07:11:52 +00:00
|
|
|
def delete_out_invalid_date_from_params
|
2012-08-14 08:23:34 +00:00
|
|
|
if((params[:bulletin]["deadline(1i)"] && params[:bulletin]["deadline(1i)"].blank?) or (params[:bulletin]["deadline(2i)"] && params[:bulletin]["deadline(2i)"].blank?) or (params[:bulletin]["deadline(3i)"] && params[:bulletin]["deadline(3i)"].blank?))
|
2012-06-28 07:19:51 +00:00
|
|
|
params[:bulletin].delete("deadline(1i)")
|
|
|
|
params[:bulletin].delete("deadline(2i)")
|
|
|
|
params[:bulletin].delete("deadline(3i)")
|
|
|
|
params[:bulletin].delete("deadline(4i)")
|
|
|
|
params[:bulletin].delete("deadline(5i)")
|
2012-08-14 07:11:52 +00:00
|
|
|
@bulletin.deadline = nil
|
2012-08-14 06:38:21 +00:00
|
|
|
end rescue nil
|
2012-06-28 07:19:51 +00:00
|
|
|
end
|
|
|
|
|
2012-07-06 10:11:55 +00:00
|
|
|
# def get_categories_for_index(id = nil)
|
|
|
|
# @bulletin_categories = []
|
|
|
|
# if(is_manager? || is_admin?)
|
|
|
|
# @bulletin_categories = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all)
|
|
|
|
# elsif is_sub_manager?
|
|
|
|
# @bulletin_categories = BulletinCategory.all
|
|
|
|
# end
|
|
|
|
# @bulletin_categories
|
|
|
|
# end
|
|
|
|
|
|
|
|
# def get_categorys(id = nil)
|
|
|
|
# @bulletin_categorys = []
|
|
|
|
# if(is_manager? || is_admin?)
|
|
|
|
# @bulletin_categorys = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all)
|
|
|
|
# elsif is_sub_manager?
|
|
|
|
# @bulletin_categorys = BulletinCategory.all.authed_for_user(current_user,'submit')
|
|
|
|
# end
|
|
|
|
# if @bulletin_categorys.empty? && params[:action] != "index"
|
|
|
|
# flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
|
|
|
|
# redirect_to :action => :index
|
|
|
|
# end
|
|
|
|
# end
|
2012-03-14 12:05:03 +00:00
|
|
|
|
|
|
|
def get_tags
|
|
|
|
module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
|
|
|
|
@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc)
|
|
|
|
end
|
2012-01-11 12:31:52 +00:00
|
|
|
|
|
|
|
end
|