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)
21 render :template => 'system/filer', :locals => {
22 :items => @speech_balloons, :model => SpeechBalloon,
23 :roles => [@user, @admin], :pager => @paginate
26 format.json { render json: @speech_balloons.to_json(SpeechBalloon.list_json_opt) }
31 @speech_balloon = SpeechBalloon.show(params[:id], [@user, @admin])
32 respond_to do |format|
33 format.html # show.html.erb
34 format.prof { render :template => 'top/prof', :layout => true }
35 format.prof { render :template => 'top/prof', :layout => true }
36 format.json { render json: @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
41 @speech_balloons = SpeechBalloon.all
43 respond_to do |format|
44 format.html { render layout: 'system' }
45 format.json { render json: @speech_balloons }
50 @speech_balloon = SpeechBalloon.find(params[:id])
52 respond_to do |format|
53 format.html { render layout: 'system' }
54 format.json { render json: @speech_balloon }
59 raise Pettanr::NotWork unless @author.working_panel
60 @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @author
62 @panel = Panel.edit(@author.working_panel, @author)
63 @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
65 @speech_balloon.supply_default
66 @speech_balloon.get_balloon.supply_default
67 @speech_balloon.get_speech.supply_default
69 respond_to do |format|
71 render @speech_balloon_template.engine_name + '/speech_balloons/new'
73 format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
78 @speech_balloon = SpeechBalloon.show(params[:id], @author)
79 @speech_balloon_template = @speech_balloon.speech_balloon_template
80 @panel = Panel.edit(@speech_balloon.panel.id, @author)
84 respond_to do |format|
86 render @speech_balloon_template.engine_name + '/speech_balloons/edit'
92 raise Pettanr::NotWork unless @author.working_panel
93 SpeechBalloon.fold_extend_settings params
94 @panel = Panel.edit(@author.working_panel, @author)
95 @speech_balloon = SpeechBalloon.new
96 @speech_balloon.attributes = params[:speech_balloon]
98 @speech_balloon_template = @speech_balloon.speech_balloon_template
101 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
103 @speech_balloon.overwrite @panel.id
105 respond_to do |format|
106 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
107 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
108 format.html { redirect_to @panel }
109 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
111 flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
113 render @speech_balloon_template.engine_name + '/speech_balloons/new'
115 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
121 SpeechBalloon.fold_extend_settings params
122 @speech_balloon = SpeechBalloon.show(params[:id], @author)
123 @speech_balloon.attributes = params[:speech_balloon]
125 @speech_balloon_template = @speech_balloon.speech_balloon_template
126 @speech_balloon.boost
128 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
130 @panel = Panel.edit(@speech_balloon.panel.id, @author)
131 @speech_balloon.overwrite @panel.id
133 respond_to do |format|
134 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
135 flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
136 format.html { redirect_to @speech_balloon }
137 format.json { head :ok }
139 flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
141 render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
143 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
149 @speech_balloon = SpeechBalloon.show(params[:id], @author)
150 @panel = Panel.edit(@speech_balloon.panel.id, @author)
152 respond_to do |format|
153 if @speech_balloon.remove @author
154 flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
155 format.html { redirect_to @panel }
156 format.json { head :ok }
158 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
159 format.html { redirect_to @speech_balloon }
160 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }