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 @item = SpeechBalloon.show(params[:id], [@user, @admin])
32 respond_to do |format|
33 format.html # show.html.erb
35 format.json { render json: @item.to_json(SpeechBalloon.show_json_opt) }
40 @speech_balloons = SpeechBalloon.all
42 respond_to do |format|
43 format.html { render layout: 'system' }
44 format.json { render json: @speech_balloons }
49 @speech_balloon = SpeechBalloon.find(params[:id])
51 respond_to do |format|
52 format.html { render layout: 'system' }
53 format.json { render json: @speech_balloon }
58 raise Pettanr::NotWork unless @author.working_panel
59 @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @author
61 @panel = Panel.edit(@author.working_panel, @author)
62 @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
64 @speech_balloon.supply_default
65 @speech_balloon.get_balloon.supply_default
66 @speech_balloon.get_speech.supply_default
68 respond_to do |format|
70 render @speech_balloon_template.engine_name + '/speech_balloons/new'
72 format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
77 @speech_balloon = SpeechBalloon.show(params[:id], @author)
78 @speech_balloon_template = @speech_balloon.speech_balloon_template
79 @panel = Panel.edit(@speech_balloon.panel.id, @author)
83 respond_to do |format|
85 render @speech_balloon_template.engine_name + '/speech_balloons/edit'
91 raise Pettanr::NotWork unless @author.working_panel
92 SpeechBalloon.fold_extend_settings params
93 @panel = Panel.edit(@author.working_panel, @author)
94 @speech_balloon = SpeechBalloon.new
95 @speech_balloon.attributes = params[:speech_balloon]
97 @speech_balloon_template = @speech_balloon.speech_balloon_template
100 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
102 @speech_balloon.overwrite @panel.id
104 respond_to do |format|
105 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
106 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
107 format.html { redirect_to @panel }
108 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
110 flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
112 render @speech_balloon_template.engine_name + '/speech_balloons/new'
114 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
120 SpeechBalloon.fold_extend_settings params
121 @speech_balloon = SpeechBalloon.show(params[:id], @author)
122 @speech_balloon.attributes = params[:speech_balloon]
124 @speech_balloon_template = @speech_balloon.speech_balloon_template
125 @speech_balloon.boost
127 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
129 @panel = Panel.edit(@speech_balloon.panel.id, @author)
130 @speech_balloon.overwrite @panel.id
132 respond_to do |format|
133 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
134 flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
135 format.html { redirect_to @speech_balloon }
136 format.json { head :ok }
138 flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
140 render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
142 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
148 @speech_balloon = SpeechBalloon.show(params[:id], @author)
149 @panel = Panel.edit(@speech_balloon.panel.id, @author)
151 respond_to do |format|
152 if @speech_balloon.remove @author
153 flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
154 format.html { redirect_to @panel }
155 format.json { head :ok }
157 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
158 format.html { redirect_to @speech_balloon }
159 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }