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