OSDN Git Service

fix:balloon r
[pettanr/pettanr.git] / app / assets / javascripts / models / balloon.js.coffee
index 48c95de..f50e03b 100644 (file)
@@ -16,26 +16,43 @@ class Pettanr.Balloon extends Peta.Element
     r: 0\r
   } \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
   speech_balloon: () ->\r
-    new Pettanr.SpeechBalloon({id: @get('speech_balloon_id')})\r
+    new Pettanr.Cache.Retriever(Pettanr.SpeechBalloon, @get('speech_balloon_id'))\r
   \r
   system_picture: () ->\r
-    new Pettanr.SystemPicture({id: @get('system_picture_id')})\r
+    new Pettanr.Cache.Retriever(Pettanr.SystemPicture, @get('system_picture_id'))\r
   \r
   r_url: () ->\r
     '/system_pictures/' + @system_picture().filename()\r
   \r
   symbol_option: () ->\r
-    sb = @speech_balloon()\r
-    sb.fetch({cache: true}).done =>\r
-      sbt = sb.speech_balloon_template()\r
-      sbt.fetch({cache: true}).done =>\r
-        sp = sbt.system_picture()\r
-        sp.fetch({cache: true}).done =>\r
-          @symbol_picture = sp.tmb_opt_img_tag()\r
-          @trigger('ready:symbol')\r
-  \r
-  initialize: () ->\r
+    retriever = @speech_balloon()\r
+    @listenTo(retriever, 'retrieve', @retrieve_speech_balloon)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_speech_balloon: (speech_balloon) -> \r
+    retriever = speech_balloon.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
+  initialize: (attr, options) ->\r
+    super(attr, options)\r
     if @id\r
       @url = @url + @id\r
     @bind('change:width', () ->\r