OSDN Git Service

fix sb engine
[pettanr/pettanr.git] / app / controllers / speech_balloons_controller.rb
index 13acc09..516aca5 100644 (file)
@@ -60,8 +60,13 @@ class SpeechBalloonsController < ApplicationController
     @speech = @speech_balloon.build_speech 
     @balloon.extend @speech_balloon_template.engine_balloon_module
     @speech.extend @speech_balloon_template.engine_speech_module
-    @balloon.supply_default @speech_balloon_template.parsed_settings
-    @speech.supply_default @speech_balloon_template.parsed_settings
+    @balloon.new_speech_balloon = @speech_balloon
+    @speech.new_speech_balloon = @speech_balloon
+    @balloon.supply_default 
+    @speech.supply_default 
+    @speech_balloon_extend = @speech_balloon.extend_speech_balloon
+    @balloon_extend = @balloon.extend_balloon
+    @speech_extend = @speech.extend_speech
     
     respond_to do |format|
       format.html {
@@ -90,33 +95,68 @@ class SpeechBalloonsController < ApplicationController
   end
 
   def create
-    @panel = Panel.edit(@author.working_panel, @author)
-    if params[:speech_balloon][:settings] and params[:speech_balloon][:settings].is_a?(Hash)
-      params[:speech_balloon][:settings] = params[:speech_balloon][:settings].to_json
+    speech_balloon_settings = params[:speech_balloon][:settings]
+    if speech_balloon_settings.blank?
+      speech_balloon_settings = {}
+    else
+      if speech_balloon_settings.is_a?(Hash)
+        params[:speech_balloon][:settings] = speech_balloon_settings.to_json
+      else
+        speech_balloon_settings = {}
+      end
     end
-    if params[:speech_balloon][:balloon_attributes][:settings] and params[:speech_balloon][:balloon_attributes][:settings].is_a?(Hash)
-      params[:speech_balloon][:balloon_attributes][:settings] = params[:speech_balloon][:balloon_attributes][:settings].to_json
+    balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
+    if balloon_settings.blank?
+      balloon_settings = {}
+    else
+      if balloon_settings.is_a?(Hash)
+        params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
+      else
+        balloon_settings = {}
+      end
     end
-    if params[:speech_balloon][:speech_attributes][:settings] and params[:speech_balloon][:speech_attributes][:settings].is_a?(Hash)
-      params[:speech_balloon][:speech_attributes][:settings] = params[:speech_balloon][:speech_attributes][:settings].to_json
+    speech_settings = params[:speech_balloon][:speech_attributes][:settings]
+    if speech_settings.blank?
+      speech_settings = {}
+    else
+      if speech_settings.is_a?(Hash)
+        params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
+      else
+        speech_settings = {}
+      end
     end
+    @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
     @balloon = @speech_balloon.balloon 
     @speech = @speech_balloon.speech 
+    
     @speech_balloon.extend @speech_balloon_template.engine_speech_balloon_module
     @balloon.extend @speech_balloon_template.engine_balloon_module
     @speech.extend @speech_balloon_template.engine_speech_module
+    
+    @balloon.new_speech_balloon = @speech_balloon
+    @speech.new_speech_balloon = @speech_balloon
+    
+    @speech_balloon.extend_speech_balloon = speech_balloon_settings
+    @balloon.extend_balloon = balloon_settings
+    @speech.extend_speech = speech_settings
+    
     @speech_balloon_extend = @speech_balloon.extend_speech_balloon
     @balloon_extend = @balloon.extend_balloon
     @speech_extend = @speech.extend_speech
     
+    params[:speech_balloon][:balloon_attributes][:system_picture_id] = @balloon.select_system_picture 
+    
     @speech_balloon.overwrite @panel.id
     
     respond_to do |format|
-      if @speech_balloon.valid? or @speech_balloon.extend_speech_balloon.valid? or @balloon.extend_balloon.valid? or @speech.extend_speech.valid? or @speech_balloon_extend.valid?
+      sbv = @speech_balloon_extend.valid?
+      bv = @balloon_extend.valid?
+      sv = @speech_extend.valid?
+      if @speech_balloon.valid? and @speech_balloon_extend.valid? and @balloon_extend.valid? and @speech_extend.valid? and sbv and bv and sv
         if @speech_balloon.store @author, params[:speech_balloon]
           flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
           format.html { redirect_to @panel }
@@ -189,7 +229,7 @@ class SpeechBalloonsController < ApplicationController
     @balloon_extend = @balloon.extend_balloon
     @speech_extend = @speech.extend_speech
     
-    @balloon.select_system_picture 
+    params[:speech_balloon][:balloon_attributes][:system_picture_id] = @balloon.select_system_picture 
     
     @panel = Panel.edit(@speech_balloon.panel.id, @author)
     @speech_balloon.overwrite @panel.id