OSDN Git Service

e9e5790e439460b0513bce27d0cfcc4c83ebc1a4
[pettanr/pettanr.git] / app / assets / javascripts / locmare / profiler / association / has_one.js.coffee
1 class Locmare.ProfilerModule.AssociationModule.HasOne extends Pettanr.View\r
2   tagName: 'div'\r
3   \r
4   initialize: (options) ->\r
5     @association = options.association\r
6     @has_one_manifest = options.has_one_manifest\r
7     @filer = null\r
8     controller = Manifest.manifest().controllers[@has_one_manifest.controller_name]\r
9     action = controller.actions[@has_one_manifest.action_name]\r
10     @list = action.find({id: @item().get('id')})\r
11   \r
12   clear: () ->\r
13     this.$el.html('')\r
14     @list.open(this, {\r
15       success: (page_status) =>\r
16         @set_filer()\r
17         @render()\r
18     })\r
19     this\r
20   \r
21   render: () ->\r
22     this.$el.html('')\r
23     this.$el.html(@filer.el)\r
24     this\r
25   \r
26   set_filer: () ->\r
27     @filer = new Locmare.Filer({\r
28       item_name: @has_one_model().item_name(), \r
29       items: @list.items(), \r
30       pager: @pager, \r
31     })\r
32     @filer.render()\r
33     @listenTo(@filer, 'http_get', @http_get)\r
34     @listenTo(@filer, 'pick', @pick)\r
35   \r
36   item: () ->\r
37     @profiler().item\r
38   \r
39   has_one_model: () ->\r
40     @has_one_manifest.model()\r
41   \r
42   profiler: () ->\r
43     @association.profiler\r
44   \r
45   add_pick: (target_model) ->\r
46     @list.open((page_status) =>\r
47       @set_filer()\r
48       @render()\r
49       @filer.add_pick(target_model)\r
50     )\r
51   \r
52   http_get: (url) ->\r
53     @trigger('http_get', url)\r
54   \r
55   pick: (item) ->\r
56     @trigger('pick', item)\r
57   \r