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