OSDN Git Service

manifest list mg
[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_html_format format
20     format.html {
21       @author = @item
22     }
23   end
24   
25   def show
26     set_show
27     respond_to do |format|
28       show_html_format format
29       show_prof_format format
30       show_json_format format
31     end
32   end
33   
34   def count
35     list_count
36   end
37   
38   def new
39     form_new
40   end
41   
42   def edit
43     form_edit
44   end
45   
46   def create
47     @author = Author.new()
48     @author.supply_default 
49     @author.attributes = params[:author]
50     @author.overwrite @operators
51     respond_to do |format|
52       if @author.save
53         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
54         format.html { redirect_to root_path }
55         format.json { render json: @author.to_json(Author.show_json_opt), status: :created }
56       else
57         flash[:notice] = I18n.t('flash.notice.not_created', :model => Author.model_name.human)
58         format.html { render action: "new" }
59         format.json { render json: @au.errors, status: :unprocessable_entity }
60       end
61     end
62   end
63
64   def update
65     @author = Author.edit(params[:id], @operators)
66     @author.attributes = params[:author]
67     @author.overwrite @operators
68
69     respond_to do |format|
70       if @author.save
71         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
72         format.html { redirect_to '/home/configure' }
73         format.json { head :ok }
74       else
75         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Author.model_name.human)
76         format.html { render action: "edit" }
77         format.json { render json: @author.errors, status: :unprocessable_entity }
78       end
79     end
80   end
81 end