OSDN Git Service

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