OSDN Git Service

rename model name
[pettanr/pettanr.git] / app / controllers / sheets_controller.rb
1 class SheetsController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
4     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
5   else
6     before_filter :authenticate_reader, :only => [
7       :index, :show, :play, :by_story, :by_panel, :by_author, :count, :count_by_story, :count_by_panel, :count_by_author
8     ]
9     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
10     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
11   end
12   
13   def index
14     filer_list
15   end
16   
17   def by_story
18     filer_list
19   end
20   
21   def by_panel
22     filer_list
23   end
24   
25   def by_author
26     filer_list
27   end
28   
29   def show_html_format format
30     format.html {
31       if @operators.author
32         @new_panel_items = assist_items('home', 'panels')
33         
34         @new_story_items = assist_items('home', 'stories')
35         @fresh_story_items = assist_items('home', 'story_sheets').map {|ss| ss.story}
36       end
37     }
38   end
39   
40   def show
41     set_show
42     respond_to do |format|
43       show_html_format format
44       show_prof_format format
45       show_json_format_for_root format
46     end
47   end
48   
49   def play
50     @item = self.class.model.show(params[:id], @operators)
51     set_play
52     list_result = @list.open(@operators, params[:id])
53     @items = list_result.items 
54     respond_to do |format|
55       format.html {
56         if @operators.author
57           @new_panel_items = assist_items('panel', 'private')
58         end
59       }
60       format.json { render json: @items.to_json(self.class.model.list_json_opt) }
61     end
62   end
63   
64   def count
65     list_count
66   end
67   
68   def count_by_story
69     list_count
70   end
71   
72   def count_by_panel
73     list_count
74   end
75   
76   def count_by_author
77     list_count
78   end
79   
80   def new
81     set_new
82     respond_to do |format|
83       format.html {
84         @editor = Editor::SheetEditor.new @item, @operators
85         render :template => @editor.template_name, :locals => {
86           :editor => @editor
87         }
88       }
89       format.json { render json: @item.to_json }
90     end
91   end
92   
93   def edit
94     set_edit
95     respond_to do |format|
96       format.html {
97         @editor = Editor::SheetEditor.new @item, @operators
98         render :template => @editor.template_name, :locals => {
99           :editor => @editor
100         }
101       }
102       format.json { render json: @item.to_json }
103     end
104   end
105   
106   def create
107     @sheet = Sheet.new
108     @sheet.supply_default 
109     jsn = nil
110     if params[:json]
111       jsn = JSON.parse_no_except(params[:json])
112     end
113     @prm = params[:sheet] || jsn
114     
115     respond_to do |format|
116       if @sheet.store @prm, @operators
117         created_html_format format
118         created_json_format format
119       else
120         format.html {
121           flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
122           @editor = Editor::PanelEditor.new @item, @operators
123           render :template => @editor.template_name, :locals => {
124             :editor => @editor
125           }
126         }
127         not_created_json_format format
128       end
129     end
130   end
131   
132   def update
133     @sheet = Sheet.edit(params[:id], @operators)
134     jsn = nil
135     if params[:json]
136       jsn = JSON.parse(params[:json])
137     end
138     @prm = params[:sheet] || jsn
139     respond_to do |format|
140       if @sheet.store @prm, @operators
141         updated_html_format format
142         updated_json_format format
143       else
144         format.html {
145           flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
146           @editor = Editor::PanelEditor.new @item, @operators
147           render :template => @editor.template_name, :locals => {
148             :editor => @editor
149           }
150         }
151         not_updated_json_format format
152       end
153     end
154   end
155   
156   def destroy
157     @sheet = Sheet.edit(params[:id], @operators)
158     respond_to do |format|
159       if @sheet.destroy_with_sheet_panel
160         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Sheet.model_name.human)
161         format.html { redirect_to '/home/sheets' }
162         format.json { head :ok }
163       else
164         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Sheet.model_name.human)
165         format.html { redirect_to @sheet }
166         format.json { render json: @sheet.errors, status: :unprocessable_entity }
167       end
168     end
169   end
170 end