OSDN Git Service

temp
[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   before_filter :authenticate_admin!, :only => [:list, :browse]
12
13   def self.model
14     Comic
15   end
16   
17   def index
18     public_list
19   end
20
21   def show
22     @item = Comic.show(params[:id], @operators)
23     respond_to do |format|
24       format.html {
25         @comic = @item
26       }
27       format.prof { 
28         @profiler = @@profiler_manager.open(@item, @operators)
29         render :template => 'system/prof', :locals => {
30           :profiler => @profiler
31         }
32       }
33       format.json { render json: @item.to_json(Comic.show_json_opt) }
34       format.atom 
35       format.rss 
36     end
37   end
38
39   def count
40     @comic = {:count => Comic.visible_count}
41     respond_to do |format|
42       format.json { render json: @comic.to_json }
43     end
44   end
45   
46   def list
47     @comics = Comic.all
48
49     respond_to do |format|
50       format.html { render layout: 'system' }# index.html.erb
51       format.json { render json: @comics }
52     end
53   end
54
55   def browse
56     @comic = Comic.find(params[:id])
57
58     respond_to do |format|
59       format.html { render layout: 'system' } # show.html.erb
60       format.json { render json: @comic }
61     end
62   end
63   
64   def new
65     @comic = Comic.new
66     @comic.supply_default
67     respond_to do |format|
68       format.html # new.html.erb
69       format.js
70       format.json { render json: @comic.to_json(Comic.show_json_opt) }
71     end
72   end
73
74   def edit
75     @comic = Comic.edit(params[:id], @author)
76     respond_to do |format|
77       format.html 
78       format.js
79     end
80   end
81
82   def create
83     @comic = Comic.new
84     @comic.supply_default 
85     @comic.attributes = params[:comic]
86     @comic.overwrite @operators
87
88     respond_to do |format|
89       if @comic.save
90         flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human)
91         format.html { redirect_to @comic }
92         format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
93       else
94         flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human)
95         format.html { render action: "new" }
96         format.json { render json: @comic.errors, status: :unprocessable_entity }
97       end
98     end
99   end
100
101   def update
102     @comic = Comic.edit(params[:id], @operators)
103     @comic.attributes = params[:comic]
104     @comic.overwrite @operators
105     respond_to do |format|
106       if @comic.save
107         flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
108         format.html { redirect_to @comic }
109         format.json { head :ok }
110       else
111         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human)
112         format.html { render action: "edit" }
113         format.json { render json: @comic.errors, status: :unprocessable_entity }
114       end
115     end
116   end
117
118   def destroy
119     @comic = Comic.edit(params[:id], @author)
120     respond_to do |format|
121       if @comic.destroy_with_story
122         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
123         format.html { redirect_to '/home/comics' }
124         format.json { head :ok }
125       else
126         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
127         format.html { redirect_to @comic }
128         format.json { render json: @comic.errors, status: :unprocessable_entity }
129       end
130     end
131   end
132 end