OSDN Git Service

d4eaeee31b141f9ed7f770ae457fb18fc330317f
[pettanr/pettanr.git] / app / assets / javascripts / views / show.js.coffee
1 class Pettanr.Views.Show\r
2 class Pettanr.Views.Show.Header extends Backbone.View\r
3   tagName: 'h1'\r
4   className: 'show-header'\r
5   \r
6   initialize: (options) ->\r
7     @item = options.item\r
8     @operators = options.operators\r
9     @title = options.caption\r
10     @icon_url = options.icon_url\r
11     @caption_url = options.caption_url\r
12     @prof_url = options.prof_url\r
13     \r
14     @icon = new Pettanr.Image.Icon({item: @item, half: true})\r
15     @icon_button = new Tag.A({\r
16       attr: {href: '/' + @icon_url}, \r
17       handler_name: @icon_url,\r
18       class_name: 'icon',\r
19       content: @icon.render().el\r
20     })\r
21     @caption = new Tag.A({\r
22       attr: {href: '/' + @caption_url},\r
23       handler_name: @caption_url,\r
24       class_name: 'caption',\r
25       content: @title\r
26     })\r
27     @prof = new Pettanr.Image.SymbolImg({attr: {src: '/images/prof.gif'}, half: true})\r
28     @prof_button = new Tag.A({\r
29       attr: {href: '/' + @prof_url}, \r
30       handler_name: @prof_url,\r
31       class_name: 'prof',\r
32       content: @prof.render().el\r
33     })\r
34   \r
35   render: () ->\r
36     this.$el.html('')\r
37     this.$el.append(@icon_button.render().el)\r
38     this.$el.append(@caption.render().el)\r
39     this.$el.append(@prof_button.render().el)\r
40     this\r
41   \r
42 class Pettanr.Views.Show.HeaderAuthor extends Backbone.View\r
43   tagName: 'div'\r
44   \r
45   initialize: (options) ->\r
46     @item = options.item\r
47     _this = this\r
48     @author = @item.author()\r
49     @author.fetch({cache: true}).done ->\r
50       name = _this.author.get('name')\r
51       author_url = Pettanr.url(_this.author.table_name(), 'show', {id: _this.author.get('id')})\r
52       _this.linked_author =  new Tag.A({\r
53         attr: {href: '/' + author_url}, \r
54         handler_name: author_url,\r
55         content: name\r
56       })\r
57       _this.render()\r
58   \r
59   render: () ->\r
60     this.$el.html('')\r
61     this.$el.append(Pettanr.AppHelper.t_a(@item.item_name(), 'author_id'))\r
62     this.$el.append(@linked_author.render().el) if @linked_author\r
63     this\r
64   \r
65 class Pettanr.Views.Show.OwnerFooter extends Backbone.View\r
66   tagName: 'div'\r
67   className: 'show-owner-footer'\r
68   \r
69   initialize: (options) ->\r
70     super(options)\r
71     @item = options.item\r
72     @operators = options.operators\r
73     @edit_url = Pettanr.url(@item.table_name(), 'edit', {id: @item.get('id')})\r
74     @edit =  new Tag.A({\r
75       attr: {href: '/' + @edit_url}, \r
76       handler_name: @edit_url,\r
77       content: I18n.t('link.edit')\r
78     })\r
79     @destroy_url = Pettanr.url(@item.table_name(), 'destroy', {id: @item.get('id')})\r
80     @destroy =  new Tag.A({\r
81       attr: {href: '/' + @destroy_url}, \r
82       handler_name: @destroy_url,\r
83       content: I18n.t('link.destroy')\r
84     })\r
85   \r
86   render: () ->\r
87     this.$el.html('')\r
88     this.$el.append(@edit.render().el)\r
89     this.$el.append(@destroy.render().el)\r
90     this\r
91   \r
92 class Pettanr.Views.Show.Owner extends Backbone.View\r
93   tagName: 'div'\r
94   \r
95   initialize: (options) ->\r
96     super(options)\r
97     @item = options.item\r
98     @operators = options.operators\r
99     @header = new Tag.H3({\r
100       class_name: 'owner-header',\r
101       content: I18n.t('editor')\r
102     })\r
103     @footer = new Pettanr.Views.Show.OwnerFooter({item: @item, operators: @operators})\r
104   \r
105   render: () ->\r
106     this.$el.html('')\r
107     this.$el.append(@header.render().el)\r
108     this.$el.append(@footer.render().el)\r
109     this\r
110   \r