publication/app/controllers/admin/chapters_controller.rb

60 lines
1.3 KiB
Ruby
Raw Normal View History

2018-10-04 02:47:23 +00:00
class Admin::ChaptersController < OrbitAdminController
def initialize
super
2023-06-04 14:41:53 +00:00
@app_title = "publication"
2018-10-04 02:47:23 +00:00
end
def index
2018-10-04 09:44:54 +00:00
@table_fields = [:title, :author, :page, :sort_number]
2018-10-04 02:47:23 +00:00
@chapters = Chapter.order_by(sort).page(params[:page]).per(10)
render partial: "index" if request.xhr?
end
def new
@chapter = Chapter.new
2023-06-04 14:41:53 +00:00
@publication = Publication.find(params[:publication_id])
if can_edit_or_delete?(@publication)
2018-10-04 02:47:23 +00:00
@tags = @module_app.tags || []
else
render_401
end
end
def create
chapter = Chapter.create(chapter_params)
redirect_to params[:referer_url]
end
def edit
@chapter = Chapter.find(params[:id])
2023-06-04 14:41:53 +00:00
if can_edit_or_delete?(@publication)
@publication = @chapter.publication
2018-10-04 02:47:23 +00:00
else
render_401
end
end
def update
chapter = Chapter.find(params[:id])
chapter.update_attributes(chapter_params)
redirect_to params[:referer_url]
end
def destroy
chapter = Chapter.find(params[:id])
2023-06-04 14:41:53 +00:00
publication = chapter.publication
2018-10-04 02:47:23 +00:00
chapter.destroy
2023-06-04 14:41:53 +00:00
redirect_to admin_publication_path(publication.id, page: params[:page])
2018-10-04 02:47:23 +00:00
end
private
def chapter_params
params.require(:chapter).permit!
end
def setup_vars
2023-06-04 14:41:53 +00:00
@module_app = ModuleApp.where(key: "publication").first
2018-10-04 02:47:23 +00:00
end
end