From a2a7efc593f3409af5cf27c7a4dd6b6409f94506 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 9 Mar 2016 18:00:24 +0800 Subject: [PATCH] some fixes for certificates --- .../admin/certificates_controller.rb | 57 ++++++++++++++++++- .../admin/certificates/_certificates.html.erb | 2 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/certificates_controller.rb b/app/controllers/admin/certificates_controller.rb index 0b3f5d2..389c02f 100644 --- a/app/controllers/admin/certificates_controller.rb +++ b/app/controllers/admin/certificates_controller.rb @@ -1,4 +1,11 @@ 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) @@ -16,7 +23,6 @@ class Admin::CertificatesController < OrbitMemberController def edit @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @certificate = Certificate.find(params[:id]) end def frontend_setting @@ -25,6 +31,55 @@ class Admin::CertificatesController < OrbitMemberController @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 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 + + 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 diff --git a/app/views/admin/certificates/_certificates.html.erb b/app/views/admin/certificates/_certificates.html.erb index 9ae83b1..02ae460 100644 --- a/app/views/admin/certificates/_certificates.html.erb +++ b/app/views/admin/certificates/_certificates.html.erb @@ -4,7 +4,7 @@ <%= link_to certificate.title, page_for_certificate(certificate), target: "blank"%>