nccu_com_vnccu_program/app/controllers/admin/nccu_com_vnccu_programs_con...

119 lines
3.4 KiB
Ruby

# encoding: utf-8
class Admin::NccuComVnccuProgramsController < OrbitAdminController
include Admin::NccuComVnccuProgramsHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_nccu_com_vnccu_program, only: [:edit, :destroy, :song_list]
def initialize
super
@app_title = "nccu_com_vnccu_program"
end
def filter_fields(categories)
{
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}
}
end
def index
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories)
@table_fields = [:category, 'nccu_com_vnccu_program.year', 'nccu_com_vnccu_program.semester', 'nccu_com_vnccu_program.program_name', 'nccu_com_vnccu_program.week', 'nccu_com_vnccu_program.hour', 'nccu_com_vnccu_program.host']
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:year=>"desc",:id=>"desc"}
@nccu_com_vnccu_programs = ComVnccuProgram.order_by(sort).with_categories(filters("category"))
@nccu_com_vnccu_programs = search_data(@nccu_com_vnccu_programs,[:title]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def new
@nccu_com_vnccu_program = ComVnccuProgram.new
@hosts = @nccu_com_vnccu_program.get_hosts
end
def create
nccu_com_vnccu_program = ComVnccuProgram.new(com_vnccu_program)
nccu_com_vnccu_program.create_user_id = current_user.id
nccu_com_vnccu_program.update_user_id = current_user.id
nccu_com_vnccu_program.save
redirect_to params['referer_url']
end
def edit
if can_edit_or_delete?(@nccu_com_vnccu_program)
@categories = @module_app.categories.enabled
@hosts = @nccu_com_vnccu_program.get_hosts
else
render_401
end
end
def update
nccu_com_vnccu_program = ComVnccuProgram.find(params[:id])
nccu_com_vnccu_program.update_attributes(com_vnccu_program)
redirect_to params['referer_url']
end
def destroy
@nccu_com_vnccu_program.destroy
redirect_to "/admin/nccu_com_vnccu_programs"
end
def export
@nccu_com_vnccu_programs = ComVnccuProgram.where(:year=>params[:year], :semester=>params[:semester])
@year = params[:year]
@semester = params[:semester]
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="export.xlsx"'
}
end
end
def export_data
end
def song_list
@song_lists = ComVnccuProgramSongList.where(:com_vnccu_program_id => @nccu_com_vnccu_program.id).desc(:created_at).page(params[:page]).per(10)
end
def edit_com_vnccu_program_song_list
@com_vnccu_program_song_list = ComVnccuProgramSongList.find(params[:id])
@com_vnccu_program = ComVnccuProgram.find(@com_vnccu_program_song_list.com_vnccu_program_id)
end
def delete_com_vnccu_program_song_list
@com_vnccu_program_song_list = ComVnccuProgramSongList.find(params[:id])
@com_vnccu_program_id = @com_vnccu_program_song_list.com_vnccu_program_id
@com_vnccu_program_song_list.destroy
redirect_to "/admin/nccu_com_vnccu_programs/@nccu_com_vnccu_program_id.to_s/com_vnccu_program_song_list"
end
private
def set_nccu_com_vnccu_program
@nccu_com_vnccu_program = ComVnccuProgram.find(params[:id])
end
def com_vnccu_program
params.require(:com_vnccu_program).permit!
end
end