OSDN Git Service

t#30328:pull porting
[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   else
6     before_filter :authenticate_reader, :only => [:index, :show]
7     before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
8   end
9   before_filter :authenticate_admin!, :only => [:list, :browse]
10
11   def index
12     @page = Author.page params[:page]
13     @page_size = Author.page_size params[:page_size]
14     @authors = Author.list(@page, @page_size)
15
16     respond_to do |format|
17       format.html # index.html.erb
18       format.json { render :json => @authors.to_json(Author.list_json_opt) }
19     end
20   end
21
22   def show
23     @au = Author.show(params[:id], [@author, @admin])
24
25     respond_to do |format|
26       format.html
27       format.json { render :json => @au.to_json(Author.show_json_opt) }
28     end
29   end
30
31   def count
32     @au = {:count => Author.visible_count}
33     respond_to do |format|
34       format.json { render json: @au.to_json }
35     end
36   end
37   
38   def list
39     @authors = Author.all
40
41     respond_to do |format|
42       format.html { render layout: 'system' }
43     end
44   end
45
46   def browse
47     @au = Author.find(params[:id])
48
49     respond_to do |format|
50       format.html { render layout: 'system' }
51     end
52   end
53   
54   def new
55     @au = Author.new
56     @au.supply_default 
57
58     respond_to do |format|
59       format.html # new.html.erb
60       format.js
61       format.json { render json: @au.to_json(Author.show_json_opt) }
62     end
63   end
64
65   def edit
66     @au = Author.edit(params[:id], @author)
67   end
68
69   def create
70     @au = Author.new()
71     @au.supply_default 
72     @au.attributes = params[:author]
73     @au.overwrite @user.id
74     respond_to do |format|
75       if @au.save
76         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
77         format.html { redirect_to root_path }
78         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
79       else
80         format.html { render action: "new" }
81         format.json { render json: @au.errors, status: :unprocessable_entity }
82       end
83     end
84   end
85
86   def update
87     @au = Author.edit(params[:id], @author)
88     @au.attributes = params[:author]
89     @au.overwrite @user.id
90
91     respond_to do |format|
92       if @au.save
93         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
94         format.html { redirect_to '/home/configure' }
95         format.json { head :ok }
96       else
97         format.html { render action: "edit" }
98         format.json { render json: @au.errors, status: :unprocessable_entity }
99       end
100     end
101   end
102 end