nkuht-donate/app/controllers/admin/nkuht_donates_controller.rb

121 lines
2.9 KiB
Ruby

# encoding: utf-8
class Admin::NkuhtDonatesController < OrbitAdminController
require 'axlsx'
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_nkuht_donate, only: [:edit, :update, :set_write_off, :destroy]
def initialize
super
@app_title = "nkuht_donate"
end
def index
@filter_fields = {}
@table_fields = ['nkuht_donate.donation_payment_number', 'nkuht_donate.donation_serial_date', 'nkuht_donate.name', 'nkuht_donate.donation_amount', 'nkuht_donate.donation_way', 'nkuht_donate.donate_public', 'nkuht_donate.donation_unit', 'nkuht_donate.donation_use', 'nkuht_donate.donation_payment_status', 'nkuht_donate.donation_write_off_status']
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:created_at=>"desc"}
@nkuht_donates = NkuhtDonateMain.all.order_by(sort)
@nkuht_donates = search_data(@nkuht_donates,[:name]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def export
@nkuht_donates = NkuhtDonateMain.all.order_by({:created_at=>"desc"})
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="export.xlsx"'
}
end
end
def new
@nkuht_donate = NkuhtDonateMain.new
@nkuht_donate_units = NkuhtDonateUnit.all
@nkuht_donate_departments = NkuhtDonateDepartment.all
@nkuht_donate_uses = NkuhtDonateUse.all
@showother = "hide"
end
def create
nkuht_donate = NkuhtDonateMain.new(nkuht_donate_params)
nkuht_donate.donation_serial_number = NkuhtDonateMain.get_serial_number
nkuht_donate.donation_payment_number = NkuhtDonateMain.get_payment_number
nkuht_donate.create_user_id = current_user.id
nkuht_donate.update_user_id = current_user.id
nkuht_donate.save
redirect_to params['referer_url']
end
def edit
@nkuht_donate_units = NkuhtDonateUnit.all
@nkuht_donate_departments = NkuhtDonateDepartment.all
@nkuht_donate_uses = NkuhtDonateUse.all
if !@nkuht_donate.nkuht_donate_use_id.blank?
if @nkuht_donate.nkuht_donate_use.title == "其他" || @nkuht_donate.nkuht_donate_use.title == "Other"
@showother = ""
else
@showother = "hide"
end
else
@showother = "hide"
end
end
def update
@nkuht_donate.update_user_id = current_user.id
@nkuht_donate.update_attributes(nkuht_donate_params)
redirect_to params['referer_url']
end
def set_write_off
@nkuht_donate.donation_write_off_status = true
@nkuht_donate.save
redirect_to "/admin/nkuht_donates?page=#{params['page']}"
end
def destroy
@nkuht_donate.destroy
redirect_to "/admin/nkuht_donates"
end
private
def set_nkuht_donate
@nkuht_donate = NkuhtDonateMain.find(params[:id])
end
def nkuht_donate_params
params.require(:nkuht_donate_main).permit!
end
end