OSDN Git Service

3eda75ebaf004a3a3bef22f69e829e2798f19fb8
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
1 class ComicsController < ApplicationController
2   layout 'test' if Pettanr::Application.test_layout
3   if Const.run_mode == 0
4     before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy]
5   else
6     before_filter :authenticate_user!, :only => [:top, :index, :show, :play, :new, :create, :edit, :update, :destroy]
7   end
8   before_filter :authenticate_admin!, :only => [:list, :browse]
9
10   def top
11     respond_to do |format|
12       format.html # index.html.erb
13     end
14   end
15   
16   # GET /comics
17   # GET /comics.json
18   def index
19     @page = Comic.page params[:page]
20     @page_size = Comic.page_size params[:page_size]
21     @comics = Comic.list(@page, @page_size)
22     respond_to do |format|
23       format.html # index.html.erb
24       format.json { render json: @comics.to_json(Comic.list_json_opt) }
25     end
26   end
27
28   # GET /comics/1
29   # GET /comics/1.json
30   def show
31     @comic = Comic.show(params[:id], @author)
32
33     respond_to do |format|
34       format.html # show.html.erb
35       format.json { render json: @comic.to_json(Comic.show_json_opt) }
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   # GET /comics/new
65   # GET /comics/new.js
66   def new
67     @comic = Comic.new
68     @comic.supply_default
69     respond_to do |format|
70       format.html # new.html.erb
71       format.js
72       format.json { render json: @comic.to_json(Comic.show_json_opt) }
73     end
74   end
75
76   # GET /comics/1/edit
77   # GET /comics/1.js/edit
78   def edit
79     @comic = Comic.edit(params[:id], @author)
80     respond_to do |format|
81       format.html 
82       format.js
83     end
84   end
85
86   # POST /comics
87   # POST /comics.json
88   def create
89     @comic = Comic.new
90     @comic.supply_default 
91     @comic.attributes = params[:comic]
92     @comic.overwrite @author
93
94     respond_to do |format|
95       if @comic.save
96         format.html { redirect_to @comic, notice: 'Comic was successfully created.' }
97         format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
98       else
99         format.html { render action: "new" }
100         format.json { render json: @comic.errors, status: :unprocessable_entity }
101       end
102     end
103   end
104
105   # PUT /comics/1
106   # PUT /comics/1.json
107   def update
108     @comic = Comic.edit(params[:id], @author)
109     @comic.attributes = params[:comic]
110     @comic.overwrite @author
111     respond_to do |format|
112       if @comic.save
113         format.html { redirect_to @comic, notice: 'Comic was successfully updated.' }
114         format.json { head :ok }
115       else
116         format.html { render action: "edit" }
117         format.json { render json: @comic.errors, status: :unprocessable_entity }
118       end
119     end
120   end
121
122   # DELETE /comics/1
123   # DELETE /comics/1.json
124   def destroy
125     @comic = Comic.edit(params[:id], @author)
126     @comic.destroy
127     respond_to do |format|
128       format.html { redirect_to comics_url }
129       format.json { head :ok }
130     end
131   end
132 end