+++ /dev/null
-class ComicsController < ApplicationController
- layout 'test' if MagicNumber['test_layout']
- if MagicNumber['run_mode'] == 0
- before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
- before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
- else
- before_filter :authenticate_reader, :only => [:top, :index, :show]
- before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
- before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
- end
- before_filter :authenticate_admin!, :only => [:list, :browse]
-
- def index
- @page = Comic.page params[:page]
- @page_size = Comic.page_size params[:page_size]
- @comics = Comic.list(@page, @page_size)
- respond_to do |format|
- format.html {
- @paginate = Comic.list_paginate(@page, @page_size)
- }
- format.json { render json: @comics.to_json(Comic.list_json_opt) }
- format.atom
- format.rss
- end
- end
-
- def show
- @comic = Comic.show(params[:id], [@user, @admin])
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @comic.to_json(Comic.show_json_opt) }
- format.atom
- format.rss
- end
- end
-
- def count
- @comic = {:count => Comic.visible_count}
- respond_to do |format|
- format.json { render json: @comic.to_json }
- end
- end
-
- def list
- @comics = Comic.all
-
- respond_to do |format|
- format.html { render layout: 'system' }# index.html.erb
- format.json { render json: @comics }
- end
- end
-
- def browse
- @comic = Comic.find(params[:id])
-
- respond_to do |format|
- format.html { render layout: 'system' } # show.html.erb
- format.json { render json: @comic }
- end
- end
-
- def new
- @comic = Comic.new
- @comic.supply_default
- respond_to do |format|
- format.html # new.html.erb
- format.js
- format.json { render json: @comic.to_json(Comic.show_json_opt) }
- end
- end
-
- def edit
- @comic = Comic.edit(params[:id], @author)
- respond_to do |format|
- format.html
- format.js
- end
- end
-
- def create
- @comic = Comic.new
- @comic.supply_default
- @comic.attributes = params[:comic]
- @comic.overwrite @author
-
- respond_to do |format|
- if @comic.save
- flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human)
- format.html { redirect_to @comic }
- format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
- else
- flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human)
- format.html { render action: "new" }
- format.json { render json: @comic.errors, status: :unprocessable_entity }
- end
- end
- end
-
- def update
- @comic = Comic.edit(params[:id], @author)
- @comic.attributes = params[:comic]
- @comic.overwrite @author
- respond_to do |format|
- if @comic.save
- flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
- format.html { redirect_to @comic }
- format.json { head :ok }
- else
- flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human)
- format.html { render action: "edit" }
- format.json { render json: @comic.errors, status: :unprocessable_entity }
- end
- end
- end
-
- def destroy
- @comic = Comic.edit(params[:id], @author)
- respond_to do |format|
- if @comic.destroy_with_story
- flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
- format.html { redirect_to '/home/comics' }
- format.json { head :ok }
- else
- flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
- format.html { redirect_to @comic }
- format.json { render json: @comic.errors, status: :unprocessable_entity }
- end
- end
- end
-end