OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / views / show.js.coffee
1 class Pettanr.Views.Show\r
2 class Pettanr.Views.Show.Header extends Pettanr.View\r
3   tagName: 'h1'\r
4   className: 'show-header'\r
5   \r
6   initialize: (options) ->\r
7     @item = options.item\r
8     @title = options.caption\r
9     @icon_url = options.icon_url\r
10     @caption_url = options.caption_url\r
11     @prof_url = options.prof_url\r
12     \r
13     @pick = null\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_button, '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(@pick.render().el) if @pick\r
38     this.$el.append(@icon_button.render().el)\r
39     this.$el.append(@caption.render().el)\r
40     this.$el.append(@prof_button.render().el)\r
41     this\r
42   \r
43   click_pick: () ->\r
44     @trigger('click:pick')\r
45   \r
46   click_icon: () ->\r
47     @trigger('click:icon')\r
48   \r
49   click_caption: () ->\r
50     @trigger('click:caption')\r
51   \r
52   click_prof: () ->\r
53     @trigger('click:prof')\r
54   \r
55   add_pick: (target_model) ->\r
56     @pick = new Pettanr.Views.Common.PickIcon({\r
57       name: target_model.pick_type(@item.item_name()), half: true\r
58     })\r
59     @listenTo(@pick, 'click', @click_pick)\r
60     @render()\r
61   \r
62 class Pettanr.Views.Show.HeaderAuthor extends Pettanr.View\r
63   tagName: 'div'\r
64   \r
65   initialize: (options) ->\r
66     @item = options.item\r
67     @item.get_parent('author', this, {\r
68       success: (@author) =>\r
69         name = @author.escape('name')\r
70         author_url = @author.show_url()\r
71         @linked_author =  new Tag.A({\r
72           attr: {href: '/' + author_url}, \r
73           content: name\r
74         })\r
75         @listenTo(@linked_author, 'click', @click)\r
76         @render()\r
77     })\r
78   \r
79   render: () ->\r
80     this.$el.html('')\r
81     this.$el.append(Pettanr.AppHelper.t_a(@item.item_name(), 'author_id'))\r
82     this.$el.append(@linked_author.render().el) if @linked_author\r
83     this\r
84   \r
85   click: () ->\r
86     @trigger('click:author')\r
87   \r
88 class Pettanr.Views.Show.HeaderArtist extends Pettanr.View\r
89   tagName: 'div'\r
90   \r
91   initialize: (options) ->\r
92     @item = options.item\r
93     @item.get_parent('artist', this, {\r
94       success: (@artist) =>\r
95         name = @artist.escape('name')\r
96         artist_url = @artist.show_url()\r
97         @linked_artist =  new Tag.A({\r
98           attr: {href: '/' + artist_url}, \r
99           content: name\r
100         })\r
101         @listenTo(@linked_artist, 'click', @click)\r
102         @render()\r
103     })\r
104   \r
105   render: () ->\r
106     this.$el.html('')\r
107     this.$el.append(Pettanr.AppHelper.t_a(@item.item_name(), 'artist_id'))\r
108     this.$el.append(@linked_artist.render().el) if @linked_artist\r
109     this\r
110   \r
111   click: () ->\r
112     @trigger('click:artist')\r
113   \r
114 class Pettanr.Views.Show.LinkedNewButton extends Tag.A\r
115   \r
116   initialize: (options) ->\r
117     item = options.item\r
118     dn = options.dic_name || 'link.new'\r
119     super({\r
120       attr: {href: '/' + item.new_url()}, \r
121       content: I18n.t(dn)\r
122     })\r
123   \r
124 class Pettanr.Views.Show.LinkedEditButton extends Tag.A\r
125   \r
126   initialize: (options) ->\r
127     item = options.item\r
128     dn = options.dic_name || 'link.edit'\r
129     super({\r
130       attr: {href: '/' + item.edit_url()}, \r
131       content: I18n.t(dn)\r
132     })\r
133   \r
134 class Pettanr.Views.Show.LinkedDestroyButton extends Tag.A\r
135   \r
136   initialize: (options) ->\r
137     item = options.item\r
138     dn = options.dic_name || 'link.destroy'\r
139     super({\r
140       attr: {href: '/' + item.destroy_url()}, \r
141       content: I18n.t(dn)\r
142     })\r
143   \r
144 class Pettanr.Views.Show.LinkedInspireIcon extends Tag.A\r
145   \r
146   initialize: (options) ->\r
147     item = options.item\r
148     half = options.half\r
149     img = new Pettanr.Image.SymbolImg({\r
150       attr: {src: '/images/inspire.gif'}, half: half\r
151     })\r
152     super({\r
153       attr: {href: '/' + item.index_url() + '/inspire'}, \r
154       content: img.render().el\r
155     })\r
156   \r
157 class Pettanr.Views.Show.OwnerFooter extends Pettanr.View\r
158   tagName: 'div'\r
159   className: 'show-owner-footer'\r
160   \r
161   initialize: (options) ->\r
162     super(options)\r
163     @item = options.item\r
164     @edit = new Pettanr.Views.Show.LinkedEditButton({item: @item})\r
165     @destroy = new Pettanr.Views.Show.LinkedDestroyButton({item: @item})\r
166     @listenTo(@edit, 'click', @click_edit)\r
167     @listenTo(@destroy, 'click', @click_destroy)\r
168   \r
169   render: () ->\r
170     this.$el.html('')\r
171     this.$el.append(@edit.render().el)\r
172     this.$el.append(@destroy.render().el)\r
173     this\r
174   \r
175   click_edit: () ->\r
176     @trigger('click:edit')\r
177   \r
178   click_destroy: () ->\r
179     @trigger('click:destroy')\r
180   \r
181 class Pettanr.Views.Show.Owner extends Pettanr.View\r
182   tagName: 'div'\r
183   \r
184   initialize: (options) ->\r
185     super(options)\r
186     @item = options.item\r
187     @header = new Tag.H3({\r
188       class_name: 'owner-header',\r
189       content: I18n.t('editor')\r
190     })\r
191     fc = @footer_class()\r
192     @footer = new fc({item: @item})\r
193     @listenTo(@footer, 'click:edit', @click_edit)\r
194     @listenTo(@footer, 'click:destroy', @click_destroy)\r
195   \r
196   render: () ->\r
197     this.$el.html('')\r
198     this.$el.append(@header.render().el)\r
199     this.$el.append(@footer.render().el)\r
200     this\r
201   \r
202   click_edit: () ->\r
203     @trigger('click:footer:edit')\r
204     @trigger('click:edit')\r
205   \r
206   click_destroy: () ->\r
207     @trigger('click:footer:destroy')\r
208     @trigger('click:destroy')\r
209   \r
210   footer_class: () ->\r
211     Pettanr.Views.Show.OwnerFooter\r
212   \r