OSDN Git Service

bec019a76c3970967cff964909ad9bbba3c89c13
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
1 class Pettanr.Views.Common\r
2 class Pettanr.Views.Common.Icon extends Backbone.View\r
3   tagName: 'span'\r
4   \r
5   initialize: (options) ->\r
6     @item = options.item\r
7     @half = options.half\r
8     @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
9     @icon = new Pettanr.Image.Icon({item: @item, half: @half})\r
10     @icon_button = new Tag.A({\r
11       attr: {href: '/' + @icon_url}, \r
12       handler_name: @icon_url,\r
13       class_name: 'icon',\r
14       content: @icon.render().el\r
15     })\r
16   \r
17   render: () ->\r
18     this.$el.html(@icon_button.render().el)\r
19     this\r
20   \r
21 class Pettanr.Views.Common.Caption extends Backbone.View\r
22   tagName: 'span'\r
23   \r
24   initialize: (options) ->\r
25     @item = options.item\r
26     @column_name = options.column_name\r
27     @length = options.length\r
28     @name = Pettanr.truncate(@item.get(@column_name), @length)\r
29     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
30     @linked_name = new Tag.A({\r
31       attr: {href: '/' + @url}, \r
32       handler_name: @url,\r
33       content: @name\r
34     })\r
35   \r
36   render: () ->\r
37     this.$el.html(@linked_name.render().el)\r
38     this\r
39   \r
40 class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
41   tagName: 'span'\r
42   \r
43   initialize: (options) ->\r
44     @item = options.item\r
45     @half = options.half\r
46     @column_name = options.column_name\r
47     @length = options.length\r
48     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
49     @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})\r
50   \r
51   render: () ->\r
52     this.$el.html('')\r
53     this.$el.append(@icon.render().el)\r
54     this.$el.append(@caption.render().el)\r
55     this\r
56   \r
57 class Pettanr.Views.Common.Binder\r
58 class Pettanr.Views.Common.Binder.Summary extends Backbone.View\r
59   \r
60   initialize: (options) ->\r
61     @item = options.item\r
62     @visible_t = options.visible_t\r
63     @visible_column_name = options.visible_column_name\r
64     @visible = new Tag.Div({\r
65       content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
66     })\r
67     @author = @item.author()\r
68     @author.fetch({cache: true}).done =>\r
69       @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
70       @render()\r
71   \r
72   render: () ->\r
73     this.$el.html('')\r
74     this.$el.append(@visible.render().el)\r
75     if @author_icon_with_caption\r
76       this.$el.append(@author_icon_with_caption.render().el)\r
77     this\r
78   \r
79 class Pettanr.Views.Common.Leaf\r
80 class Pettanr.Views.Common.Leaf.Summary extends Backbone.View\r
81   \r
82   initialize: (options) ->\r
83     @item = options.item\r
84     @binder_item_name = options.binder_item_name\r
85     @destination_item_name = options.destination_item_name\r
86     @binder = @item[@binder_item_name]()\r
87     @binder.fetch({cache: true}).done =>\r
88       @binder_icon = @binder.icon_view(true)\r
89       @binder_author = @binder.author()\r
90       @binder_author.fetch({cache: true}).done =>\r
91         @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
92         @render()\r
93     @destination = @item[@destination_item_name]()\r
94     @destination.fetch({cache: true}).done =>\r
95       @destination_icon = @destination.icon_view(true)\r
96       @destination_author = @destination.author()\r
97       @destination_author.fetch({cache: true}).done =>\r
98         @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
99         @render()\r
100   \r
101   render: () ->\r
102     this.$el.html('')\r
103     if @binder_author_icon_with_caption and @destination_author_icon_with_caption\r
104       this.$el.append(@binder_icon.render().el)\r
105       this.$el.append(@binder_author_icon_with_caption.render().el)\r
106       this.$el.append(@destination_icon.render().el)\r
107       this.$el.append(@destination_author_icon_with_caption.render().el)\r
108     this\r
109   \r