class Admin::ChaptersController < OrbitAdminController def initialize super @app_title = "publication" end def index @table_fields = [:title, :author, :page, :sort_number] @chapters = Chapter.order_by(sort).page(params[:page]).per(10) render partial: "index" if request.xhr? end def new @chapter = Chapter.new @publication = Publication.find(params[:publication_id]) if can_edit_or_delete?(@publication) @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]) if can_edit_or_delete?(@publication) @publication = @chapter.publication 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]) publication = chapter.publication chapter.destroy redirect_to admin_publication_path(publication.id, page: params[:page]) end private def chapter_params params.require(:chapter).permit! end def setup_vars @module_app = ModuleApp.where(key: "publication").first end end