personal-journal/app/controllers/admin/journal_papers_controller.rb

163 lines
4.3 KiB
Ruby
Raw Normal View History

2014-06-12 10:27:26 +00:00
class Admin::JournalPapersController < OrbitMemberController
2014-06-25 06:20:22 +00:00
include Admin::JournalPapersHelper
layout "member_plugin"
2015-01-09 07:30:13 +00:00
before_action :set_journal_paper, only: [:show, :edit , :update, :destroy]
2014-07-11 02:43:28 +00:00
before_action :set_plugin
2015-01-09 07:30:13 +00:00
before_action :get_settings,:only => [:new, :edit, :setting]
2014-07-11 02:43:28 +00:00
2014-08-01 04:23:53 +00:00
before_action :need_access_right
2015-01-09 07:30:13 +00:00
before_action :allow_admin_only, :only => [:index, :setting]
2014-06-12 10:27:26 +00:00
2014-06-04 03:55:13 +00:00
def index
2014-07-18 07:04:07 +00:00
@writing_journals = JournalPaper.order_by(:year=>'desc').page(params[:page]).per(10)
2014-06-12 10:27:26 +00:00
end
def new
2014-08-11 11:16:52 +00:00
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
2015-01-09 07:30:13 +00:00
@journal_paper = JournalPaper.new
2014-11-21 06:13:38 +00:00
if params[:desktop]
render :layout => false
end
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def create
2015-01-20 06:40:24 +00:00
if !journal_paper_params['member_profile_id'].blank?
@member = MemberProfile.find(journal_paper_params['member_profile_id']) rescue nil
@journal_paper = JournalPaper.new(journal_paper_params)
@journal_paper.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
else
redirect_to params['referer_url']
end
elsif !params[:author_members].blank?
params[:author_members].each do |author_member|
journal_paper_params['member_profile_id'] = author_member
@journal_paper = JournalPaper.new(journal_paper_params)
@journal_paper.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
end
end
redirect_to params['referer_url']
2015-01-09 07:30:13 +00:00
else
2015-01-20 06:40:24 +00:00
journal_paper_params['member_profile_id'] = User.find(current_user.id).member_profile_id
@journal_paper = JournalPaper.new(journal_paper_params)
@journal_paper.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
end
2015-01-09 07:30:13 +00:00
redirect_to params['referer_url']
2015-01-20 06:40:24 +00:00
2015-01-09 07:30:13 +00:00
end
2015-01-20 06:40:24 +00:00
2015-01-09 07:30:13 +00:00
end
2014-06-12 10:27:26 +00:00
def edit
2014-08-11 11:16:52 +00:00
@member = @journal_paper.member_profile
2015-01-09 07:30:13 +00:00
if params[:desktop]
2014-11-26 08:09:45 +00:00
render :layout => false
end
2014-06-12 10:27:26 +00:00
end
def update
2015-01-09 07:30:13 +00:00
@member = @journal_paper.member_profile
@journal_paper.update_attributes(journal_paper_params)
@journal_paper.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
else
redirect_to params['referer_url']
2014-06-12 10:27:26 +00:00
end
end
def destroy
@journal_paper.destroy
2015-01-09 07:30:13 +00:00
respond_to do |format|
format.html { redirect_to(admin_journal_paper_url) }
2014-06-12 10:27:26 +00:00
# format.xml { head :ok }
format.js
2014-11-26 11:39:19 +00:00
format.json {render json: {"success" => true}}
2014-06-12 10:27:26 +00:00
end
end
2015-01-09 07:30:13 +00:00
def toggle_hide
if params[:ids]
@journal_papers = JournalPaper.any_in(_id: params[:ids])
2014-06-12 10:27:26 +00:00
2015-01-09 07:30:13 +00:00
@journal_papers.each do |journal_paper|
journal_paper.is_hidden = params[:disable]
journal_paper.save
end
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
render json: {"success"=>true}
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def setting
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def frontend_setting
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@intro = JournalPaperIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? JournalPaperIntro.new({:member_profile_id=>@member.id}) : @intro
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def update_frontend_setting
@member = MemberProfile.find(intro_params['member_profile_id']) rescue nil
@intro = JournalPaperIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? JournalPaperIntro.new({:member_profile_id=>@member.id}) : @intro
@intro.update_attributes(intro_params)
@intro.save
redirect_to URI.encode('/admin/members/'+@member.to_param+'/JournalPaper')
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def get_settings
@journal_levels = JournalLevel.all
@author_types = JournalPaperAuthorType.all
@paper_types = JournalPaperType.all
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def set_plugin
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'JournalPaper'}.first
2014-06-12 10:27:26 +00:00
end
private
def set_journal_paper
2014-06-25 05:26:03 +00:00
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
2015-01-09 07:30:13 +00:00
@journal_paper = JournalPaper.find_by(:uid => uid) rescue JournalPaper.find(params[:id])
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def journal_paper_params
params.require(:journal_paper).permit! rescue nil
2014-06-12 10:27:26 +00:00
end
2015-01-09 07:30:13 +00:00
def intro_params
params.require(:journal_paper_intro).permit! rescue nil
2014-06-12 10:27:26 +00:00
end
2014-06-04 03:55:13 +00:00
end