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

203 lines
5.2 KiB
Ruby

class Admin::JournalPapersController < OrbitMemberController
include Admin::JournalPapersHelper
layout "member_plugin"
before_action :set_journal_paper, only: [:show, :edit , :update]
before_action :get_plugins, only: [:index, :writing_journal_setting, :new, :create, :edit, :update]
before_action :set_types, only: [:writing_journal_setting, :new, :edit, :create, :update]
before_action :find_journal_paper, only: [:destroy]
before_action :set_plugin
before_action :need_access_right
before_action :allow_admin_only, :only => [:index, :writing_journal_setting]
def index
@writing_journals = JournalPaper.order_by(:year=>'desc').page(params[:page]).per(10)
respond_to do |format|
format.html # index.html.erb
format.js { }
format.xml { render :xml => @writing_journals }
end
end
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
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
end
def edit
@member = @journal_paper.member_profile
end
def create
@journal_paper = JournalPaper.new(journal_paper_attributes)
respond_to do |format|
if @journal_paper.save
format.html { redirect_to params['referer_url'] }
format.json { render action: 'show', status: :created, location: @journal_paper }
else
format.html { render action: 'new' }
format.json { render json: @journal_paper.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @journal_paper.update_attributes(journal_paper_attributes)
format.html { redirect_to params['referer_url'] }
# format.js { render 'toggle_enable' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @journal_paper.errors, status: :unprocessable_entity }
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
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
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)
end
def find_journal_paper
@journal_paper = JournalPaper.find_by(id: params[:id])
end
def journal_paper_attributes
params.require(:journal_paper).permit! rescue nil
end
def get_plugins
@plugins = OrbitApp::Plugin::Registration.all rescue nil
end
def set_plugin
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'JournalPaper'}.first
end
def set_types
@journal_levels = JournalLevel.all
@author_types = JournalPaperAuthorType.all
@paper_types = JournalPaperType.all
end
end