OSDN Git Service

69160ac91128e8d4e5b3a7db9a9b54fb894acc84
[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       class_name: 'icon',\r
18       content: @icon.render().el\r
19     })\r
20     @caption = new Tag.A({\r
21       attr: {href: '/' + @caption_url},\r
22       class_name: 'caption',\r
23       content: _.escape(@title)\r
24     })\r
25     @prof = new Pettanr.Image.SymbolImg({attr: {src: '/images/prof.gif'}, half: true})\r
26     @prof_button = new Tag.A({\r
27       attr: {href: '/' + @prof_url}, \r
28       class_name: 'prof',\r
29       content: @prof.render().el\r
30     })\r
31     @listenTo(@icon, 'click', @click_icon)\r
32     @listenTo(@caption, 'click', @click_caption)\r
33     @listenTo(@prof_button, 'click', @click_prof)\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   click_icon: () ->\r
43     @trigger('click:icon')\r
44   \r
45   click_caption: () ->\r
46     @trigger('click:caption')\r
47   \r
48   click_prof: () ->\r
49     @trigger('click:prof')\r
50   \r
51 class Pettanr.Views.Show.HeaderAuthor extends Backbone.View\r
52   tagName: 'div'\r
53   \r
54   initialize: (options) ->\r
55     @item = options.item\r
56     @author = @item.author()\r
57     @author.fetch({cache: true}).done =>\r
58       name = @author.escape('name')\r
59       author_url = @author.show_url()\r
60       @linked_author =  new Tag.A({\r
61         attr: {href: '/' + author_url}, \r
62         content: name\r
63       })\r
64       @listenTo(@linked_author, 'click', @click)\r
65       @render()\r
66   \r
67   render: () ->\r
68     this.$el.html('')\r
69     this.$el.append(Pettanr.AppHelper.t_a(@item.item_name(), 'author_id'))\r
70     this.$el.append(@linked_author.render().el) if @linked_author\r
71     this\r
72   \r
73   click: () ->\r
74     @trigger('click:author')\r
75   \r
76 class Pettanr.Views.Show.LinkedEditButton extends Tag.A\r
77   \r
78   initialize: (options) ->\r
79     item = options.item\r
80     super({\r
81       attr: {href: '/' + item.edit_url()}, \r
82       content: I18n.t('link.edit')\r
83     })\r
84   \r
85   url: () ->\r
86     @url\r
87   \r
88 class Pettanr.Views.Show.LinkedDestroyButton extends Tag.A\r
89   \r
90   initialize: (options) ->\r
91     item = options.item\r
92     super({\r
93       attr: {href: '/' + item.destroy_url()}, \r
94       content: I18n.t('link.destroy')\r
95     })\r
96   \r
97   url: () ->\r
98     @destroy_url\r
99   \r
100 class Pettanr.Views.Show.OwnerFooter extends Backbone.View\r
101   tagName: 'div'\r
102   className: 'show-owner-footer'\r
103   \r
104   initialize: (options) ->\r
105     super(options)\r
106     @item = options.item\r
107     @operators = options.operators\r
108     @edit = new Pettanr.Views.Show.LinkedEditButton({item: @item})\r
109     @destroy = new Pettanr.Views.Show.LinkedDestroyButton({item: @item})\r
110     @listenTo(@edit, 'click', @click_edit)\r
111     @listenTo(@destroy, 'click', @click_destroy)\r
112   \r
113   render: () ->\r
114     this.$el.html('')\r
115     this.$el.append(@edit.render().el)\r
116     this.$el.append(@destroy.render().el)\r
117     this\r
118   \r
119   click_edit: () ->\r
120     @trigger('click:edit')\r
121   \r
122   click_destroy: () ->\r
123     @trigger('click:destroy')\r
124   \r
125 class Pettanr.Views.Show.Owner extends Backbone.View\r
126   tagName: 'div'\r
127   \r
128   initialize: (options) ->\r
129     super(options)\r
130     @item = options.item\r
131     @operators = options.operators\r
132     @header = new Tag.H3({\r
133       class_name: 'owner-header',\r
134       content: I18n.t('editor')\r
135     })\r
136     @footer = new Pettanr.Views.Show.OwnerFooter({item: @item, operators: @operators})\r
137     @listenTo(@footer, 'click:edit', @click_edit)\r
138     @listenTo(@footer, 'click:destroy', @click_destroy)\r
139   \r
140   render: () ->\r
141     this.$el.html('')\r
142     this.$el.append(@header.render().el)\r
143     this.$el.append(@footer.render().el)\r
144     this\r
145   \r
146   click_edit: () ->\r
147     @trigger('click:footer:edit')\r
148     @trigger('click:edit')\r
149   \r
150   click_destroy: () ->\r
151     @trigger('click:footer:destroy')\r
152     @trigger('click:destroy')\r
153   \r