OSDN Git Service

v07
[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       fail: (response, opt) =>\r
19         @open_error_dialog(response, opt)\r
20     })\r
21     this\r
22   \r
23   render: () ->\r
24     this.$el.html('')\r
25     this.$el.html(@filer.el)\r
26     this\r
27   \r
28   set_filer: () ->\r
29     @filer = new Locmare.Filer({\r
30       item_name: @has_one_model().item_name(), \r
31       items: @list.items(), \r
32       pager: @pager, \r
33     })\r
34     @filer.render()\r
35     @listenTo(@filer, 'http_get', @http_get)\r
36     @listenTo(@filer, 'pick', @pick)\r
37   \r
38   item: () ->\r
39     @profiler().item\r
40   \r
41   has_one_model: () ->\r
42     @has_one_manifest.model()\r
43   \r
44   profiler: () ->\r
45     @association.profiler\r
46   \r
47   add_pick: (target_model) ->\r
48     @list.open(this, {\r
49       success: (page_status) =>\r
50         @set_filer()\r
51         @render()\r
52         @filer.add_pick(target_model)\r
53       fail: (response, opt) =>\r
54         @open_error_dialog(response, opt)\r
55     })\r
56   \r
57   http_get: (url) ->\r
58     @trigger('http_get', url)\r
59   \r
60   pick: (item) ->\r
61     @trigger('pick', item)\r
62   \r