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]
8 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
9 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
11 before_filter :authenticate_admin!, :only => [:list, :browse]
14 @page = SpeechBalloon.page params[:page]
15 @page_size = SpeechBalloon.page_size params[:page_size]
16 @speech_balloons = SpeechBalloon.list(@page, @page_size)
18 respond_to do |format|
20 @paginate = SpeechBalloon.list_paginate(@page, @page_size)
22 format.json { render json: @speech_balloons.to_json(SpeechBalloon.list_json_opt) }
27 @speech_balloon = SpeechBalloon.show(params[:id], [@user, @admin])
28 respond_to do |format|
29 format.html # show.html.erb
30 format.prof { render :template => 'top/prof', :layout => true }
31 format.prof { render :template => 'top/prof', :layout => true }
32 format.json { render json: @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
37 @speech_balloons = SpeechBalloon.all
39 respond_to do |format|
40 format.html { render layout: 'system' }
41 format.json { render json: @speech_balloons }
46 @speech_balloon = SpeechBalloon.find(params[:id])
48 respond_to do |format|
49 format.html { render layout: 'system' }
50 format.json { render json: @speech_balloon }
55 raise Pettanr::NotWork unless @author.working_panel
56 @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @author
58 @panel = Panel.edit(@author.working_panel, @author)
59 @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
61 @speech_balloon.supply_default
62 @speech_balloon.get_balloon.supply_default
63 @speech_balloon.get_speech.supply_default
65 respond_to do |format|
67 render @speech_balloon_template.engine_name + '/speech_balloons/new'
69 format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
74 @speech_balloon = SpeechBalloon.show(params[:id], @author)
75 @speech_balloon_template = @speech_balloon.speech_balloon_template
76 @panel = Panel.edit(@speech_balloon.panel.id, @author)
80 respond_to do |format|
82 render @speech_balloon_template.engine_name + '/speech_balloons/edit'
88 raise Pettanr::NotWork unless @author.working_panel
89 SpeechBalloon.fold_extend_settings params
90 @panel = Panel.edit(@author.working_panel, @author)
91 @speech_balloon = SpeechBalloon.new
92 @speech_balloon.attributes = params[:speech_balloon]
94 @speech_balloon_template = @speech_balloon.speech_balloon_template
97 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
99 @speech_balloon.overwrite @panel.id
101 respond_to do |format|
102 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
103 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
104 format.html { redirect_to @panel }
105 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
107 flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
109 render @speech_balloon_template.engine_name + '/speech_balloons/new'
111 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
117 SpeechBalloon.fold_extend_settings params
118 @speech_balloon = SpeechBalloon.show(params[:id], @author)
119 @speech_balloon.attributes = params[:speech_balloon]
121 @speech_balloon_template = @speech_balloon.speech_balloon_template
122 @speech_balloon.boost
124 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
126 @panel = Panel.edit(@speech_balloon.panel.id, @author)
127 @speech_balloon.overwrite @panel.id
129 respond_to do |format|
130 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
131 flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
132 format.html { redirect_to @speech_balloon }
133 format.json { head :ok }
135 flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
137 render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
139 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
145 @speech_balloon = SpeechBalloon.show(params[:id], @author)
146 @panel = Panel.edit(@speech_balloon.panel.id, @author)
148 respond_to do |format|
149 if @speech_balloon.remove @author
150 flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
151 format.html { redirect_to @panel }
152 format.json { head :ok }
154 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
155 format.html { redirect_to @speech_balloon }
156 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }