OSDN Git Service

t#31566:add mylist sb
[pettanr/pettanr.git] / app / controllers / authors_controller.rb
1 class AuthorsController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
5     before_filter :authenticate_author, :only => [:edit, :update]
6   else
7     before_filter :authenticate_reader, :only => [:index, :show, :comics, :stories, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
8     before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
9     before_filter :authenticate_author, :only => [:edit, :update]
10   end
11   before_filter :authenticate_admin!, :only => [:list, :browse]
12
13   def index
14     @page = Author.page params[:page]
15     @page_size = Author.page_size params[:page_size]
16     @authors = Author.list(@page, @page_size)
17
18     respond_to do |format|
19       format.html {
20         @paginate = Author.list_paginate(@page, @page_size)
21       }
22       format.json { render :json => @authors.to_json(Author.list_json_opt) }
23     end
24   end
25
26   def show
27     @au = Author.show(params[:id], [@user, @admin])
28
29     respond_to do |format|
30       format.html
31       format.json { render :json => @au.to_json(Author.show_json_opt) }
32     end
33   end
34
35   def comics
36     @au = Author.show(params[:id], [@user, @admin])
37
38     @page = Author.page params[:page]
39     @page_size = Author.comic_page_size params[:page_size]
40     @comics = Comic.himlist(@au, @page, @page_size)
41
42     respond_to do |format|
43       format.html {
44         @paginate = Comic.himlist_paginate(@au, @page, @page_size)
45       }
46       format.json { render json: @comics.to_json(Comic.list_json_opt) }
47     end
48   end
49   
50   def stories
51     @au = Author.show(params[:id], [@user, @admin])
52
53     @page = Author.page params[:page]
54     @page_size = Author.comic_page_size params[:page_size]
55     @stories = Story.himlist(@au, @page, @page_size)
56
57     respond_to do |format|
58       format.html {
59         @paginate = Story.himlist_paginate(@au, @page, @page_size)
60       }
61       format.json { render json: @stories.to_json(Story.list_json_opt) }
62     end
63   end
64   
65   def panels
66     @au = Author.show(params[:id], [@user, @admin])
67
68     @page = Author.page params[:page]
69     @page_size = Author.panel_page_size params[:page_size]
70     @panels = Panel.himlist(@au, @page, @page_size)
71
72     respond_to do |format|
73       format.html {
74         @paginate = Panel.himlist_paginate(@au, @page, @page_size)
75       }
76       format.json { render text: Panel.list_as_json_text(@panels) }
77     end
78   end
79   
80   def panel_pictures
81     @au = Author.show(params[:id], [@user, @admin])
82
83     @page = Author.page params[:page]
84     @page_size = Author.panel_picture_page_size params[:page_size]
85     @panel_pictures = PanelPicture.himlist(@au, @page, @page_size)
86
87     respond_to do |format|
88       format.html {
89         @paginate = PanelPicture.himlist_paginate(@au, @page, @page_size)
90       }
91       format.json { render json: @panel_pictures.to_json(PanelPicture.list_json_opt) }
92     end
93   end
94   
95   def speech_balloons
96     @au = Author.show(params[:id], [@user, @admin])
97
98     @page = Author.page params[:page]
99     @page_size = Author.panel_picture_page_size params[:page_size]
100     @speech_balloons = SpeechBalloon.himlist(@au, @page, @page_size)
101
102     respond_to do |format|
103       format.html {
104         @paginate = SpeechBalloon.himlist_paginate(@au, @page, @page_size)
105       }
106       format.json { render json: @speech_balloons.to_json(SpeechBalloon.list_json_opt) }
107     end
108   end
109   
110   def ground_pictures
111     @au = Author.show(params[:id], [@user, @admin])
112
113     @page = Author.page params[:page]
114     @page_size = Author.ground_picture_page_size params[:page_size]
115     @ground_pictures = GroundPicture.himlist(@au, @page, @page_size)
116
117     respond_to do |format|
118       format.html {
119         @paginate = GroundPicture.himlist_paginate(@au, @page, @page_size)
120       }
121       format.json { render json: @ground_pictures.to_json(GroundPicture.list_json_opt) }
122     end
123   end
124   
125   def ground_colors
126     @au = Author.show(params[:id], [@user, @admin])
127
128     @page = Author.page params[:page]
129     @page_size = Author.ground_color_page_size params[:page_size]
130     @ground_colors = GroundColor.himlist(@au, @page, @page_size)
131
132     respond_to do |format|
133       format.html {
134         @paginate = GroundColor.himlist_paginate(@au, @page, @page_size)
135       }
136       format.json { render json: @ground_colors.to_json(GroundColor.list_json_opt) }
137     end
138   end
139   
140   def count
141     @au = {:count => Author.visible_count}
142     respond_to do |format|
143       format.json { render json: @au.to_json }
144     end
145   end
146   
147   def list
148     @authors = Author.all
149
150     respond_to do |format|
151       format.html { render layout: 'system' }
152     end
153   end
154
155   def browse
156     @au = Author.find(params[:id])
157
158     respond_to do |format|
159       format.html { render layout: 'system' }
160     end
161   end
162   
163   def new
164     @au = Author.new
165     @au.supply_default 
166
167     respond_to do |format|
168       format.html # new.html.erb
169       format.js
170       format.json { render json: @au.to_json(Author.show_json_opt) }
171     end
172   end
173
174   def edit
175     @au = Author.edit(params[:id], @author)
176   end
177
178   def create
179     @au = Author.new()
180     @au.supply_default 
181     @au.attributes = params[:author]
182     @au.overwrite @user.id
183     respond_to do |format|
184       if @au.save
185         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
186         format.html { redirect_to root_path }
187         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
188       else
189         flash[:notice] = I18n.t('flash.notice.not_created', :model => Author.model_name.human)
190         format.html { render action: "new" }
191         format.json { render json: @au.errors, status: :unprocessable_entity }
192       end
193     end
194   end
195
196   def update
197     @au = Author.edit(params[:id], @author)
198     @au.attributes = params[:author]
199     @au.overwrite @user.id
200
201     respond_to do |format|
202       if @au.save
203         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
204         format.html { redirect_to '/home/configure' }
205         format.json { head :ok }
206       else
207         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Author.model_name.human)
208         format.html { render action: "edit" }
209         format.json { render json: @au.errors, status: :unprocessable_entity }
210       end
211     end
212   end
213 end