OSDN Git Service

fix filer
[pettanr/pettanr.git] / app / controllers / authors_controller.rb
1 class AuthorsController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
4     before_filter :authenticate_author, :only => [:edit, :update]
5   else
6     before_filter :authenticate_reader, :only => [:index, :show, :count]
7     before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
8     before_filter :authenticate_author, :only => [:edit, :update]
9   end
10
11   def self.model
12     Author
13   end
14   
15   def index
16     filer_list
17   end
18   
19   def show
20     @item = Author.show(params[:id], @operators)
21
22     respond_to do |format|
23       format.html {
24         @author = @item
25       }
26       format_prof format
27       format.json { render :json => @item.to_json(Author.show_json_opt) }
28     end
29   end
30   
31   def count
32     list_count
33   end
34   
35   def new
36     @author = Author.new
37     @author.supply_default 
38
39     respond_to do |format|
40       format.html
41       format.js
42       format.json { render json: @au.to_json(Author.show_json_opt) }
43     end
44   end
45
46   def edit
47     @author = Author.edit(params[:id], @operators)
48   end
49
50   def create
51     @author = Author.new()
52     @author.supply_default 
53     @author.attributes = params[:author]
54     @author.overwrite @operators
55     respond_to do |format|
56       if @author.save
57         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
58         format.html { redirect_to root_path }
59         format.json { render json: @author.to_json(Author.show_json_opt), status: :created }
60       else
61         flash[:notice] = I18n.t('flash.notice.not_created', :model => Author.model_name.human)
62         format.html { render action: "new" }
63         format.json { render json: @au.errors, status: :unprocessable_entity }
64       end
65     end
66   end
67
68   def update
69     @author = Author.edit(params[:id], @operators)
70     @author.attributes = params[:author]
71     @author.overwrite @operators
72
73     respond_to do |format|
74       if @author.save
75         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
76         format.html { redirect_to '/home/configure' }
77         format.json { head :ok }
78       else
79         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Author.model_name.human)
80         format.html { render action: "edit" }
81         format.json { render json: @author.errors, status: :unprocessable_entity }
82       end
83     end
84   end
85 end