OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05client
[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]
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 count
34     @au = {:count => Author.visible_count}
35     respond_to do |format|
36       format.json { render json: @au.to_json }
37     end
38   end
39   
40   def list
41     @authors = Author.all
42
43     respond_to do |format|
44       format.html { render layout: 'system' }
45     end
46   end
47
48   def browse
49     @au = Author.find(params[:id])
50
51     respond_to do |format|
52       format.html { render layout: 'system' }
53     end
54   end
55   
56   def new
57     @au = Author.new
58     @au.supply_default 
59
60     respond_to do |format|
61       format.html # new.html.erb
62       format.js
63       format.json { render json: @au.to_json(Author.show_json_opt) }
64     end
65   end
66
67   def edit
68     @au = Author.edit(params[:id], @author)
69   end
70
71   def create
72     @au = Author.new()
73     @au.supply_default 
74     @au.attributes = params[:author]
75     @au.overwrite @user.id
76     respond_to do |format|
77       if @au.save
78         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
79         format.html { redirect_to root_path }
80         format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
81       else
82         format.html { render action: "new" }
83         format.json { render json: @au.errors, status: :unprocessable_entity }
84       end
85     end
86   end
87
88   def update
89     @au = Author.edit(params[:id], @author)
90     @au.attributes = params[:author]
91     @au.overwrite @user.id
92
93     respond_to do |format|
94       if @au.save
95         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
96         format.html { redirect_to '/home/configure' }
97         format.json { head :ok }
98       else
99         format.html { render action: "edit" }
100         format.json { render json: @au.errors, status: :unprocessable_entity }
101       end
102     end
103   end
104 end