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