OSDN Git Service

t#:
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
1 class ComicsController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
5     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
6   else
7     before_filter :authenticate_reader, :only => [:top, :index, :show]
8     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
9     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
10   end
11
12   def self.model
13     Comic
14   end
15   
16   def index
17     public_list
18   end
19
20   def show
21     @item = Comic.show(params[:id], @operators)
22     respond_to do |format|
23       format.html {
24         @comic = @item
25       }
26       format_prof format
27       format.json { render json: @item.to_json(Comic.show_json_opt) }
28       format.atom 
29       format.rss 
30     end
31   end
32
33   def count
34     @comic = {:count => Comic.visible_count}
35     respond_to do |format|
36       format.json { render json: @comic.to_json }
37     end
38   end
39   
40   def new
41     @comic = Comic.new
42     @comic.supply_default
43     respond_to do |format|
44       format.html
45       format.js
46       format.json { render json: @comic.to_json(Comic.show_json_opt) }
47     end
48   end
49
50   def edit
51     @comic = Comic.edit(params[:id], @operators)
52     respond_to do |format|
53       format.html 
54       format.js
55     end
56   end
57
58   def create
59     @comic = Comic.new
60     @comic.supply_default 
61     @comic.attributes = params[:comic]
62     @comic.overwrite @operators
63
64     respond_to do |format|
65       if @comic.save
66         flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human)
67         format.html { redirect_to @comic }
68         format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
69       else
70         flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human)
71         format.html { render action: "new" }
72         format.json { render json: @comic.errors, status: :unprocessable_entity }
73       end
74     end
75   end
76
77   def update
78     @comic = Comic.edit(params[:id], @operators)
79     @comic.attributes = params[:comic]
80     @comic.overwrite @operators
81     respond_to do |format|
82       if @comic.save
83         flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
84         format.html { redirect_to @comic }
85         format.json { head :ok }
86       else
87         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human)
88         format.html { render action: "edit" }
89         format.json { render json: @comic.errors, status: :unprocessable_entity }
90       end
91     end
92   end
93
94   def destroy
95     @comic = Comic.edit(params[:id], @operators)
96     respond_to do |format|
97       if @comic.destroy_with_story
98         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
99         format.html { redirect_to '/home/comics' }
100         format.json { head :ok }
101       else
102         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
103         format.html { redirect_to @comic }
104         format.json { render json: @comic.errors, status: :unprocessable_entity }
105       end
106     end
107   end
108 end