OSDN Git Service

fix Manifest
[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, :scrolls, :scroll_panels, :comics, :stories, :story_sheets, :sheets, :sheet_panels, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
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     public_list
17   end
18   
19   def scrolls
20     has_many_list
21   end
22   
23   def scroll_panels
24     has_many_list
25   end
26   
27   def comics
28     has_many_list
29   end
30   
31   def stories
32     has_many_list
33   end
34   
35   def story_sheets
36     has_many_list
37   end
38   
39   def sheets
40     has_many_list
41   end
42   
43   def sheet_panels
44     has_many_list
45   end
46   
47   def panels
48     has_many_list
49   end
50   
51   def panel_pictures
52     has_many_list
53   end
54   
55   def speech_balloons
56     has_many_list
57   end
58   
59   def ground_pictures
60     has_many_list
61   end
62   
63   def ground_colors
64     has_many_list
65   end
66   
67   def show
68     @item = Author.show(params[:id], @operators)
69
70     respond_to do |format|
71       format.html {
72         @author = @item
73       }
74       format_prof format
75       format.json { render :json => @item.to_json(Author.show_json_opt) }
76     end
77   end
78
79   def count
80     @au = {:count => Author.visible_count}
81     respond_to do |format|
82       format.json { render json: @au.to_json }
83     end
84   end
85   
86   def new
87     @author = Author.new
88     @author.supply_default 
89
90     respond_to do |format|
91       format.html
92       format.js
93       format.json { render json: @au.to_json(Author.show_json_opt) }
94     end
95   end
96
97   def edit
98     @author = Author.edit(params[:id], @operators)
99   end
100
101   def create
102     @author = Author.new()
103     @author.supply_default 
104     @author.attributes = params[:author]
105     @author.overwrite @operators
106     respond_to do |format|
107       if @author.save
108         flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
109         format.html { redirect_to root_path }
110         format.json { render json: @author.to_json(Author.show_json_opt), status: :created }
111       else
112         flash[:notice] = I18n.t('flash.notice.not_created', :model => Author.model_name.human)
113         format.html { render action: "new" }
114         format.json { render json: @au.errors, status: :unprocessable_entity }
115       end
116     end
117   end
118
119   def update
120     @author = Author.edit(params[:id], @operators)
121     @author.attributes = params[:author]
122     @author.overwrite @operators
123
124     respond_to do |format|
125       if @author.save
126         flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
127         format.html { redirect_to '/home/configure' }
128         format.json { head :ok }
129       else
130         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Author.model_name.human)
131         format.html { render action: "edit" }
132         format.json { render json: @author.errors, status: :unprocessable_entity }
133       end
134     end
135   end
136 end