X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fspeech_balloons_controller.rb;h=bc5aea82b212501f28ec314975a354389be25d63;hb=9f5258607f0be5c8c6f4f8f9efb85ec462f33b68;hp=543c4c3118ed252d1acb846c7b3f3b4f61da0669;hpb=6871c7b0c1a7a02d4fe3b8ff597f3978e4df7f89;p=pettanr%2Fpettanr.git diff --git a/app/controllers/speech_balloons_controller.rb b/app/controllers/speech_balloons_controller.rb index 543c4c31..bc5aea82 100644 --- a/app/controllers/speech_balloons_controller.rb +++ b/app/controllers/speech_balloons_controller.rb @@ -1,10 +1,12 @@ class SpeechBalloonsController < ApplicationController layout 'test' if MagicNumber['test_layout'] if MagicNumber['run_mode'] == 0 - before_filter :authenticate_user, :only => [] + before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] else before_filter :authenticate_reader, :only => [:index, :show] - before_filter :authenticate_user, :only => [] + before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] end before_filter :authenticate_admin!, :only => [:list, :browse] @@ -14,13 +16,15 @@ class SpeechBalloonsController < ApplicationController @speech_balloons = SpeechBalloon.list(@page, @page_size) respond_to do |format| - format.html # index.html.erb + format.html { + @paginate = SpeechBalloon.list_paginate(@page, @page_size) + } format.json { render json: @speech_balloons.to_json(SpeechBalloon.list_json_opt) } end end def show - @speech_balloon = SpeechBalloon.show(params[:id], @author) + @speech_balloon = SpeechBalloon.show(params[:id], [@user, @admin]) respond_to do |format| format.html # show.html.erb format.json { render json: @speech_balloon.to_json(SpeechBalloon.show_json_opt) } @@ -45,4 +49,111 @@ class SpeechBalloonsController < ApplicationController end end + def new + raise Pettanr::NotWork unless @author.working_panel + @speech_balloon_template = SpeechBalloonTemplate.show params[:speech_balloon_template_id], @author + + @panel = Panel.edit(@author.working_panel, @author) + @speech_balloon = SpeechBalloon.new :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech_balloon.boost + @speech_balloon.supply_default + @speech_balloon.get_balloon.supply_default + @speech_balloon.get_speech.supply_default + + respond_to do |format| + format.html { + render @speech_balloon_template.engine_name + '/speech_balloons/new' + } + format.json { render :json => @speech_balloon.to_json(SpeechBalloon.show_json_opt) } + end + end + + def edit + @speech_balloon = SpeechBalloon.show(params[:id], @author) + @speech_balloon_template = @speech_balloon.speech_balloon_template + @panel = Panel.edit(@speech_balloon.panel.id, @author) + + @speech_balloon.boost + + respond_to do |format| + format.html { + render @speech_balloon_template.engine_name + '/speech_balloons/edit' + } + end + end + + def create + raise Pettanr::NotWork unless @author.working_panel + SpeechBalloon.fold_extend_settings params + @panel = Panel.edit(@author.working_panel, @author) + @speech_balloon = SpeechBalloon.new + @speech_balloon.attributes = params[:speech_balloon] + + @speech_balloon_template = @speech_balloon.speech_balloon_template + @speech_balloon.boost + + params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture + + @speech_balloon.overwrite @panel.id + + respond_to do |format| + if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon]) + flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human) + format.html { redirect_to @panel } + format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel } + else + flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human) + format.html { + render @speech_balloon_template.engine_name + '/speech_balloons/new' + } + format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } + end + end + end + + def update + SpeechBalloon.fold_extend_settings params + @speech_balloon = SpeechBalloon.show(params[:id], @author) + @speech_balloon.attributes = params[:speech_balloon] + + @speech_balloon_template = @speech_balloon.speech_balloon_template + @speech_balloon.boost + + params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture + + @panel = Panel.edit(@speech_balloon.panel.id, @author) + @speech_balloon.overwrite @panel.id + + respond_to do |format| + if @speech_balloon.valid? and @speech_balloon.store(@author, params[:speech_balloon]) + flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human) + format.html { redirect_to @speech_balloon } + format.json { head :ok } + else + flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human) + format.html { + render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit' + } + format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @speech_balloon = SpeechBalloon.show(params[:id], @author) + @panel = Panel.edit(@speech_balloon.panel.id, @author) + + respond_to do |format| + if @speech_balloon.remove @author + flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human) + format.html { redirect_to @panel } + format.json { head :ok } + else + flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human) + format.html { redirect_to @speech_balloon } + format.json { render json: @speech_balloon.errors, status: :unprocessable_entity } + end + end + end + end