OSDN Git Service

fix summary
[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     @length = options.length\r
27     @name = Pettanr.truncate(@item.get('name'), @length)\r
28     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
29     @linked_name = new Tag.A({\r
30       attr: {href: '/' + @url}, \r
31       handler_name: @url,\r
32       content: @name\r
33     })\r
34   \r
35   render: () ->\r
36     this.$el.html(@linked_name.render().el)\r
37     this\r
38   \r
39 class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
40   tagName: 'span'\r
41   \r
42   initialize: (options) ->\r
43     @item = options.item\r
44     @column = options.column\r
45     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
46     @caption = new Pettanr.Views.Common.Caption({item: @item, column: @column, length: @length})\r
47   \r
48   render: () ->\r
49     this.$el.html('')\r
50     this.$el.append(@icon.render().el)\r
51     this.$el.append(@caption.render().el)\r
52     this\r
53   \r