106 lines
2.7 KiB
Ruby
106 lines
2.7 KiB
Ruby
class Admin::TechnologyTransfersController < OrbitMemberController
|
|
include Admin::CertificatesHelper
|
|
layout "member_plugin"
|
|
before_action :set_tt, only: [:show, :edit , :update, :destroy]
|
|
before_action :set_plugin
|
|
before_action :get_settings,:only => [:new, :edit, :setting]
|
|
|
|
before_action :need_access_right
|
|
before_action :allow_admin_only, :only => [:index, :setting]
|
|
|
|
def index
|
|
@technology_transfers = TechnologyTransfer.order_by(:created_at=>'desc').page(params[:page]).per(10)
|
|
end
|
|
|
|
def new
|
|
@tt = TechnologyTransfer.new
|
|
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
|
|
end
|
|
|
|
def create
|
|
tt = TechnologyTransfer.create(tt_params)
|
|
redirect_to params[:referer_url]
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def destroy
|
|
@tt.destroy
|
|
redirect_to admin_courses_path(:page => params[:page])
|
|
end
|
|
|
|
def update
|
|
@tt.update_attributes(tt_params)
|
|
@tt.save
|
|
redirect_to params[:referer_url]
|
|
end
|
|
|
|
def setting
|
|
end
|
|
|
|
def frontend_setting
|
|
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
|
|
@intro = TechnologyTransferIntro.find_by(:member_profile_id=>@member.id) rescue nil
|
|
@intro = @intro.nil? ? TechnologyTransferIntro.new({:member_profile_id=>@member.id}) : @intro
|
|
end
|
|
|
|
def update_frontend_setting
|
|
@member = MemberProfile.find(intro_params['member_profile_id']) rescue nil
|
|
@intro = CourseIntro.find_by(:member_profile_id=>@member.id) rescue nil
|
|
@intro = @intro.nil? ? CourseIntro.new({:member_profile_id=>@member.id}) : @intro
|
|
@intro.update_attributes(intro_params)
|
|
@intro.save
|
|
redirect_to URI.encode('/admin/members/'+@member.to_param+'/TechnologyTransfer')
|
|
end
|
|
|
|
def toggle_hide
|
|
if params[:ids]
|
|
@projects = Course.any_in(_id: params[:ids])
|
|
|
|
@projects.each do |project|
|
|
project.is_hidden = params[:disable]
|
|
project.save
|
|
end
|
|
end
|
|
|
|
render json: {"success"=>true}
|
|
end
|
|
|
|
private
|
|
|
|
def tt_params
|
|
params.require(:technology_transfer).permit!
|
|
end
|
|
|
|
|
|
def intro_params
|
|
params.require(:technology_transfer_intro).permit! rescue nil
|
|
end
|
|
|
|
def get_settings
|
|
@technology_transfer_categories = TechnologyTransferCategory.all.order_by(:sort_position => "asc")
|
|
end
|
|
|
|
def set_plugin
|
|
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'TechnologyTransfer'}.first
|
|
end
|
|
|
|
def set_tt
|
|
path = request.path.split('/')
|
|
if path.last.include? '-'
|
|
uid = path[-1].split("-").last
|
|
uid = uid.split("?").first
|
|
else
|
|
uid = path[-2].split("-").last
|
|
uid = uid.split("?").first
|
|
end
|
|
@tt = TechnologyTransfer.find_by(:uid => uid) rescue TechnologyTransfer.find(params[:id])
|
|
end
|
|
|
|
|
|
end
|