OSDN Git Service

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