forked from saurabh/personal-journal
197 lines
5.0 KiB
Ruby
197 lines
5.0 KiB
Ruby
class Admin::JournalPapersController < OrbitMemberController
|
|
include Admin::JournalPapersHelper
|
|
layout "member_plugin"
|
|
|
|
before_action :set_journal_paper, only: [:show, :edit , :update, :destroy]
|
|
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]
|
|
|
|
def index
|
|
@writing_journals = JournalPaper.all
|
|
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
|
|
@members_data = JournalPaper.member_data rescue nil
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.xml { render :xml => @journal_paper }
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@members_data = JournalPaper.member_data rescue nil
|
|
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
|
|
@journal_paper_authors = @journal_paper.journal_paper_authors
|
|
|
|
respond_to do |format|
|
|
if @journal_paper.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 => @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 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
|
|
|
|
end
|