OSDN Git Service

t#31537:fix flash
[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, :ground_pictures, :ground_colors, :panel_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 ground_pictures
96     @au = Author.show(params[:id], [@user, @admin])
97
98     @page = Author.page params[:page]
99     @page_size = Author.ground_picture_page_size params[:page_size]
100     @ground_pictures = GroundPicture.himlist(@au, @page, @page_size)
101
102     respond_to do |format|
103       format.html {
104         @paginate = GroundPicture.himlist_paginate(@au, @page, @page_size)
105       }
106       format.json { render json: @ground_pictures.to_json(GroundPicture.list_json_opt) }
107     end
108   end
109   
110   def ground_colors
111     @au = Author.show(params[:id], [@user, @admin])
112
113     @page = Author.page params[:page]
114     @page_size = Author.ground_color_page_size params[:page_size]
115     @ground_colors = GroundColor.himlist(@au, @page, @page_size)
116
117     respond_to do |format|
118       format.html {
119         @paginate = GroundColor.himlist_paginate(@au, @page, @page_size)
120       }
121       format.json { render json: @ground_colors.to_json(GroundColor.list_json_opt) }
122     end
123   end
124   
125   def count
126     @au = {:count => Author.visible_count}
127     respond_to do |format|
128       format.json { render json: @au.to_json }
129     end
130   end
131   
132   def list
133     @authors = Author.all
134
135     respond_to do |format|
136       format.html { render layout: 'system' }
137     end
138   end
139
140   def browse
141     @au = Author.find(params[:id])
142
143     respond_to do |format|
144       format.html { render layout: 'system' }
145     end
146   end
147   
148   def new
149     @au = Author.new
150     @au.supply_default 
151
152     respond_to do |format|
153       format.html # new.html.erb
154       format.js
155       format.json { render json: @au.to_json(Author.show_json_opt) }
156     end
157   end
158
159   def edit
160     @au = Author.edit(params[:id], @author)
161   end
162
163   def create
164     @au = Author.new()
165     @au.supply_default 
166     @au.attributes = params[:author]
167     @au.overwrite @user.id
168     respond_to do |format|
169       if @au.save
170         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
171         format.html { redirect_to root_path }
172         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
173       else
174         flash[:notice] = I18n.t('flash.notice.not_created', :model => Author.model_name.human)
175         format.html { render action: "new" }
176         format.json { render json: @au.errors, status: :unprocessable_entity }
177       end
178     end
179   end
180
181   def update
182     @au = Author.edit(params[:id], @author)
183     @au.attributes = params[:author]
184     @au.overwrite @user.id
185
186     respond_to do |format|
187       if @au.save
188         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
189         format.html { redirect_to '/home/configure' }
190         format.json { head :ok }
191       else
192         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Author.model_name.human)
193         format.html { render action: "edit" }
194         format.json { render json: @au.errors, status: :unprocessable_entity }
195       end
196     end
197   end
198 end