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

215 lines
5.6 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"
2014-07-10 06:52:06 +00:00
before_action :set_journal_paper, only: [:show, :edit , :update]
2014-06-12 10:27:26 +00:00
before_action :get_plugins, only: [:index, :writing_journal_setting, :new, :create, :edit, :update]
2014-06-18 04:09:19 +00:00
before_action :set_types, only: [:writing_journal_setting, :new, :edit, :create, :update]
2014-07-10 06:52:06 +00:00
before_action :find_journal_paper, only: [:destroy]
2014-07-11 02:43:28 +00:00
before_action :set_plugin
2014-08-01 04:23:53 +00:00
before_action :need_access_right
before_action :allow_admin_only, :only => [:index, :writing_journal_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
respond_to do |format|
format.html # index.html.erb
format.js { }
format.xml { render :xml => @writing_journals }
end
2014-06-04 03:55:13 +00:00
end
2014-06-12 10:27:26 +00:00
def show
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @journal_paper }
end
end
def new
@journal_paper = JournalPaper.new
2014-08-11 11:16:52 +00:00
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
2014-11-21 06:13:38 +00:00
if params[:desktop]
render :layout => false
end
2014-06-12 10:27:26 +00:00
end
def edit
2014-08-11 11:16:52 +00:00
@member = @journal_paper.member_profile
2014-11-26 08:09:45 +00:00
if params[:desktop]
render :layout => false
end
2014-06-12 10:27:26 +00:00
end
def create
@journal_paper = JournalPaper.new(journal_paper_attributes)
respond_to do |format|
if @journal_paper.save
2014-11-26 11:39:19 +00:00
if params[:desktop] == "true"
format.json { render json: get_paper_list }
end
2014-08-01 04:23:53 +00:00
format.html { redirect_to params['referer_url'] }
2014-07-11 02:43:28 +00:00
format.json { render action: 'show', status: :created, location: @journal_paper }
2014-06-12 10:27:26 +00:00
else
2014-07-10 09:25:26 +00:00
format.html { render action: 'new' }
2014-07-10 10:23:57 +00:00
format.json { render json: @journal_paper.errors, status: :unprocessable_entity }
2014-06-12 10:27:26 +00:00
end
end
end
def update
respond_to do |format|
2014-06-25 05:26:03 +00:00
if @journal_paper.update_attributes(journal_paper_attributes)
2014-11-26 11:39:19 +00:00
if params[:desktop] == "true"
format.json { render json: get_paper_list }
end
2014-08-01 04:23:53 +00:00
format.html { redirect_to params['referer_url'] }
2014-06-12 10:27:26 +00:00
# format.js { render 'toggle_enable' }
2014-07-11 02:43:28 +00:00
format.json { head :no_content }
2014-06-12 10:27:26 +00:00
else
2014-06-18 07:52:17 +00:00
format.html { render action: "edit" }
2014-07-10 10:23:57 +00:00
format.json { render json: @journal_paper.errors, status: :unprocessable_entity }
2014-06-12 10:27:26 +00:00
end
end
end
def destroy
@journal_paper.destroy
respond_to do |format|
format.html { redirect_to(admin_journal_papers_url) }
# 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
def delete
end
def writing_journal_setting
@set_level_type = JournalLevel.new(display: 'List')
@level_type_url = admin_journal_papers_path
@set_author_type = JournalPaperAuthorType.new(display: 'List')
@author_type_url = admin_journal_papers_path
@set_paper_type = JournalPaperType.new(display: 'List')
@paper_type_url = admin_journal_papers_path
end
def add_level
@set_level_type = JournalLevel.new(display: 'List')
@level_type_url = admin_journal_levels_path
@set_level_type.id = params[:id]
respond_to do |format|
format.js
end
end
def edit_level
@set_level_type = JournalLevel.find(params[:journal_paper_id])
@level_type_url = admin_journal_level_path(@set_level_type)
respond_to do |format|
format.js
end
end
def add_author_type
@set_author_type = JournalPaperAuthorType.new(display: 'List')
@author_type_url = admin_journal_paper_author_types_path
@set_author_type.id = params[:id]
respond_to do |format|
format.js
end
end
def edit_author_type
@set_author_type = JournalPaperAuthorType.find(params[:journal_paper_id])
@author_type_url = admin_journal_paper_author_type_path(@set_author_type)
respond_to do |format|
format.js
end
end
def add_paper_type
@set_paper_type = JournalPaperType.new(:display => 'List')
@paper_type_url = admin_journal_paper_types_path
@set_paper_type.id = params[:id]
respond_to do |format|
format.js
end
end
def edit_paper_type
@set_paper_type = JournalPaperType.find(params[:journal_paper_id])
@paper_type_url = admin_journal_paper_type_path(@set_paper_type)
respond_to do |format|
format.js
end
end
def data_share
if params[:ids]
@writing_journals = JournalPaper.any_in(_id: params[:ids])
@writing_journals.each do |writing_journal|
writing_journal.is_hidden = params[:disable]
writing_journal.save
end
end
respond_to do |format|
format.html { redirect_to(admin_member_path(id: params[:member_profile_id],show_plugin_profile: "JournalPaper")) }
format.json { render json: {"success"=>true}.to_json}
end
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
@journal_paper = JournalPaper.find_by(uid: uid)
2014-06-12 10:27:26 +00:00
end
2014-07-10 06:52:06 +00:00
def find_journal_paper
@journal_paper = JournalPaper.find_by(id: params[:id])
end
2014-06-12 10:27:26 +00:00
def journal_paper_attributes
params.require(:journal_paper).permit! rescue nil
end
def get_plugins
@plugins = OrbitApp::Plugin::Registration.all rescue nil
end
2014-07-11 02:43:28 +00:00
def set_plugin
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'JournalPaper'}.first
end
2014-06-12 10:27:26 +00:00
def set_types
@journal_levels = JournalLevel.all
@author_types = JournalPaperAuthorType.all
@paper_types = JournalPaperType.all
end
2014-06-04 03:55:13 +00:00
end