some fixes for certificates

This commit is contained in:
Harry Bomrah 2016-03-09 18:00:24 +08:00
parent 8f6fbe68a0
commit a2a7efc593
2 changed files with 57 additions and 2 deletions

View File

@ -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

View File

@ -4,7 +4,7 @@
<%= link_to certificate.title, page_for_certificate(certificate), target: "blank"%>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t('edit'), edit_admin_certificate_path(certificate.id,:page => params[:page]) %></li>
<li><%= link_to t('edit'), edit_admin_certificate_path(certificate,:page => params[:page]) %></li>
<li><%= link_to t(:delete_), admin_certificate_path(id: certificate.id, :page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' } %></li>
</ul>
</div>