OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Namespace for utility functions. | 8 * Namespace for utility functions. |
9 */ | 9 */ |
10 var filelist = {}; | 10 var filelist = {}; |
11 | 11 |
12 /** | 12 /** |
13 * Custom column model for advanced auto-resizing. | |
14 * @param {Array.<cr.ui.table.TableColumn>} tableColumns Table columns. | |
15 * @constructor | |
16 */ | |
yoshiki
2013/04/17 08:12:00
Add "@extends {cr.ui.table.TableColumnModel}".
mtomasz
2013/04/17 08:52:21
Done.
| |
17 function FileTableColumnModel(tableColumns) { | |
18 cr.ui.table.TableColumnModel.call(this, tableColumns); | |
19 } | |
20 | |
21 /** | |
22 * Inherits from cr.ui.Table. | |
23 */ | |
24 FileTableColumnModel.prototype.__proto__ = | |
25 cr.ui.table.TableColumnModel.prototype; | |
26 | |
27 /** | |
28 * Normalizes widths to make their sum 100%. Uses the proportional approach | |
29 * with some additional constraints. | |
30 * | |
31 * @param {number} contentWidth Target width. | |
32 * @override | |
33 */ | |
34 FileTableColumnModel.prototype.normalizeWidths = function(contentWidth) { | |
35 var fixedWidth = 0; | |
36 var flexibleWidth = 0; | |
37 | |
38 // Some columns have fixed width. | |
39 for (var index = 0; index < this.size; index++) { | |
40 var column = this.columns_[index]; | |
41 if (column.id == 'selection') | |
42 fixedWidth += column.width; | |
43 else | |
44 flexibleWidth += column.width; | |
45 } | |
46 | |
47 var factor = (contentWidth - fixedWidth) / flexibleWidth; | |
48 for (var index = 0; index < this.size; index++) { | |
49 var column = this.columns_[index]; | |
50 if (column.id == 'selection') | |
51 continue; | |
52 column.width = column.width * factor; | |
53 } | |
54 }; | |
55 | |
56 /** | |
13 * File list Table View. | 57 * File list Table View. |
14 * @constructor | 58 * @constructor |
15 */ | 59 */ |
16 function FileTable() { | 60 function FileTable() { |
17 throw new Error('Designed to decorate elements'); | 61 throw new Error('Designed to decorate elements'); |
18 } | 62 } |
19 | 63 |
20 /** | 64 /** |
21 * Inherits from cr.ui.Table. | 65 * Inherits from cr.ui.Table. |
22 */ | 66 */ |
23 FileTable.prototype.__proto__ = cr.ui.Table.prototype; | 67 FileTable.prototype.__proto__ = cr.ui.Table.prototype; |
24 | 68 |
25 /** | 69 /** |
26 * Decorates the element. | 70 * Decorates the element. |
27 * @param {HTMLElement} self Table to decorate. | 71 * @param {HTMLElement} self Table to decorate. |
28 * @param {MetadataCache} metadataCache To retrieve metadata. | 72 * @param {MetadataCache} metadataCache To retrieve metadata. |
29 * @param {boolean} fullPage True if it's full page File Manager, | 73 * @param {boolean} fullPage True if it's full page File Manager, |
30 * False if a file open/save dialog. | 74 * False if a file open/save dialog. |
31 */ | 75 */ |
32 FileTable.decorate = function(self, metadataCache, fullPage) { | 76 FileTable.decorate = function(self, metadataCache, fullPage) { |
33 cr.ui.Table.decorate(self); | 77 cr.ui.Table.decorate(self); |
34 self.__proto__ = FileTable.prototype; | 78 self.__proto__ = FileTable.prototype; |
35 self.metadataCache_ = metadataCache; | 79 self.metadataCache_ = metadataCache; |
36 self.collator_ = v8Intl.Collator([], {numeric: true, sensitivity: 'base'}); | 80 self.collator_ = v8Intl.Collator([], {numeric: true, sensitivity: 'base'}); |
37 | 81 |
38 var columns = [ | 82 var columns = [ |
39 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), | 83 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), |
40 fullPage ? 386 : 324), | 84 fullPage ? 386 : 324), |
41 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), | 85 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), |
42 fullPage ? 100 : 92, true), | 86 fullPage ? 100 : 92, true), |
43 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'), | 87 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'), |
44 fullPage ? 160 : 160), | 88 fullPage ? 160 : 160), |
45 new cr.ui.table.TableColumn('modificationTime', | 89 new cr.ui.table.TableColumn('modificationTime', |
46 str('DATE_COLUMN_LABEL'), | 90 str('DATE_COLUMN_LABEL'), |
47 fullPage ? 150 : 210), | 91 fullPage ? 150 : 210) |
48 new cr.ui.table.TableColumn('offline', | 92 ]; |
49 str('OFFLINE_COLUMN_LABEL'), | |
50 130) | |
51 ]; | |
52 | 93 |
53 columns[0].renderFunction = self.renderName_.bind(self); | 94 columns[0].renderFunction = self.renderName_.bind(self); |
54 columns[1].renderFunction = self.renderSize_.bind(self); | 95 columns[1].renderFunction = self.renderSize_.bind(self); |
55 columns[1].defaultOrder = 'desc'; | 96 columns[1].defaultOrder = 'desc'; |
56 columns[2].renderFunction = self.renderType_.bind(self); | 97 columns[2].renderFunction = self.renderType_.bind(self); |
57 columns[3].renderFunction = self.renderDate_.bind(self); | 98 columns[3].renderFunction = self.renderDate_.bind(self); |
58 columns[3].defaultOrder = 'desc'; | 99 columns[3].defaultOrder = 'desc'; |
59 columns[4].renderFunction = self.renderOffline_.bind(self); | |
60 | 100 |
61 columns[0].headerRenderFunction = | 101 var tableColumnModelClass; |
62 self.renderNameColumnHeader_.bind(self, columns[0].name); | 102 if (util.platform.newUI()) { |
103 tableColumnModelClass = FileTableColumnModel; | |
104 columns.push(new cr.ui.table.TableColumn('selection', | |
105 '', | |
106 50, true)); | |
107 columns[4].renderFunction = self.renderSelection_.bind(self); | |
108 columns[4].headerRenderFunction = | |
109 self.renderSelectionColumnHeader_.bind(self); | |
110 } else { | |
111 tableColumnModelClass = cr.ui.table.TableColumnModel; | |
112 columns.push(new cr.ui.table.TableColumn('offline', | |
113 str('OFFLINE_COLUMN_LABEL'), | |
114 130)); | |
115 columns[4].renderFunction = self.renderOffline_.bind(self); | |
116 columns[0].headerRenderFunction = | |
117 self.renderNameColumnHeader_.bind(self, columns[0].name); | |
118 } | |
63 | 119 |
64 var columnModel = Object.create(cr.ui.table.TableColumnModel.prototype, { | 120 var columnModel = Object.create(tableColumnModelClass.prototype, { |
yoshiki
2013/04/17 08:12:00
nit: Remove a space at the head of the line.
mtomasz
2013/04/17 08:52:21
Done.
| |
65 size: { | 121 size: { |
66 get: function() { | 122 get: function() { |
123 if (util.platform.newUI()) | |
124 return this.totalSize; | |
67 return this.showOfflineColumn ? this.totalSize : this.totalSize - 1; | 125 return this.showOfflineColumn ? this.totalSize : this.totalSize - 1; |
68 } | 126 } |
69 }, | 127 }, |
70 | 128 |
71 totalSize: { | 129 totalSize: { |
72 get: function() { | 130 get: function() { |
73 return columns.length; | 131 return columns.length; |
74 } | 132 } |
75 }, | 133 }, |
76 | 134 |
77 showOfflineColumn: { | 135 showOfflineColumn: { |
78 writable: true, | 136 writable: true, |
79 value: false | 137 value: false |
80 } | 138 } |
81 }); | 139 }); |
82 cr.ui.table.TableColumnModel.call(columnModel, columns); | 140 |
141 tableColumnModelClass.call(columnModel, columns); | |
83 self.columnModel = columnModel; | 142 self.columnModel = columnModel; |
84 self.setDateTimeFormat(true); | 143 self.setDateTimeFormat(true); |
85 self.setRenderFunction(self.renderTableRow_.bind(self, | 144 self.setRenderFunction(self.renderTableRow_.bind(self, |
86 self.getRenderFunction())); | 145 self.getRenderFunction())); |
87 | 146 |
147 if (util.platform.newUI()) | |
148 ScrollBar.createVertical(self, self.list); | |
149 | |
88 var handleSelectionChange = function() { | 150 var handleSelectionChange = function() { |
89 var selectAll = self.querySelector('#select-all-checkbox'); | 151 var selectAll = self.querySelector('#select-all-checkbox'); |
90 if (selectAll) | 152 if (selectAll) |
91 self.updateSelectAllCheckboxState_(selectAll); | 153 self.updateSelectAllCheckboxState_(selectAll); |
92 }; | 154 }; |
93 | 155 |
94 Object.defineProperty(self.list_, 'selectionModel', { | 156 Object.defineProperty(self.list_, 'selectionModel', { |
95 get: function() { | 157 get: function() { |
96 return this.selectionModel_; | 158 return this.selectionModel_; |
97 }, | 159 }, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 * Invoked by cr.ui.Table when a file needs to be rendered. | 233 * Invoked by cr.ui.Table when a file needs to be rendered. |
172 * | 234 * |
173 * @param {Entry} entry The Entry object to render. | 235 * @param {Entry} entry The Entry object to render. |
174 * @param {string} columnId The id of the column to be rendered. | 236 * @param {string} columnId The id of the column to be rendered. |
175 * @param {cr.ui.Table} table The table doing the rendering. | 237 * @param {cr.ui.Table} table The table doing the rendering. |
176 * @return {HTMLDivElement} Created element. | 238 * @return {HTMLDivElement} Created element. |
177 * @private | 239 * @private |
178 */ | 240 */ |
179 FileTable.prototype.renderName_ = function(entry, columnId, table) { | 241 FileTable.prototype.renderName_ = function(entry, columnId, table) { |
180 var label = this.ownerDocument.createElement('div'); | 242 var label = this.ownerDocument.createElement('div'); |
181 if (this.selectionModel.multiple) { | 243 if (!util.platform.newUI()) { |
182 var checkBox = this.ownerDocument.createElement('INPUT'); | 244 if (this.selectionModel.multiple) { |
183 filelist.decorateSelectionCheckbox(checkBox, entry, this.list); | 245 var checkBox = this.ownerDocument.createElement('INPUT'); |
yoshiki
2013/04/17 08:12:00
nit: 'INPUT' should be in small letter for consist
mtomasz
2013/04/17 08:52:21
Done.
| |
184 label.appendChild(checkBox); | 246 filelist.decorateSelectionCheckbox(checkBox, entry, this.list); |
247 label.appendChild(checkBox); | |
248 } | |
185 } | 249 } |
186 label.appendChild(this.renderIconType_(entry, columnId, table)); | 250 label.appendChild(this.renderIconType_(entry, columnId, table)); |
187 label.entry = entry; | 251 label.entry = entry; |
188 label.className = 'detail-name'; | 252 label.className = 'detail-name'; |
189 label.appendChild(filelist.renderFileNameLabel(this.ownerDocument, entry)); | 253 label.appendChild(filelist.renderFileNameLabel(this.ownerDocument, entry)); |
190 return label; | 254 return label; |
191 }; | 255 }; |
192 | 256 |
193 /** | 257 /** |
258 * Render the Selection column of the detail table. | |
259 * | |
260 * Invoked by cr.ui.Table when a file needs to be rendered. | |
261 * | |
262 * @param {Entry} entry The Entry object to render. | |
263 * @param {string} columnId The id of the column to be rendered. | |
264 * @param {cr.ui.Table} table The table doing the rendering. | |
265 * @return {HTMLDivElement} Created element. | |
266 * @private | |
267 */ | |
268 FileTable.prototype.renderSelection_ = function(entry, columnId, table) { | |
269 var label = this.ownerDocument.createElement('div'); | |
270 label.className = 'selection-label'; | |
271 if (this.selectionModel.multiple) { | |
272 var checkBox = this.ownerDocument.createElement('INPUT'); | |
yoshiki
2013/04/17 08:12:00
ditto
mtomasz
2013/04/17 08:52:21
Done.
| |
273 filelist.decorateSelectionCheckbox(checkBox, entry, this.list); | |
274 label.appendChild(checkBox); | |
275 } | |
276 return label; | |
277 }; | |
278 | |
279 /** | |
194 * Render the Size column of the detail table. | 280 * Render the Size column of the detail table. |
195 * | 281 * |
196 * @param {Entry} entry The Entry object to render. | 282 * @param {Entry} entry The Entry object to render. |
197 * @param {string} columnId The id of the column to be rendered. | 283 * @param {string} columnId The id of the column to be rendered. |
198 * @param {cr.ui.Table} table The table doing the rendering. | 284 * @param {cr.ui.Table} table The table doing the rendering. |
199 * @return {HTMLDivElement} Created element. | 285 * @return {HTMLDivElement} Created element. |
200 * @private | 286 * @private |
201 */ | 287 */ |
202 FileTable.prototype.renderSize_ = function(entry, columnId, table) { | 288 FileTable.prototype.renderSize_ = function(entry, columnId, table) { |
203 var div = this.ownerDocument.createElement('div'); | 289 var div = this.ownerDocument.createElement('div'); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 return item; | 574 return item; |
489 }; | 575 }; |
490 | 576 |
491 /** | 577 /** |
492 * Renders the name column header. | 578 * Renders the name column header. |
493 * @param {string} name Localized column name. | 579 * @param {string} name Localized column name. |
494 * @return {HTMLLiElement} Created element. | 580 * @return {HTMLLiElement} Created element. |
495 * @private | 581 * @private |
496 */ | 582 */ |
497 FileTable.prototype.renderNameColumnHeader_ = function(name) { | 583 FileTable.prototype.renderNameColumnHeader_ = function(name) { |
498 if (!this.selectionModel.multiple) { | 584 if (!this.selectionModel.multiple) |
499 return this.ownerDocument.createTextNode(name); | 585 return this.ownerDocument.createTextNode(name); |
500 } | 586 |
501 var input = this.ownerDocument.createElement('input'); | 587 var input = this.ownerDocument.createElement('input'); |
502 input.setAttribute('type', 'checkbox'); | 588 input.setAttribute('type', 'checkbox'); |
503 input.setAttribute('tabindex', -1); | 589 input.setAttribute('tabindex', -1); |
504 input.id = 'select-all-checkbox'; | 590 input.id = 'select-all-checkbox'; |
505 input.className = 'common'; | 591 input.className = 'common'; |
506 | 592 |
507 this.updateSelectAllCheckboxState_(input); | 593 this.updateSelectAllCheckboxState_(input); |
508 | 594 |
509 input.addEventListener('click', function(event) { | 595 input.addEventListener('click', function(event) { |
510 if (input.checked) | 596 if (input.checked) |
511 this.selectionModel.selectAll(); | 597 this.selectionModel.selectAll(); |
512 else | 598 else |
513 this.selectionModel.unselectAll(); | 599 this.selectionModel.unselectAll(); |
514 event.stopPropagation(); | 600 event.stopPropagation(); |
515 }.bind(this)); | 601 }.bind(this)); |
516 | 602 |
517 var fragment = this.ownerDocument.createDocumentFragment(); | 603 var fragment = this.ownerDocument.createDocumentFragment(); |
518 fragment.appendChild(input); | 604 fragment.appendChild(input); |
519 fragment.appendChild(this.ownerDocument.createTextNode(name)); | 605 fragment.appendChild(this.ownerDocument.createTextNode(name)); |
520 return fragment; | 606 return fragment; |
521 }; | 607 }; |
522 | 608 |
523 /** | 609 /** |
610 * Renders the selection column header. | |
611 * @param {string} name Localized column name. | |
612 * @return {HTMLLiElement} Created element. | |
613 * @private | |
614 */ | |
615 FileTable.prototype.renderSelectionColumnHeader_ = function(name) { | |
616 if (!this.selectionModel.multiple) | |
617 return this.ownerDocument.createTextNode(''); | |
618 | |
619 var input = this.ownerDocument.createElement('input'); | |
620 input.setAttribute('type', 'checkbox'); | |
621 input.setAttribute('tabindex', -1); | |
622 input.id = 'select-all-checkbox'; | |
623 input.className = 'common'; | |
624 | |
625 this.updateSelectAllCheckboxState_(input); | |
626 | |
627 input.addEventListener('click', function(event) { | |
628 if (input.checked) | |
629 this.selectionModel.selectAll(); | |
630 else | |
631 this.selectionModel.unselectAll(); | |
632 event.stopPropagation(); | |
633 }.bind(this)); | |
634 | |
635 var fragment = this.ownerDocument.createDocumentFragment(); | |
636 fragment.appendChild(input); | |
637 return fragment; | |
638 }; | |
639 | |
640 /** | |
524 * Render the type column of the detail table. | 641 * Render the type column of the detail table. |
525 * | 642 * |
526 * Invoked by cr.ui.Table when a file needs to be rendered. | 643 * Invoked by cr.ui.Table when a file needs to be rendered. |
527 * | 644 * |
528 * @param {Entry} entry The Entry object to render. | 645 * @param {Entry} entry The Entry object to render. |
529 * @param {string} columnId The id of the column to be rendered. | 646 * @param {string} columnId The id of the column to be rendered. |
530 * @param {cr.ui.Table} table The table doing the rendering. | 647 * @param {cr.ui.Table} table The table doing the rendering. |
531 * @return {HTMLDivElement} Created element. | 648 * @return {HTMLDivElement} Created element. |
532 * @private | 649 * @private |
533 */ | 650 */ |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 break; | 804 break; |
688 } | 805 } |
689 } | 806 } |
690 if (url) { | 807 if (url) { |
691 iconDiv.style.backgroundImage = 'url(' + url + ')'; | 808 iconDiv.style.backgroundImage = 'url(' + url + ')'; |
692 } else { | 809 } else { |
693 iconDiv.style.backgroundImage = null; | 810 iconDiv.style.backgroundImage = null; |
694 } | 811 } |
695 } | 812 } |
696 }; | 813 }; |
OLD | NEW |