OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / assets / javascripts / locmare / profiler / association / has_one.js.coffee
index c2108e9..0c6c6e0 100644 (file)
@@ -1,24 +1,40 @@
-class Locmare.ProfilerModule.AssociationModule.HasOne extends Backbone.View\r
+class Locmare.ProfilerModule.AssociationModule.HasOne extends Pettanr.View\r
   tagName: 'div'\r
   \r
   initialize: (options) ->\r
     @association = options.association\r
     @has_one_manifest = options.has_one_manifest\r
     @filer = null\r
-    m = new @parent_model(@parent_id())\r
-    m = new Pettanr.FilerCollection({}, @has_one_manifest.list_options(@item().get('id')))\r
-    _this = this\r
-    m.fetch().done ->\r
-      items = m.models\r
-      _this.filer = new Locmare.Filer(_this.has_one_model().item_name, items, null, _this.profiler().operators)\r
-      _this.render()\r
+    controller = Manifest.manifest().controllers[@has_one_manifest.controller_name]\r
+    action = controller.actions[@has_one_manifest.action_name]\r
+    @list = action.find({id: @item().get('id')})\r
+  \r
+  clear: () ->\r
+    this.$el.html('')\r
+    @list.open(this, {\r
+      success: (page_status) =>\r
+        @set_filer()\r
+        @render()\r
+      fail: (response, opt) =>\r
+        @open_error_dialog(response, opt)\r
+    })\r
+    this\r
   \r
   render: () ->\r
     this.$el.html('')\r
-    if @filer\r
-      this.$el.html(@filer.render().el)\r
+    this.$el.html(@filer.el)\r
     this\r
   \r
+  set_filer: () ->\r
+    @filer = new Locmare.Filer({\r
+      item_name: @has_one_model().item_name(), \r
+      items: @list.items(), \r
+      pager: @pager, \r
+    })\r
+    @filer.render()\r
+    @listenTo(@filer, 'http_get', @http_get)\r
+    @listenTo(@filer, 'pick', @pick)\r
+  \r
   item: () ->\r
     @profiler().item\r
   \r
@@ -28,3 +44,19 @@ class Locmare.ProfilerModule.AssociationModule.HasOne extends Backbone.View
   profiler: () ->\r
     @association.profiler\r
   \r
+  add_pick: (target_model) ->\r
+    @list.open(this, {\r
+      success: (page_status) =>\r
+        @set_filer()\r
+        @render()\r
+        @filer.add_pick(target_model)\r
+      fail: (response, opt) =>\r
+        @open_error_dialog(response, opt)\r
+    })\r
+  \r
+  http_get: (url) ->\r
+    @trigger('http_get', url)\r
+  \r
+  pick: (item) ->\r
+    @trigger('pick', item)\r
+  \r