class Admin::CertificatesController < OrbitMemberController include Admin::CertificatesHelper layout "member_plugin" before_action :set_certificate, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :need_access_right before_action :allow_admin_only, :only => [:index, :setting] def index @certificates = Certificate.order_by(:created_at=>'desc').page(params[:page]).per(10) end def new @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @certificate = Certificate.new end def create certificate = Certificate.create(certificate_params) redirect_to params[:referer_url] end def edit @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil end def frontend_setting @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @intro = CertificateIntro.find_by(:member_profile_id=>@member.id) rescue nil @intro = @intro.nil? ? CertificateIntro.new({:member_profile_id=>@member.id}) : @intro end def destroy @course.destroy redirect_to admin_courses_path(:page => params[:page]) end def update @course.update_attributes(course_params) @course.save redirect_to params[:referer_url] end def update_frontend_setting @member = MemberProfile.find(intro_params['member_profile_id']) rescue nil @intro = CertificateIntro.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+'/Certificate') end def toggle_hide if params[:ids] @certificates = Certificate.any_in(_id: params[:ids]) @certificates.each do |certificate| certificate.is_hidden = params[:disable] certificate.save end end render json: {"success"=>true} end private def certificate_params params.require(:certificate).permit! end def intro_params params.require(:certificate_intro).permit! end def set_plugin @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Certificate'}.first end def set_certificate 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 @certificate = Certificate.find_by(:uid => uid) rescue Certificate.find(params[:id]) end end