OSDN Git Service

4a23494ab1eac78b8f619fdb3a3c4ff06df6d604
[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.LinkedEditButton extends Tag.A\r
66   \r
67   initialize: (options) ->\r
68     item = options.item\r
69     edit_url = Pettanr.url(item.table_name(), 'edit', {id: item.get('id')})\r
70     super({\r
71       attr: {href: '/' + edit_url}, \r
72       handler_name: edit_url,\r
73       content: I18n.t('link.edit')\r
74     })\r
75   \r
76 class Pettanr.Views.Show.LinkedDestroyButton extends Tag.A\r
77   \r
78   initialize: (options) ->\r
79     item = options.item\r
80     edit_url = Pettanr.url(item.table_name(), 'destroy', {id: item.get('id')})\r
81     super({\r
82       attr: {href: '/' + edit_url}, \r
83       handler_name: edit_url,\r
84       content: I18n.t('link.destroy')\r
85     })\r
86   \r
87 class Pettanr.Views.Show.OwnerFooter extends Backbone.View\r
88   tagName: 'div'\r
89   className: 'show-owner-footer'\r
90   \r
91   initialize: (options) ->\r
92     super(options)\r
93     @item = options.item\r
94     @operators = options.operators\r
95     @edit = new Pettanr.Views.Show.LinkedEditButton({item: @item})\r
96     @destroy = new Pettanr.Views.Show.LinkedDestroyButton({item: @item})\r
97   \r
98   render: () ->\r
99     this.$el.html('')\r
100     this.$el.append(@edit.render().el)\r
101     this.$el.append(@destroy.render().el)\r
102     this\r
103   \r
104 class Pettanr.Views.Show.Owner extends Backbone.View\r
105   tagName: 'div'\r
106   \r
107   initialize: (options) ->\r
108     super(options)\r
109     @item = options.item\r
110     @operators = options.operators\r
111     @header = new Tag.H3({\r
112       class_name: 'owner-header',\r
113       content: I18n.t('editor')\r
114     })\r
115     @footer = new Pettanr.Views.Show.OwnerFooter({item: @item, operators: @operators})\r
116   \r
117   render: () ->\r
118     this.$el.html('')\r
119     this.$el.append(@header.render().el)\r
120     this.$el.append(@footer.render().el)\r
121     this\r
122   \r