1 class SpeechBalloonsController < ApplicationController
2 layout 'test' if MagicNumber['test_layout']
3 if MagicNumber['run_mode'] == 0
4 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
5 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
7 before_filter :authenticate_reader, :only => [:index, :show, :by_panel, :by_author]
8 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
9 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
29 @item = SpeechBalloon.show(params[:id], @operators)
30 respond_to do |format|
32 @speech_balloon = @item
35 format.json { render json: @item.to_json(SpeechBalloon.show_json_opt) }
40 raise Pettanr::NotWork unless @operators.author.working_panel
41 @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @operators
43 @panel = Panel.edit(@operators.author.working_panel, @operators)
44 @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
46 @speech_balloon.supply_default
47 @speech_balloon.get_balloon.supply_default
48 @speech_balloon.get_speech.supply_default
50 respond_to do |format|
52 render @speech_balloon_template.engine_name + '/speech_balloons/new'
54 format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
59 @speech_balloon = SpeechBalloon.show(params[:id], @operators)
60 @speech_balloon_template = @speech_balloon.speech_balloon_template
61 @panel = Panel.edit(@speech_balloon.panel.id,@operators)
65 respond_to do |format|
67 render @speech_balloon_template.engine_name + '/speech_balloons/edit'
73 raise Pettanr::NotWork unless @operators.author.working_panel
74 SpeechBalloon.fold_extend_settings params
75 @panel = Panel.edit(@operators.author.working_panel, @operators)
76 @speech_balloon = SpeechBalloon.new
77 @speech_balloon.attributes = params[:speech_balloon]
79 @speech_balloon_template = @speech_balloon.speech_balloon_template
82 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
84 @speech_balloon.overwrite @panel.id
86 respond_to do |format|
87 if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon])
88 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
89 format.html { redirect_to @panel }
90 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
92 flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
94 render @speech_balloon_template.engine_name + '/speech_balloons/new'
96 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
102 SpeechBalloon.fold_extend_settings params
103 @speech_balloon = SpeechBalloon.show(params[:id], @operators)
104 @speech_balloon.attributes = params[:speech_balloon]
106 @speech_balloon_template = @speech_balloon.speech_balloon_template
107 @speech_balloon.boost
109 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
111 @panel = Panel.edit(@speech_balloon.panel.id, @operators)
112 @speech_balloon.overwrite @panel.id
114 respond_to do |format|
115 if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon])
116 flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
117 format.html { redirect_to @speech_balloon }
118 format.json { head :ok }
120 flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
122 render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
124 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
130 @speech_balloon = SpeechBalloon.show(params[:id], @operators)
131 @panel = Panel.edit(@speech_balloon.panel.id, @operators)
133 respond_to do |format|
134 if @speech_balloon.remove @operators.author
135 flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
136 format.html { redirect_to @panel }
137 format.json { head :ok }
139 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
140 format.html { redirect_to @speech_balloon }
141 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }