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.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.EmptyCaption extends Backbone.View\r
21   tagName: 'div'\r
22   className: 'empty'\r
23   \r
24   render: () ->\r
25     this.$el.html('empty')\r
26     this\r
27   \r
28 class Pettanr.Views.Common.Icon extends Backbone.View\r
29   tagName: 'span'\r
30   \r
31   initialize: (options) ->\r
32     @item = options.item\r
33     @half = options.half\r
34     @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
35     @icon = new Pettanr.Image.Icon({item: @item, half: @half})\r
36     @icon_button = new Tag.A({\r
37       attr: {href: '/' + @icon_url}, \r
38       handler_name: @icon_url,\r
39       class_name: 'icon',\r
40       content: @icon.render().el\r
41     })\r
42   \r
43   render: () ->\r
44     this.$el.html(@icon_button.render().el)\r
45     this\r
46   \r
47 class Pettanr.Views.Common.Caption extends Backbone.View\r
48   tagName: 'span'\r
49   \r
50   initialize: (options) ->\r
51     @item = options.item\r
52     @column_name = options.column_name\r
53     @length = options.length\r
54     @name = Pettanr.truncate(@item.get(@column_name), @length)\r
55     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
56     @linked_name = new Tag.A({\r
57       attr: {href: '/' + @url}, \r
58       handler_name: @url,\r
59       content: _.escape(@name)\r
60     })\r
61   \r
62   render: () ->\r
63     this.$el.html(@linked_name.render().el)\r
64     this\r
65   \r
66 class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
67   tagName: 'span'\r
68   \r
69   initialize: (options) ->\r
70     @item = options.item\r
71     @half = options.half\r
72     @column_name = options.column_name\r
73     @length = options.length\r
74     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
75     @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})\r
76   \r
77   render: () ->\r
78     this.$el.html('')\r
79     this.$el.append(@icon.render().el)\r
80     this.$el.append(@caption.render().el)\r
81     this\r
82   \r
83 class Pettanr.Views.Common.Summary extends Backbone.View\r
84   \r
85   initialize: (options) ->\r
86     @clear()\r
87     @listenTo(this, 'ready', @render)\r
88   \r
89   clear: () ->\r
90     icon = new Pettanr.Views.Common.LoadIcon()\r
91     this.$el.html(icon.render().el)\r
92     this\r
93   \r
94   render: () ->\r
95     this.$el.html('')\r
96     this\r
97   \r
98 class Pettanr.Views.Common.Binder\r
99 class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary\r
100   \r
101   initialize: (options) ->\r
102     super(options)\r
103     @item = options.item\r
104     @visible_t = options.visible_t\r
105     @visible_column_name = options.visible_column_name\r
106     @load()\r
107   \r
108   load: () ->\r
109     @visible = new Tag.Div({\r
110       content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
111     })\r
112     @author = @item.author()\r
113     @author.fetch({cache: true}).done =>\r
114       @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
115       @trigger('ready')\r
116   \r
117   render: () ->\r
118     this.$el.html('')\r
119     this.$el.append(@visible.render().el)\r
120     this.$el.append(@author_icon_with_caption.render().el)\r
121     this\r
122   \r
123 class Pettanr.Views.Common.Leaf\r
124 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary\r
125   \r
126   initialize: (options) ->\r
127     super(options)\r
128     @item = options.item\r
129     @binder_item_name = options.binder_item_name\r
130     @destination_item_name = options.destination_item_name\r
131     @load()\r
132   \r
133   load: () ->\r
134     @binder = @item[@binder_item_name]()\r
135     @binder.fetch({cache: true}).done =>\r
136       @binder_icon = @binder.icon_view(true)\r
137       @binder_author = @binder.author()\r
138       @binder_author.fetch({cache: true}).done =>\r
139         @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
140         @trigger('ready')\r
141     @destination = @item[@destination_item_name]()\r
142     @destination.fetch({cache: true}).done =>\r
143       @destination_icon = @destination.icon_view(true)\r
144       @destination_author = @destination.author()\r
145       @destination_author.fetch({cache: true}).done =>\r
146         @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
147         @trigger('ready')\r
148   \r
149   render: () ->\r
150     this.$el.html('')\r
151     if @binder_author_icon_with_caption\r
152       this.$el.append(@binder_icon.render().el)\r
153       this.$el.append(@binder_author_icon_with_caption.render().el)\r
154     if @destination_author_icon_with_caption\r
155       this.$el.append(@destination_icon.render().el)\r
156       this.$el.append(@destination_author_icon_with_caption.render().el)\r
157     this\r
158   \r