OSDN Git Service

fix: show's destroy button
[pettanr/pettanr.git] / app / assets / javascripts / models / balloon.js.coffee
index 48fb028..d4a5040 100644 (file)
@@ -1,5 +1,4 @@
 class Pettanr.Balloon extends Peta.Element\r
-  url: '/balloons/'\r
   \r
   @singular: () ->\r
     'Balloon'\r
@@ -16,26 +15,41 @@ 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.Cache.Retriever(Pettanr.SystemPicture, @get('system_picture_id'))\r
   \r
   r_url: () ->\r
     '/system_pictures/' + @system_picture().filename()\r
   \r
-  symbol_option: (cb) ->\r
-    sb = @speech_balloon()\r
-    sb.fetch().done ->\r
-      sbt = sb.speech_balloon_template()\r
-      sbt.fetch().done ->\r
-        sp = sbt.system_picture()\r
-        sp.fetch().done ->\r
-          cb(sp.tmb_opt_img_tag())\r
-  \r
-  initialize: () ->\r
-    if @id\r
-      @url = @url + @id\r
-  \r
-class Pettanr.Balloon.Collection extends Backbone.Collection\r
-  model: Pettanr.Balloon\r
-  url: '/balloons'\r
-\r
+  symbol_option: () ->\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
+  \r