OSDN Git Service

fix:balloon r
[pettanr/pettanr.git] / app / assets / javascripts / models / speech_balloon.js.coffee
index ecb19a8..359669a 100644 (file)
@@ -13,21 +13,50 @@ class Pettanr.SpeechBalloon extends Peta.Element
     t: null\r
   } \r
   \r
+  @pick_item_name: () ->\r
+    'speech_balloon_template'\r
+  \r
+  @traceable_item_names: () ->\r
+    ['speech', 'balloon']\r
+  \r
+  pick: () ->\r
+    # \r
+    speech_balloon_template = @templates.speech_balloon_template\r
+    {\r
+      speech_balloon_template_id: speech_balloon_template.get('id'),\r
+      speech_balloon_template_module_name: speech_balloon_template.get('module_name')\r
+    }\r
+  \r
   panel: () ->\r
-    new Pettanr.Panel({id: @get('panel_id')})\r
+    new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id'))\r
   \r
   speech_balloon_template: () ->\r
-    new Pettanr.SpeechBalloonTemplate({id: @get('speech_balloon_template_id')})\r
+    new Pettanr.Cache.Retriever(Pettanr.SpeechBalloonTemplate, @get('speech_balloon_template_id'))\r
   \r
   @has_picture: () ->\r
     false\r
   \r
-  symbol_option: (cb) ->\r
-    sbt = @speech_balloon_template()\r
-    sbt.fetch({cache: true}).done ->\r
-      sp = sbt.system_picture()\r
-      sp.fetch({cache: true}).done ->\r
-        cb(sp.tmb_opt_img_tag())\r
+  symbol_option: () ->\r
+    retriever = @speech_balloon_template()\r
+    @listenTo(retriever, 'retrieve', @retrieve_speech_balloon_template)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_speech_balloon_template: (speech_balloon_template) -> \r
+    retriever = speech_balloon_template.system_picture()\r
+    @listenTo(retriever, 'retrieve', @retrieve_system_picture)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_system_picture: (system_picture) -> \r
+    @trigger('ready:symbol', system_picture.tmb_opt_img_tag())\r
+  \r
+  filer_caption: () ->\r
+    retriever = @retriever()\r
+    @listenTo(retriever, 'retrieve', @retrieve_filer_caption)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_filer_caption: (item) -> \r
+    caption = item.escape('caption')\r
+    @trigger('ready:caption', caption)\r
   \r
   plain_scenario: () ->\r
     @get('caption')\r
@@ -35,11 +64,40 @@ class Pettanr.SpeechBalloon extends Peta.Element
   element_face: () ->\r
     new Pettanr.Views.SpeechBalloon.ElementFace({element: this})\r
   \r
-  initialize: () ->\r
+  initialize: (attr, options) ->\r
+    super(attr, options)\r
     if @id\r
       @url = @url + @id\r
   \r
-class Pettanr.SpeechBalloon.Collection extends Backbone.Collection\r
-  model: Pettanr.SpeechBalloon\r
-  url: '/speech_balloons/'\r
+class Pettanr.SpeechBalloon.TraceFromBalloon\r
+  \r
+  constructor: (options) ->\r
+    _.extend(this, Backbone.Events)\r
+  \r
+  trace: (balloon) ->\r
+    @balloon(balloon)\r
+  \r
+  balloon: (balloon) ->\r
+    retriever = new Pettanr.Cache.Retriever(Pettanr.SpeechBalloon, balloon.get('speech_balloon_id'))\r
+    @listenTo(retriever, 'retrieve', @speech_balloon)\r
+    retriever.retrieve()\r
+  \r
+  speech_balloon: (speech_balloon) ->\r
+    @trigger('trace', speech_balloon)\r
+  \r
+class Pettanr.SpeechBalloon.TraceFromSpeech\r
+  \r
+  constructor: (options) ->\r
+    _.extend(this, Backbone.Events)\r
+  \r
+  trace: (speech) ->\r
+    @speech(speech)\r
+  \r
+  speech: (speech) ->\r
+    retriever = new Pettanr.Cache.Retriever(Pettanr.SpeechBalloon, speech.get('speech_balloon_id'))\r
+    @listenTo(retriever, 'retrieve', @speech_balloon)\r
+    retriever.retrieve()\r
+  \r
+  speech_balloon: (speech_balloon) ->\r
+    @trigger('trace', speech_balloon)\r
   \r