OSDN Git Service

add scroll player
[pettanr/pettanr.git] / app / assets / javascripts / views / scrolls / play.js.coffee
1 class Pettanr.Views.Scroll.PlayModule\r
2 class Pettanr.Views.Scroll.PlayModule.Header extends Pettanr.Views.Show.Header\r
3   \r
4   initialize: (options) ->\r
5     super(options)\r
6   \r
7 class Pettanr.Views.Scroll.PlayModule.Owner extends Pettanr.Views.Show.Owner\r
8   \r
9   initialize: (options) ->\r
10     super(options)\r
11   \r
12 class Pettanr.Views.Scroll.PlayModule.Footer extends Backbone.View\r
13   tagName: 'table'\r
14   className: 'no-border'\r
15   \r
16   initialize: (options) ->\r
17     @panel = options.panel\r
18     @scroll_panel = options.scroll_panel\r
19     @operators = options.operators\r
20   \r
21   render: () ->\r
22     this.$el.html('')\r
23     this.$el.append(\r
24       (new Pettanr.Views.Panel.Icon({item: @panel, half: true})).render().el\r
25     )\r
26     this.$el.append(\r
27       (new Pettanr.Views.Author.Icon({item: @panel.author(), half: true})).render().el\r
28     )\r
29     this.$el.append(Pettanr.AppHelper.distance_of_time_in_words_to_now(@panel.get('updated_at')))\r
30     #\r
31     this.$el.append(\r
32       (new Pettanr.Views.Panel.Icon({item: @scroll_panel, half: true})).render().el\r
33     )\r
34     this.$el.append(\r
35       (new Pettanr.Views.Author.Icon({item: @panel.author(), half: true})).render().el\r
36     )\r
37     this.$el.append(Pettanr.AppHelper.distance_of_time_in_words_to_now(@scroll_panel.get('updated_at')))\r
38     #\r
39     if @panel.is_own(@operators)\r
40       this.$el.append('')\r
41     this\r
42   \r
43 class Pettanr.Views.Scroll.PlayModule.Credits extends Backbone.View\r
44   tagName: 'div'\r
45   className: 'credits'\r
46   \r
47   initialize: (options) ->\r
48     @parent = options.parent\r
49     @licensed_pictures = {}\r
50   \r
51   render: () ->\r
52     this.$el.html('')\r
53     this\r
54   \r
55   push: (append_pictures) ->\r
56     _this = this\r
57     _.each append_pictures, (picture, pid) ->\r
58       return if _this.licensed_pictures[pid]\r
59       _this.licensed_pictures[pid] = picture\r
60       picture.fetch({cache: true}).done ->\r
61         credit = picture.credit_view()\r
62         _this.$el.append(credit.render().el)\r
63   \r
64 class Pettanr.Views.Scroll.PlayModule.Panels extends Backbone.View\r
65   tagName: 'div'\r
66   \r
67   initialize: (options) ->\r
68     @parent = options.parent\r
69     @items = options.items\r
70     @credits = options.credits\r
71     @operators = options.operators\r
72   \r
73   render: () ->\r
74     this.$el.html('')\r
75     _this = this\r
76     _.each @items, (scroll_panel) ->\r
77       return if not scroll_panel.has_panel()\r
78       panel = scroll_panel.panel()\r
79       panel.fetch({cache: true}).done ->\r
80         body = new Pettanr.Views.Panel.Body({\r
81           panel: panel,\r
82           operators: _this.operators,\r
83           spot: null\r
84         })\r
85         _this.$el.append(body.render().el)\r
86         footer = new Pettanr.Views.Panel.Footer({\r
87           scroll_panel: scroll_panel,\r
88           panel: panel,\r
89           operators: _this.operators\r
90         })\r
91         _this.$el.append(footer.render().el)\r
92         _this.credits.push(panel.licensed_pictures())\r
93     this\r
94   \r
95 class Pettanr.Views.Scroll.PlayModule.Body extends Backbone.View\r
96   tagName: 'div'\r
97   \r
98   initialize: (options) ->\r
99     @parent = options.parent\r
100     @list = options.list\r
101     @operators = options.operators\r
102     @items = @list.items()\r
103     if @items.length < 1\r
104       @render_empty()\r
105     else\r
106       @render()\r
107   \r
108   render_empty: () ->\r
109     this.$el.html('')\r
110     this.$el.append((new Tag.H2({content: I18n.t('scrolls.play.empty')})).render().el)\r
111     this\r
112   \r
113   render: () ->\r
114     this.$el.html('')\r
115     # paginate(@pager)\r
116     credits = new Pettanr.Views.Scroll.PlayModule.Credits({parent: this})\r
117     panels = new Pettanr.Views.Scroll.PlayModule.Panels({\r
118       parent: this,\r
119       items: @items,\r
120       credits: credits,\r
121       operators: @operators\r
122     })\r
123     this.$el.append(panels.render().el)\r
124     this.$el.append(credits.render().el)\r
125     rb = new Tag.RowBreak()\r
126     this.$el.append(rb.render().el)\r
127     # paginate(@pager)\r
128     this\r
129   \r
130 class Pettanr.Views.Scroll.Play extends Backbone.View\r
131   tagName: 'div'\r
132   className: 'show'\r
133   \r
134   initialize: (options) ->\r
135     @item = options.item\r
136     @list = options.list\r
137     @operators = options.operators\r
138     icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
139     caption_url = Pettanr.url(@item.table_name(), 'play', {id: @item.get('id')})\r
140     prof_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id'), format: 'prof'})\r
141     @header = new Pettanr.Views.Scroll.PlayModule.Header({\r
142       item: @item, \r
143       operators: @operators,\r
144       caption: @item.get('title'), \r
145       icon_url: icon_url,\r
146       caption_url: caption_url,\r
147       prof_url: prof_url\r
148     })\r
149     @author = new Pettanr.Views.Show.HeaderAuthor({item: @item})\r
150     @body = new Pettanr.Views.Scroll.PlayModule.Body({\r
151       parent: this,\r
152       list: @list, \r
153       operators: @operators\r
154     })\r
155     @owner = new Pettanr.Views.Scroll.PlayModule.Owner({item: @item, operators: @operators})\r
156   \r
157   render: () ->\r
158     this.$el.html('')\r
159     this.$el.append(@header.render().el)\r
160     this.$el.append(@author.render().el)\r
161     this.$el.append(@body.render().el)\r
162     this.$el.append(@owner.render().el) if @item.is_own(@operators)\r
163     this\r
164   \r