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

189 lines
4.8 KiB
Ruby
Raw Normal View History

2014-06-12 10:27:26 +00:00
class Admin::JournalPapersController < OrbitMemberController
before_action :set_journal_paper, only: [:show, :edit , :update, :destroy]
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-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
@journal_paper = JournalPaper.find(params[:id])
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
format.html { render :action => "new" }
format.xml { render :xml => @journal_paper.errors, :status => :unprocessable_entity }
end
end
end
def update
@writing_journal = JournalPaper.find(params[:id])
@journal_paper_authors = @writing_journal.journal_paper_authors
respond_to do |format|
if @writing_journal.update_attributes(journal_paper_attributes)
format.html { redirect_to admin_journal_papers_path }
# format.js { render 'toggle_enable' }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @writing_journal.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
@journal_paper = JournalPaper.find(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_types
@journal_levels = JournalLevel.all
@author_types = JournalPaperAuthorType.all
@paper_types = JournalPaperType.all
end
2014-06-04 03:55:13 +00:00
end