diff options
Diffstat (limited to 'node_modules/montage-user/ui/controller/paged-array-controller.js')
-rwxr-xr-x | node_modules/montage-user/ui/controller/paged-array-controller.js | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/node_modules/montage-user/ui/controller/paged-array-controller.js b/node_modules/montage-user/ui/controller/paged-array-controller.js new file mode 100755 index 00000000..80642467 --- /dev/null +++ b/node_modules/montage-user/ui/controller/paged-array-controller.js | |||
@@ -0,0 +1,260 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/ui/controller/paged-array-controller | ||
8 | @requires montage/core/core | ||
9 | @requires ui/controller/array-controller | ||
10 | @requires core/event/mutable-event | ||
11 | */ | ||
12 | var Montage = require("montage").Montage, | ||
13 | ArrayController = require("ui/controller/array-controller").ArrayController, | ||
14 | MutableEvent = require("core/event/mutable-event").MutableEvent; | ||
15 | /** | ||
16 | @class module:montage/ui/controller/paged-array-controller.PagedArrayController | ||
17 | @extends module:montage/ui/controller/array-controller.ArrayController | ||
18 | */ | ||
19 | exports.PagedArrayController = Montage.create(ArrayController,/** @lends module:montage/ui/controller/paged-array-controller.PagedArrayController# */ { | ||
20 | /** | ||
21 | Description TODO | ||
22 | @private | ||
23 | */ | ||
24 | _pageSize: { | ||
25 | value: 10 | ||
26 | }, | ||
27 | //changing this should recalculate pageIndex to contain first item of previous current page | ||
28 | // via gotoOffset ? | ||
29 | /** | ||
30 | Description TODO | ||
31 | @type {Function} | ||
32 | @default {Number} 10 | ||
33 | */ | ||
34 | pageSize: { | ||
35 | get: function() { | ||
36 | return this._pageSize; | ||
37 | }, | ||
38 | set: function(value) { | ||
39 | if (value !== this._pageSize) { | ||
40 | this._calculate(value, this._pageIndex, this._padding); | ||
41 | } | ||
42 | } | ||
43 | }, | ||
44 | |||
45 | /** | ||
46 | Description TODO | ||
47 | @private | ||
48 | */ | ||
49 | _padding: { | ||
50 | value: 0 | ||
51 | }, | ||
52 | // changing this should change the organized object to have the new padding | ||
53 | /** | ||
54 | Description TODO | ||
55 | @type {Function} | ||
56 | @default {Number} 0 | ||
57 | */ | ||
58 | padding: { | ||
59 | get: function() { | ||
60 | return this._padding; | ||
61 | }, | ||
62 | set: function(value) { | ||
63 | if (value !== this._padding) { | ||
64 | this._calculate(this._pageSize, this._pageIndex, value); | ||
65 | } | ||
66 | } | ||
67 | }, | ||
68 | /** | ||
69 | Description TODO | ||
70 | @private | ||
71 | */ | ||
72 | _pageIndex: { | ||
73 | value: 0, | ||
74 | enumerable: false | ||
75 | }, | ||
76 | // changing this should change the start and endIndex | ||
77 | /** | ||
78 | Description TODO | ||
79 | @type {Function} | ||
80 | @default {Number} 0 | ||
81 | */ | ||
82 | pageIndex: { | ||
83 | get: function() { | ||
84 | return this._pageIndex; | ||
85 | }, | ||
86 | set: function(pageIndex) { | ||
87 | if (pageIndex !== this._pageIndex) { | ||
88 | pageIndex = pageIndex >= this.pageCount ? this.pageCount - 1 : pageIndex < 0 ? 0 : pageIndex; | ||
89 | this._calculate(this._pageSize, pageIndex, this._padding); | ||
90 | } | ||
91 | } | ||
92 | }, | ||
93 | |||
94 | /** | ||
95 | Description TODO | ||
96 | @private | ||
97 | */ | ||
98 | _pageCount: { | ||
99 | value: null, | ||
100 | enumerable: false | ||
101 | }, | ||
102 | /** | ||
103 | Description TODO | ||
104 | @type {Function} | ||
105 | @default null | ||
106 | */ | ||
107 | pageCount: { | ||
108 | get: function() { | ||
109 | return this._pageCount; | ||
110 | } | ||
111 | }, | ||
112 | |||
113 | /** | ||
114 | Description TODO | ||
115 | @type {Function} | ||
116 | @default {Array} array | ||
117 | */ | ||
118 | pageNumber: { | ||
119 | dependencies: ["pageIndex"], | ||
120 | get: function() { | ||
121 | return this._pageIndex + 1; | ||
122 | } | ||
123 | }, | ||
124 | |||
125 | /** | ||
126 | Description TODO | ||
127 | @private | ||
128 | */ | ||
129 | _calculate: { | ||
130 | value: function(pageSize, pageIndex, padding) { | ||
131 | var contentLength = this.content.length, | ||
132 | pageCount = this._pageCount, | ||
133 | startIndex, endIndex, | ||
134 | pageSizeChangeEvent, | ||
135 | pageIndexChangeEvent, | ||
136 | paddingChangeEvent, | ||
137 | pageCountChangeEvent, | ||
138 | startIndexChangeEvent, | ||
139 | endIndexChangeEvent; | ||
140 | |||
141 | if (pageSize !== this._pageSize) { | ||
142 | pageSizeChangeEvent = MutableEvent.changeEventForKeyAndValue("pageSize", this._pageSize); | ||
143 | this._pageSize = pageSize; | ||
144 | } | ||
145 | if (pageIndex !== this._pageIndex) { | ||
146 | pageIndexChangeEvent = MutableEvent.changeEventForKeyAndValue("pageIndex", this._pageIndex); | ||
147 | this._pageIndex = pageIndex; | ||
148 | } | ||
149 | if (padding !== this._padding) { | ||
150 | paddingChangeEvent = MutableEvent.changeEventForKeyAndValue("padding", this._padding); | ||
151 | this._padding = padding; | ||
152 | } | ||
153 | |||
154 | pageCountChangeEvent = MutableEvent.changeEventForKeyAndValue("pageCount", pageCount); | ||
155 | this._pageCount = pageCount = Math.ceil(contentLength / pageSize); | ||
156 | |||
157 | startIndexChangeEvent = MutableEvent.changeEventForKeyAndValue("startIndex", this._startIndex); | ||
158 | startIndex = pageIndex * pageSize - padding; | ||
159 | this._startIndex = startIndex = startIndex < 0 ? 0 : startIndex; | ||
160 | |||
161 | endIndexChangeEvent = MutableEvent.changeEventForKeyAndValue("endIndex", this._endIndex); | ||
162 | endIndex = pageIndex * pageSize + pageSize + padding; | ||
163 | this._endIndex = endIndex = endIndex > contentLength ? contentLength : endIndex; | ||
164 | |||
165 | if (pageCountChangeEvent.minus !== pageCount) { | ||
166 | this.dispatchEvent(pageCountChangeEvent.withPlusValue(pageCount)); | ||
167 | } | ||
168 | if (startIndexChangeEvent.minus !== startIndex) { | ||
169 | this.dispatchEvent(startIndexChangeEvent.withPlusValue(startIndex)); | ||
170 | } | ||
171 | if (endIndexChangeEvent.minus !== endIndex) { | ||
172 | this.dispatchEvent(endIndexChangeEvent.withPlusValue(endIndex)); | ||
173 | } | ||
174 | if (pageSizeChangeEvent) { | ||
175 | this.dispatchEvent(pageSizeChangeEvent.withPlusValue(pageSize)); | ||
176 | } | ||
177 | if (pageIndexChangeEvent) { | ||
178 | this.dispatchEvent(pageIndexChangeEvent.withPlusValue(pageIndex)); | ||
179 | } | ||
180 | if (paddingChangeEvent) { | ||
181 | this.dispatchEvent(paddingChangeEvent.withPlusValue(padding)); | ||
182 | } | ||
183 | } | ||
184 | }, | ||
185 | /** | ||
186 | Description TODO | ||
187 | @function | ||
188 | */ | ||
189 | gotoFirstPage: { | ||
190 | value: function() { | ||
191 | this.gotoPage(0); | ||
192 | } | ||
193 | }, | ||
194 | /** | ||
195 | Description TODO | ||
196 | @function | ||
197 | */ | ||
198 | gotoLastPage: { | ||
199 | value: function() { | ||
200 | this.gotoPage(this.pageCount - 1); | ||
201 | } | ||
202 | }, | ||
203 | /** | ||
204 | Description TODO | ||
205 | @function | ||
206 | */ | ||
207 | gotoNextPage: { | ||
208 | value: function() { | ||
209 | this.gotoPage(this.pageIndex + 1); | ||
210 | } | ||
211 | }, | ||
212 | /** | ||