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

202 lines
5.1 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-06-12 10:27:26 +00:00
2014-06-04 03:55:13 +00:00
def index
2014-06-12 10:27:26 +00:00
@writing_journals = JournalPaper.all
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-06-18 04:09:19 +00:00
@members_data = JournalPaper.member_data rescue nil
2014-06-12 10:27:26 +00:00
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @journal_paper }
end
end
def edit
2014-06-18 04:09:19 +00:00
@members_data = JournalPaper.member_data rescue nil
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
format.html { redirect_to admin_journal_papers_path }
format.xml { render :xml => @journal_paper, :status => :created, :location => @journal_paper }
else
2014-07-10 09:25:26 +00:00
format.html { render action: 'new' }
format.json { render json: @extension.errors, status: :unprocessable_entity }
2014-06-12 10:27:26 +00:00
end
end
end
def update
2014-06-25 05:26:03 +00:00
@journal_paper_authors = @journal_paper.journal_paper_authors
2014-06-12 10:27:26 +00:00
respond_to do |format|
2014-06-25 05:26:03 +00:00
if @journal_paper.update_attributes(journal_paper_attributes)
2014-06-12 10:27:26 +00:00
format.html { redirect_to admin_journal_papers_path }
# format.js { render 'toggle_enable' }
format.xml { head :ok }
else
2014-06-18 07:52:17 +00:00
format.html { render action: "edit" }
2014-07-10 09:25:26 +00:00
format.json { render json: @extension.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
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
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