orbit-personalbook/app/controllers/panel/personal_book/back_end/writing_book_categorys_cont...

143 lines
3.5 KiB
Ruby

class Panel::PersonalBook::BackEnd::WritingBookCategorysController < OrbitBackendController
include OrbitControllerLib::DivisionForDisable
open_for_manager :except => [:index]
def index
get_types
@writing_book_categorys = @types.all
@writing_book_category = @types.new(:display => 'List')
# @url = panel_personal_book_back_end_writing_book_categorys_path
@url = eval("panel_personal_book_back_end_#{@app_type}s_path")
respond_to do |format|
format.html # index.html.erb
format.js
end
end
# GET /writing_books/1
# GET /writing_books/1.xml
def show
get_types
@writing_book_category = @types.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.js
end
end
# GET /writing_books/new
# GET /writing_books/new.xml
def new
get_types
@writing_book_category = @types.new(:display => 'List')
@verb = :post
respond_to do |format|
format.html # new.html.erb
format.js
end
end
# GET /writing_books/1/edit
def edit
get_types
@writing_book_category = @types.find(params[:id])
# @url = panel_personal_book_back_end_writing_book_category_path(@writing_book_category)
# @url = eval("panel_personal_book_back_end_#{@app_type}_path(@writing_book_category)")
@url = polymorphic_path([:panel, :personal_book, :back_end, @writing_book_category])
@verb = :put
respond_to do |format|
format.html
format.js
end
end
# POST /writing_books
# POST /writing_books.xml
def create
get_types
@writing_book_category = @types.new(params[:writing_book_category])
respond_to do |format|
if @writing_book_category.save
format.html { redirect_to(panel_personal_book_back_end_writing_book_categorys_url, :notice => t('writing_book_category.create_writing_book_category_success')) }
format.js
else
format.html { render :action => "new" }
format.js { render action: "new" }
end
end
end
# PUT /writing_books/1
# PUT /writing_books/1.xml
def update
get_types
@writing_book_category = @types.find(params[:id])
# debugger
# @url = panel_personal_book_back_end_writing_book_category_path(@writing_book_category)
# @url = eval("panel_personal_book_back_end_#{@app_type}_path(#{@writing_book_category})")
@url = polymorphic_path([:panel, :personal_book, :back_end, @writing_book_category])
respond_to do |format|
if @writing_book_category.update_attributes(params[:writing_book_category])
format.html { redirect_to(panel_personal_book_back_end_writing_book_categorys_url, :notice => t('writing_book_category.update_writing_book_category_success')) }
# format.xml { head :ok }
format.js
else
format.html { render :action => "edit" }
format.js { render :action => "edit" }
end
end
end
# DELETE /writing_books/1
# DELETE /writing_books/1.xml
def destroy
get_types
@writing_book_category = @types.find(params[:id])
@writing_book_category.disable = @writing_book_category.disable ? false : true
if @writing_book_category.save!
respond_to do |format|
format.html { redirect_to(panel_personal_book_back_end_writing_book_categorys_url) }
# format.xml { head :ok }
format.js
end
else
flash[:error] = t("writing_book_category.update_failed")
format.html { render :action => "index" }
end
end
protected
def get_types
@types = @app_type.classify.constantize
end
end