hps_member/app/controllers/admin/member_counselors_controlle...

111 lines
3.1 KiB
Ruby
Raw Normal View History

2017-05-18 12:12:35 +00:00
class Admin::MemberCounselorsController < OrbitAdminController
def uploads
@files = HpsFile.all.desc(:created_at).page(params[:page]).per(10)
@table_fields = ["member_counselor.file_date","member_counselor.file_title", "member_counselor.downloaded_times", "member_counselor.account", "member_counselor.user_type", "actions"]
end
2017-06-29 08:06:30 +00:00
def results
@files = HpsResult.all.desc(:created_at).page(params[:page]).per(10)
@table_fields = ["member_counselor.file_date","member_counselor.file_title", "member_counselor.downloaded_times", "member_counselor.account", "member_counselor.user_type", "actions"]
end
def records
@records = HpsCounselingRecord.all.desc(:created_at).page(params[:page]).per(10)
@table_fields = ["member_counselor.file_date","member_counselor.title", "member_counselor.event_title", "member_counselor.account", "actions"]
end
2017-05-18 12:12:35 +00:00
def index
2017-06-29 08:06:30 +00:00
if !params[:user_type].present?
@counselors = HpsMember.all.desc(:created_at)
else
types = params[:user_type].collect{|ut| ut.to_i if ut.is_i?}
types.delete(nil)
@counselors = HpsMember.where(:user_type.in => params[:user_type])
end
@counselors = search_data(@counselors,[:name, :account]).page(params[:page]).per(10)
2017-05-18 12:12:35 +00:00
@table_fields = ["member_counselor.account","member_counselor.name", "member_counselor.user_type"]
end
def new
@counselor = HpsMember.new
end
def edit
@counselor = HpsMember.find(params[:id])
end
def create
@counselor = HpsMember.new(counselor_params)
if @counselor.save
redirect_to admin_member_counselors_path
else
render :action => "new"
end
end
def destroy
counselor = HpsMember.find(params[:id])
counselor.destroy
redirect_to admin_member_counselors_path(:page => params[:page])
end
def update
@counselor = HpsMember.find(params[:id])
if @counselor.update_attributes(counselor_params)
redirect_to admin_member_counselors_path(:page => params[:page])
else
render :action => "edit"
end
end
def get_info
@objects = []
case params[:get_info]
when "counties"
@objects = HpsCity.find(params[:id]).hps_counties.asc(:old_id)
when "schools"
@objects = HpsCounty.find(params[:id]).hps_schools.asc(:old_id)
end
render :layout => false
end
def destroy_upload
hpsupload = HpsFile.find(params[:id])
hpsupload.destroy
redirect_to uploads_admin_member_counselors_path
end
2017-06-29 08:06:30 +00:00
def destroy_result
hpresult = HpsResult.find(params[:id])
hpresult.destroy
redirect_to results_admin_member_counselors_path
end
def destroy_record
record = HpsCounselingRecord.find(params[:id])
record.destroy
redirect_to records_admin_member_counselors_path
end
def showrecord
@record = HpsCounselingRecord.find(params[:id])
end
def export_records
@records = HpsCounselingRecord.all.desc(:created_at)
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="counselor_records.xlsx"'
}
end
end
2017-05-18 12:12:35 +00:00
private
def counselor_params
params.require(:hps_member).permit!
end
end