OSDN Git Service

try editor event dispatching
[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     @author = @item.author()\r
48     @author.fetch({cache: true}).done =>\r
49       name = @author.get('name')\r
50       author_url = Pettanr.url(@author.table_name(), 'show', {id: @author.get('id')})\r
51       @linked_author =  new Tag.A({\r
52         attr: {href: '/' + author_url}, \r
53         handler_name: author_url,\r
54         content: name\r
55       })\r
56       @render()\r
57   \r
58   render: () ->\r
59     this.$el.html('')\r
60     this.$el.append(Pettanr.AppHelper.t_a(@item.item_name(), 'author_id'))\r
61     this.$el.append(@linked_author.render().el) if @linked_author\r
62     this\r
63   \r
64 class Pettanr.Views.Show.LinkedEditButton extends Tag.A\r
65   \r
66   initialize: (options) ->\r
67     item = options.item\r
68     edit_url = Pettanr.url(item.table_name(), 'edit', {id: item.get('id')})\r
69     super({\r
70       attr: {href: '/' + edit_url}, \r
71       handler_name: edit_url,\r
72       content: I18n.t('link.edit')\r
73     })\r
74   \r
75 class Pettanr.Views.Show.LinkedDestroyButton extends Tag.A\r
76   \r
77   initialize: (options) ->\r
78     item = options.item\r
79     edit_url = Pettanr.url(item.table_name(), 'destroy', {id: item.get('id')})\r
80     super({\r
81       attr: {href: '/' + edit_url}, \r
82       handler_name: edit_url,\r
83       content: I18n.t('link.destroy')\r
84     })\r
85   \r
86 class Pettanr.Views.Show.OwnerFooter extends Backbone.View\r
87   tagName: 'div'\r
88   className: 'show-owner-footer'\r
89   \r
90   initialize: (options) ->\r
91     super(options)\r
92     @item = options.item\r
93     @operators = options.operators\r
94     @edit = new Pettanr.Views.Show.LinkedEditButton({item: @item})\r
95     @destroy = new Pettanr.Views.Show.LinkedDestroyButton({item: @item})\r
96   \r
97   render: () ->\r
98     this.$el.html('')\r
99     this.$el.append(@edit.render().el)\r
100     this.$el.append(@destroy.render().el)\r
101     this\r
102   \r
103 class Pettanr.Views.Show.Owner extends Backbone.View\r
104   tagName: 'div'\r
105   \r
106   initialize: (options) ->\r
107     super(options)\r
108     @item = options.item\r
109     @operators = options.operators\r
110     @header = new Tag.H3({\r
111       class_name: 'owner-header',\r
112       content: I18n.t('editor')\r
113     })\r
114     @footer = new Pettanr.Views.Show.OwnerFooter({item: @item, operators: @operators})\r
115   \r
116   render: () ->\r
117     this.$el.html('')\r
118     this.$el.append(@header.render().el)\r
119     this.$el.append(@footer.render().el)\r
120     this\r
121   \r