OSDN Git Service

fix:new elm
[pettanr/pettanr.git] / app / assets / javascripts / views / speech_balloons / new_element.js.coffee
index 351ab8c..c3a7455 100644 (file)
@@ -25,8 +25,26 @@ class Pettanr.Views.SpeechBalloon.NewElement extends Backbone.View
     @listenTo(this, 'ready', @ready)\r
     if item.item_name() == @target_model.item_name()\r
       # Inspire\r
-      new_item = new @target_model(item.attributes)\r
-      @trigger('ready', new_item)\r
+      balloon_list = item.has_one('balloon')\r
+      speech_list = item.has_one('speech')\r
+      balloon_list.open(() =>\r
+        balloon = balloon_list.items()[0]\r
+        speech_list.open(() =>\r
+          speech = speech_list.items()[0]\r
+          new_item = new @target_model(item.attributes)\r
+          new_item.unset('id', {silent: true})\r
+          new_item.set({panel_id: @editor().item.get('id')}, {silent: true})\r
+          balloon.unset('id', {silent: true})\r
+          balloon.unset('speech_balloon_id', {silent: true})\r
+          speech.unset('id', {silent: true})\r
+          speech.unset('speech_balloon_id', {silent: true})\r
+          new_item.boosts 'post'\r
+          balloon.boosts 'post'\r
+          speech.boosts 'post'\r
+          new_item.set({balloon: balloon, speech: speech}, {silent: true})\r
+          @trigger('ready', new_item)\r
+        )\r
+      )\r
     else if @target_model.is_traceable(item.item_name())\r
       # Trace\r
       n = @target_model['trace_from_' + item.item_name()]\r