OSDN Git Service

fix player
[pettanr/pettanr.git] / app / assets / javascripts / locmare / filer / pager.js.coffee
1 class Locmare.FilerModule.DefaultPager extends Backbone.View\r
2   tagName: 'ul'\r
3   className: 'pagination'\r
4   \r
5   initialize: (options) ->\r
6     @page_status = options.page_status\r
7     @count = @page_status.count\r
8     @current_page = @page_status.current_page\r
9     @per_page = @page_status.per_page\r
10     @window_size = @page_status.window_size\r
11     @params = @page_status.params\r
12     @parts = []\r
13     @total = @count\r
14     @total_page = Math.floor(@total / @per_page) + 1\r
15     if @total_page > 1\r
16       @render()\r
17   \r
18   render: () ->\r
19     @parts = []\r
20     @build()\r
21     _this = this\r
22     this.$el.html('')\r
23     _.each @parts, (part) ->\r
24       _this.$el.append(part.render().el)\r
25     rb = new Tag.RowBreak()\r
26     this.$el.append(rb.render().el)\r
27     this\r
28   \r
29   build: () ->\r
30     opt = {pager: this, page_status: @page_status}\r
31     @parts.push(new Locmare.FilerModule.DefaultPager.FirstPage(opt)) if @hasPreviousPage()\r
32     @parts.push(new Locmare.FilerModule.DefaultPager.PrevPage(opt)) if @hasPreviousPage()\r
33     @parts.push(new Locmare.FilerModule.DefaultPager.PageGap(opt)) if @hasPreviousPageGap()\r
34     f = if @hasPreviousPageGap()\r
35       @current_page - @window_size\r
36     else\r
37       1\r
38     t = if @hasNextPageGap()\r
39       @current_page + @window_size\r
40     else\r
41       @total_page\r
42     for page in [f..t]\r
43       @parts.push(new Locmare.FilerModule.DefaultPager.Page({pager: this, page: page, page_status: @page_status}))\r
44     @parts.push(new Locmare.FilerModule.DefaultPager.PageGap(opt)) if @hasNextPageGap()\r
45     @parts.push(new Locmare.FilerModule.DefaultPager.NextPage(opt)) if @hasNextPage()\r
46     @parts.push(new Locmare.FilerModule.DefaultPager.LastPage(opt)) if @hasNextPage()\r
47   \r
48   hasPreviousPage: () ->\r
49     @current_page > 1\r
50   \r
51   hasNextPage: () ->\r
52     @current_page < @total_page\r
53   \r
54   hasPreviousPageGap: () ->\r
55     @current_page > @window_size + 1\r
56   \r
57   hasNextPageGap: () ->\r
58     @total_page - @current_page > @window_size\r
59   \r
60 class Locmare.FilerModule.DefaultPager.FirstPage extends Backbone.View\r
61   tagName: 'li'\r
62   className: 'first'\r
63   \r
64   initialize: (options) ->\r
65     @page_status = options.page_status\r
66     @params = @page_status.params\r
67   \r
68   render: () ->\r
69     my_params = {}\r
70     _.extend(my_params, @params)\r
71     my_params['page'] = 1\r
72     url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
73     linked_caption = new Tag.A({\r
74       attr: {href: '/' + url}, \r
75       handler_name: url,\r
76       content: '<<'\r
77     })\r
78     this.$el.html(linked_caption.render().el)\r
79     this\r
80   \r
81 class Locmare.FilerModule.DefaultPager.PrevPage extends Backbone.View\r
82   tagName: 'li'\r
83   className: 'prev'\r
84   \r
85   initialize: (options) ->\r
86     @page_status = options.page_status\r
87     @current_page = @page_status.current_page\r
88     @params = @page_status.params\r
89   \r
90   render: () ->\r
91     my_params = {}\r
92     _.extend(my_params, @params)\r
93     my_params['page'] = @current_page - 1\r
94     url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
95     linked_caption = new Tag.A({\r
96       attr: {href: '/' + url}, \r
97       handler_name: url,\r
98       content: '<'\r
99     })\r
100     this.$el.html(linked_caption.render().el)\r
101     this\r
102   \r
103   \r
104 class Locmare.FilerModule.DefaultPager.PageGap extends Backbone.View\r
105   tagName: 'li'\r
106   className: 'page-gap'\r
107   \r
108   render: () ->\r
109     this.$el.html('...')\r
110     this\r
111   \r
112 class Locmare.FilerModule.DefaultPager.Page extends Backbone.View\r
113   tagName: 'li'\r
114   className: 'page'\r
115   \r
116   initialize: (options) ->\r
117     @page_status = options.page_status\r
118     @page = options.page\r
119     @params = @page_status.params\r
120   \r
121   render: () ->\r
122     my_params = {}\r
123     _.extend(my_params, @params)\r
124     my_params['page'] = @page\r
125     url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
126     linked_caption = new Tag.A({\r
127       attr: {href: '/' + url}, \r
128       handler_name: url,\r
129       content: @page\r
130     })\r
131     this.$el.html(linked_caption.render().el)\r
132     this\r
133   \r
134 class Locmare.FilerModule.DefaultPager.NextPage extends Backbone.View\r
135   tagName: 'li'\r
136   className: 'next'\r
137   \r
138   initialize: (options) ->\r
139     @page_status = options.page_status\r
140     @current_page = @page_status.current_page\r
141     @params = @page_status.params\r
142   \r
143   render: () ->\r
144     my_params = {}\r
145     _.extend(my_params, @params)\r
146     my_params['page'] = @current_page + 1\r
147     url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
148     linked_caption = new Tag.A({\r
149       attr: {href: '/' + url}, \r
150       handler_name: url,\r
151       content: '>'\r
152     })\r
153     this.$el.html(linked_caption.render().el)\r
154     this\r
155   \r
156 class Locmare.FilerModule.DefaultPager.LastPage extends Backbone.View\r
157   tagName: 'li'\r
158   className: 'last'\r
159   \r
160   initialize: (options) ->\r
161     @page_status = options.page_status\r
162     @pager = options.pager\r
163     @params = @page_status.params\r
164   \r
165   render: () ->\r
166     my_params = {}\r
167     _.extend(my_params, @params)\r
168     my_params['page'] = @pager.total_page\r
169     url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
170     linked_caption = new Tag.A({\r
171       attr: {href: '/' + url}, \r
172       handler_name: url,\r
173       content: '>>'\r
174     })\r
175     this.$el.html(linked_caption.render().el)\r
176     this\r
177   \r
178 class Locmare.FilerModule.MorePager extends Backbone.View\r
179   \r