OSDN Git Service

add profiler
[pettanr/pettanr.git] / app / assets / javascripts / locmare / profiler / association / belongs_to.js.coffee
diff --git a/app/assets/javascripts/locmare/profiler/association/belongs_to.js.coffee b/app/assets/javascripts/locmare/profiler/association/belongs_to.js.coffee
new file mode 100644 (file)
index 0000000..2eeb697
--- /dev/null
@@ -0,0 +1,37 @@
+class Locmare.ProfilerModule.AssociationModule.BelongsTo extends Backbone.View\r
+  tagName: 'div'\r
+  \r
+  initialize: (options) ->\r
+    @association = options.association\r
+    @belongs_to_manifest = options.belongs_to_manifest\r
+    @filer = null\r
+    m = new @parent_model({id: @parent_id()})\r
+    _this = this\r
+    m.fetch().done ->\r
+      _this.filer = new Locmare.Filer(@parent_model.item_name, r, null, @profiler().operators)\r
+      _this.render()\r
+  \r
+  render: () ->\r
+    this.$el.html('')\r
+    if @filer\r
+      this.$el.html(@filer.render().el)\r
+    this\r
+  \r
+  item: () ->\r
+    @profiler.item\r
+  \r
+  parent_model: () ->\r
+    @belongs_to_manifest.model()\r
+  \r
+  parent_id: () ->\r
+    @item().get(@model_belongs_to_manifest().id_column)\r
+  \r
+  model_manifest: () ->\r
+    Manifest.manifest().models[@profiler.item_name]\r
+  \r
+  model_belongs_to_manifest: () ->\r
+    @model_manifest().associations.belongs_to[@belongs_to_manifest.model_name]\r
+  \r
+  profiler: () ->\r
+    @association.profiler()\r
+  \r