OSDN Git Service

manifest list mg
[pettanr/pettanr.git] / app / controllers / speech_balloons_controller.rb
1 class SpeechBalloonsController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
4     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
5   else
6     before_filter :authenticate_reader, :only => [
7       :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author
8     ]
9     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
10     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
11   end
12
13   def self.model
14     SpeechBalloon
15   end
16   
17   def index
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       @speech_balloon = @item
32     }
33   end
34   
35   def show
36     set_show
37     respond_to do |format|
38       show_html_format format
39       show_prof_format format
40       show_json_format format
41     end
42   end
43   
44   def count
45     list_count
46   end
47   
48   def count_by_panel
49     list_count
50   end
51   
52   def count_by_author
53     list_count
54   end
55   
56   def new
57     raise Pettanr::NotWork unless @operators.author.working_panel
58     @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @operators
59     
60     @panel = Panel.edit(@operators.author.working_panel, @operators)
61     @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
62     @speech_balloon.boost
63     @speech_balloon.supply_default
64     @speech_balloon.get_balloon.supply_default 
65     @speech_balloon.get_speech.supply_default 
66     
67     respond_to do |format|
68       format.html {
69         render @speech_balloon_template.engine_name + '/speech_balloons/new'
70       }
71       format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
72     end
73   end
74
75   def edit
76     @speech_balloon = SpeechBalloon.show(params[:id], @operators)
77     @speech_balloon_template = @speech_balloon.speech_balloon_template
78     @panel = Panel.edit(@speech_balloon.panel.id,@operators)
79     
80     @speech_balloon.boost
81     
82     respond_to do |format|
83       format.html {
84         render @speech_balloon_template.engine_name + '/speech_balloons/edit'
85       }
86     end
87   end
88
89   def create
90     raise Pettanr::NotWork unless @operators.author.working_panel
91     SpeechBalloon.fold_extend_settings params
92     @panel = Panel.edit(@operators.author.working_panel, @operators)
93     @speech_balloon = SpeechBalloon.new 
94     @speech_balloon.attributes = params[:speech_balloon]
95     
96     @speech_balloon_template = @speech_balloon.speech_balloon_template
97     @speech_balloon.boost
98     
99     params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture 
100     
101     @speech_balloon.overwrite @panel.id
102     
103     respond_to do |format|
104       if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon])
105         flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
106         format.html { redirect_to @panel }
107         format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
108       else
109         flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
110         format.html {
111           render @speech_balloon_template.engine_name + '/speech_balloons/new'
112         }
113         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
114       end
115     end
116   end
117
118   def update
119     SpeechBalloon.fold_extend_settings params
120     @speech_balloon = SpeechBalloon.show(params[:id], @operators)
121     @speech_balloon.attributes = params[:speech_balloon]
122     
123     @speech_balloon_template = @speech_balloon.speech_balloon_template
124     @speech_balloon.boost
125     
126     params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture 
127     
128     @panel = Panel.edit(@speech_balloon.panel.id, @operators)
129     @speech_balloon.overwrite @panel.id
130     
131     respond_to do |format|
132       if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon])
133         flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
134         format.html { redirect_to @speech_balloon }
135         format.json { head :ok }
136       else
137         flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
138         format.html {
139           render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
140         }
141         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
142       end
143     end
144   end
145
146   def destroy
147     @speech_balloon = SpeechBalloon.show(params[:id], @operators)
148     @panel = Panel.edit(@speech_balloon.panel.id, @operators)
149     
150     respond_to do |format|
151       if @speech_balloon.remove @operators.author
152         flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
153         format.html { redirect_to @panel }
154         format.json { head :ok }
155       else
156         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
157         format.html { redirect_to @speech_balloon }
158         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
159       end
160     end
161   end
162   
163 end