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|
34 @speech_balloon = @item
37 format.json { render json: @item.to_json(SpeechBalloon.show_json_opt) }
42 @speech_balloons = SpeechBalloon.all
44 respond_to do |format|
45 format.html { render layout: 'system' }
46 format.json { render json: @speech_balloons }
51 @speech_balloon = SpeechBalloon.find(params[:id])
53 respond_to do |format|
54 format.html { render layout: 'system' }
55 format.json { render json: @speech_balloon }
60 raise Pettanr::NotWork unless @author.working_panel
61 @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @author
63 @panel = Panel.edit(@author.working_panel, @author)
64 @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
66 @speech_balloon.supply_default
67 @speech_balloon.get_balloon.supply_default
68 @speech_balloon.get_speech.supply_default
70 respond_to do |format|
72 render @speech_balloon_template.engine_name + '/speech_balloons/new'
74 format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) }
79 @speech_balloon = SpeechBalloon.show(params[:id], @author)
80 @speech_balloon_template = @speech_balloon.speech_balloon_template
81 @panel = Panel.edit(@speech_balloon.panel.id, @author)
85 respond_to do |format|
87 render @speech_balloon_template.engine_name + '/speech_balloons/edit'
93 raise Pettanr::NotWork unless @author.working_panel
94 SpeechBalloon.fold_extend_settings params
95 @panel = Panel.edit(@author.working_panel, @author)
96 @speech_balloon = SpeechBalloon.new
97 @speech_balloon.attributes = params[:speech_balloon]
99 @speech_balloon_template = @speech_balloon.speech_balloon_template
100 @speech_balloon.boost
102 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
104 @speech_balloon.overwrite @panel.id
106 respond_to do |format|
107 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
108 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
109 format.html { redirect_to @panel }
110 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
112 flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
114 render @speech_balloon_template.engine_name + '/speech_balloons/new'
116 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
122 SpeechBalloon.fold_extend_settings params
123 @speech_balloon = SpeechBalloon.show(params[:id], @author)
124 @speech_balloon.attributes = params[:speech_balloon]
126 @speech_balloon_template = @speech_balloon.speech_balloon_template
127 @speech_balloon.boost
129 params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture
131 @panel = Panel.edit(@speech_balloon.panel.id, @author)
132 @speech_balloon.overwrite @panel.id
134 respond_to do |format|
135 if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon])
136 flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
137 format.html { redirect_to @speech_balloon }
138 format.json { head :ok }
140 flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
142 render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
144 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
150 @speech_balloon = SpeechBalloon.show(params[:id], @author)
151 @panel = Panel.edit(@speech_balloon.panel.id, @author)
153 respond_to do |format|
154 if @speech_balloon.remove @author
155 flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
156 format.html { redirect_to @panel }
157 format.json { head :ok }
159 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
160 format.html { redirect_to @speech_balloon }
161 format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }