OSDN Git Service

a283bdff8f28c7631df12e876edc8bbb374bb8f9
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
1 class Pettanr.Views.Common\r
2 class Pettanr.Views.Common.LoadIcon extends Tag.Img\r
3   \r
4   initialize: () ->\r
5     @attr = {}\r
6     @width = Manifest.manifest().magic_numbers['thumbnail_width']\r
7     @height = Manifest.manifest().magic_numbers['thumbnail_height']\r
8     @width = Pettanr.to_i(@width/2)\r
9     @height = Pettanr.to_i(@height/2)\r
10     @attr['src'] = '/images/loading.gif'\r
11     @attr['width'] = @width\r
12     @attr['height'] = @height\r
13     @attr['alt'] = 'Loading'\r
14     @attr['title'] = 'Loading'\r
15     opt = {\r
16       attr: @attr,\r
17     }\r
18     super(opt)\r
19 \r
20 class Pettanr.Views.Common.Icon extends Backbone.View\r
21   tagName: 'span'\r
22   \r
23   initialize: (options) ->\r
24     @item = options.item\r
25     @half = options.half\r
26     @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
27     @icon = new Pettanr.Image.Icon({item: @item, half: @half})\r
28     @icon_button = new Tag.A({\r
29       attr: {href: '/' + @icon_url}, \r
30       handler_name: @icon_url,\r
31       class_name: 'icon',\r
32       content: @icon.render().el\r
33     })\r
34   \r
35   render: () ->\r
36     this.$el.html(@icon_button.render().el)\r
37     this\r
38   \r
39 class Pettanr.Views.Common.Caption extends Backbone.View\r
40   tagName: 'span'\r
41   \r
42   initialize: (options) ->\r
43     @item = options.item\r
44     @column_name = options.column_name\r
45     @length = options.length\r
46     @name = Pettanr.truncate(@item.get(@column_name), @length)\r
47     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
48     @linked_name = new Tag.A({\r
49       attr: {href: '/' + @url}, \r
50       handler_name: @url,\r
51       content: _.escape(@name)\r
52     })\r
53   \r
54   render: () ->\r
55     this.$el.html(@linked_name.render().el)\r
56     this\r
57   \r
58 class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
59   tagName: 'span'\r
60   \r
61   initialize: (options) ->\r
62     @item = options.item\r
63     @half = options.half\r
64     @column_name = options.column_name\r
65     @length = options.length\r
66     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
67     @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})\r
68   \r
69   render: () ->\r
70     this.$el.html('')\r
71     this.$el.append(@icon.render().el)\r
72     this.$el.append(@caption.render().el)\r
73     this\r
74   \r
75 class Pettanr.Views.Common.Summary extends Backbone.View\r
76   \r
77   initialize: (options) ->\r
78     @clear()\r
79     @listenTo(this, 'ready', @render)\r
80   \r
81   clear: () ->\r
82     icon = new Pettanr.Views.Common.LoadIcon()\r
83     this.$el.html(icon.render().el)\r
84     this\r
85   \r
86   render: () ->\r
87     this.$el.html('')\r
88     this\r
89   \r
90 class Pettanr.Views.Common.Binder\r
91 class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary\r
92   \r
93   initialize: (options) ->\r
94     super(options)\r
95     @item = options.item\r
96     @visible_t = options.visible_t\r
97     @visible_column_name = options.visible_column_name\r
98     @load()\r
99   \r
100   load: () ->\r
101     @visible = new Tag.Div({\r
102       content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
103     })\r
104     @author = @item.author()\r
105     @author.fetch({cache: true}).done =>\r
106       @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
107       @trigger('ready')\r
108   \r
109   render: () ->\r
110     this.$el.html('')\r
111     this.$el.append(@visible.render().el)\r
112     this.$el.append(@author_icon_with_caption.render().el)\r
113     this\r
114   \r
115 class Pettanr.Views.Common.Leaf\r
116 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary\r
117   \r
118   initialize: (options) ->\r
119     super(options)\r
120     @item = options.item\r
121     @binder_item_name = options.binder_item_name\r
122     @destination_item_name = options.destination_item_name\r
123     @load()\r
124   \r
125   load: () ->\r
126     @binder = @item[@binder_item_name]()\r
127     @binder.fetch({cache: true}).done =>\r
128       @binder_icon = @binder.icon_view(true)\r
129       @binder_author = @binder.author()\r
130       @binder_author.fetch({cache: true}).done =>\r
131         @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
132         @trigger('ready')\r
133     @destination = @item[@destination_item_name]()\r
134     @destination.fetch({cache: true}).done =>\r
135       @destination_icon = @destination.icon_view(true)\r
136       @destination_author = @destination.author()\r
137       @destination_author.fetch({cache: true}).done =>\r
138         @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
139         @trigger('ready')\r
140   \r
141   render: () ->\r
142     this.$el.html('')\r
143     if @binder_author_icon_with_caption\r
144       this.$el.append(@binder_icon.render().el)\r
145       this.$el.append(@binder_author_icon_with_caption.render().el)\r
146     if @destination_author_icon_with_caption\r
147       this.$el.append(@destination_icon.render().el)\r
148       this.$el.append(@destination_author_icon_with_caption.render().el)\r
149     this\r
150   \r