OSDN Git Service

t#31223:add them contents list for author and artist
[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, :panels]
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 # index.html.erb
20       format.json { render :json => @authors.to_json(Author.list_json_opt) }
21     end
22   end
23
24   def show
25     @au = Author.show(params[:id], [@user, @admin])
26
27     respond_to do |format|
28       format.html
29       format.json { render :json => @au.to_json(Author.show_json_opt) }
30     end
31   end
32
33   def comics
34     @au = Author.show(params[:id], [@user, @admin])
35
36     @page = Author.page params[:page]
37     @page_size = Author.comic_page_size params[:page_size]
38     @comics = Comic.mylist(@au, @page, @page_size)
39
40     respond_to do |format|
41       format.html # index.html.erb
42       format.json { render json: @comics.to_json(Comic.list_json_opt) }
43     end
44   end
45   
46   def panels
47     @au = Author.show(params[:id], [@user, @admin])
48
49     @page = Author.page params[:page]
50     @page_size = Author.panel_page_size params[:page_size]
51     @panels = Panel.mylist(@au, @page, @page_size)
52
53     respond_to do |format|
54       format.html # index.html.erb
55       format.json { render text: Panel.list_as_json_text(@panels) }
56     end
57   end
58   
59   def count
60     @au = {:count => Author.visible_count}
61     respond_to do |format|
62       format.json { render json: @au.to_json }
63     end
64   end
65   
66   def list
67     @authors = Author.all
68
69     respond_to do |format|
70       format.html { render layout: 'system' }
71     end
72   end
73
74   def browse
75     @au = Author.find(params[:id])
76
77     respond_to do |format|
78       format.html { render layout: 'system' }
79     end
80   end
81   
82   def new
83     @au = Author.new
84     @au.supply_default 
85
86     respond_to do |format|
87       format.html # new.html.erb
88       format.js
89       format.json { render json: @au.to_json(Author.show_json_opt) }
90     end
91   end
92
93   def edit
94     @au = Author.edit(params[:id], @author)
95   end
96
97   def create
98     @au = Author.new()
99     @au.supply_default 
100     @au.attributes = params[:author]
101     @au.overwrite @user.id
102     respond_to do |format|
103       if @au.save
104         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
105         format.html { redirect_to root_path }
106         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
107       else
108         format.html { render action: "new" }
109         format.json { render json: @au.errors, status: :unprocessable_entity }
110       end
111     end
112   end
113
114   def update
115     @au = Author.edit(params[:id], @author)
116     @au.attributes = params[:author]
117     @au.overwrite @user.id
118
119     respond_to do |format|
120       if @au.save
121         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
122         format.html { redirect_to '/home/configure' }
123         format.json { head :ok }
124       else
125         format.html { render action: "edit" }
126         format.json { render json: @au.errors, status: :unprocessable_entity }
127       end
128     end
129   end
130 end