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.json { render json: @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
35 @speech_balloons = SpeechBalloon.all
37 respond_to do |format|
38 format.html { render layout: 'system' }
39 format.json { render json: @speech_balloons }
44 @speech_balloon = SpeechBalloon.find(params[:id])
46 respond_to do |format|
47 format.html { render layout: 'system' }
48 format.json { render json: @speech_balloon }
53 @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @author
55 @panel = Panel.edit(@author.working_panel, @author)
56 @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
58 @speech_balloon.supply_default
59 @speech_balloon.get_balloon.supply_default
60 @speech_balloon.get_speech.supply_default
62 respond_to do |format|
64 render @speech_balloon_template.engine_name + '/speech_balloons/new'
66 format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
71 @speech_balloon = SpeechBalloon.show(params[:id], @author)
72 @speech_balloon_template = @speech_balloon.speech_balloon_template
73 @panel = Panel.edit(@speech_balloon.panel.id, @author)
77 respond_to do |format|
79 render @speech_balloon_template.engine_name + '/speech_balloons/edit'
85 SpeechBalloon.fold_extend_settings params
86 @panel = Panel.edit(@author.working_panel, @author)
87 @speech_balloon = SpeechBalloon.new
88 @speech_balloon.attributes = params[:speech_balloon]
90 @speech_balloon_template = @speech_balloon.speech_balloon_template
93 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
95 @speech_balloon.overwrite @panel.id
97 respond_to do |format|
98 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
99 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
100 format.html { redirect_to @panel }
101 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
103 flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
105 render @speech_balloon_template.engine_name + '/speech_balloons/new'
107 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
113 SpeechBalloon.fold_extend_settings params
114 @speech_balloon = SpeechBalloon.show(params[:id], @author)
115 @speech_balloon.attributes = params[:speech_balloon]
117 @speech_balloon_template = @speech_balloon.speech_balloon_template
118 @speech_balloon.boost
120 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
122 @panel = Panel.edit(@speech_balloon.panel.id, @author)
123 @speech_balloon.overwrite @panel.id
125 respond_to do |format|
126 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
127 flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
128 format.html { redirect_to @speech_balloon }
129 format.json { head :ok }
131 flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
133 render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
135 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
141 @speech_balloon = SpeechBalloon.show(params[:id], @author)
142 @panel = Panel.edit(@speech_balloon.panel.id, @author)
144 respond_to do |format|
145 if @speech_balloon.remove @author
146 flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
147 format.html { redirect_to @panel }
148 format.json { head :ok }
150 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
151 format.html { redirect_to @speech_balloon }
152 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }