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 /** | 5 /** |
6 * Namespace for utility functions. | 6 * Namespace for utility functions. |
7 */ | 7 */ |
8 var filelist = {}; | 8 var filelist = {}; |
9 | 9 |
10 /** | 10 /** |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 /** | 234 /** |
235 * Inherits from cr.ui.Table. | 235 * Inherits from cr.ui.Table. |
236 */ | 236 */ |
237 FileTable.prototype.__proto__ = cr.ui.Table.prototype; | 237 FileTable.prototype.__proto__ = cr.ui.Table.prototype; |
238 | 238 |
239 /** | 239 /** |
240 * Decorates the element. | 240 * Decorates the element. |
241 * @param {!Element} self Table to decorate. | 241 * @param {!Element} self Table to decorate. |
242 * @param {MetadataCache} metadataCache To retrieve metadata. | 242 * @param {MetadataCache} metadataCache To retrieve metadata. |
243 * @param {VolumeManagerWrapper} volumeManager To retrieve volume info. | 243 * @param {VolumeManagerWrapper} volumeManager To retrieve volume info. |
244 * @param {!importer.HistoryLoader} historyLoader | |
244 * @param {boolean} fullPage True if it's full page File Manager, | 245 * @param {boolean} fullPage True if it's full page File Manager, |
245 * False if a file open/save dialog. | 246 * False if a file open/save dialog. |
246 */ | 247 */ |
247 FileTable.decorate = function(self, metadataCache, volumeManager, fullPage) { | 248 FileTable.decorate = |
249 function(self, metadataCache, volumeManager, historyLoader, fullPage) { | |
248 cr.ui.Table.decorate(self); | 250 cr.ui.Table.decorate(self); |
249 self.__proto__ = FileTable.prototype; | 251 self.__proto__ = FileTable.prototype; |
250 self.metadataCache_ = metadataCache; | 252 self.metadataCache_ = metadataCache; |
251 self.volumeManager_ = volumeManager; | 253 self.volumeManager_ = volumeManager; |
254 self.historyLoader_ = historyLoader; | |
252 | 255 |
253 var columns = [ | 256 var columns = [ |
254 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), | 257 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), |
255 fullPage ? 386 : 324), | 258 fullPage ? 386 : 324), |
256 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), | 259 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), |
257 110, true), | 260 110, true), |
261 new cr.ui.table.TableColumn('status', str('STATUS_COLUMN_LABEL'), | |
262 20, true), | |
258 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'), | 263 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'), |
259 fullPage ? 110 : 110), | 264 fullPage ? 110 : 110), |
260 new cr.ui.table.TableColumn('modificationTime', | 265 new cr.ui.table.TableColumn('modificationTime', |
261 str('DATE_COLUMN_LABEL'), | 266 str('DATE_COLUMN_LABEL'), |
262 fullPage ? 150 : 210) | 267 fullPage ? 150 : 210) |
263 ]; | 268 ]; |
264 | 269 |
265 columns[0].renderFunction = self.renderName_.bind(self); | 270 columns[0].renderFunction = self.renderName_.bind(self); |
266 columns[1].renderFunction = self.renderSize_.bind(self); | 271 columns[1].renderFunction = self.renderSize_.bind(self); |
267 columns[1].defaultOrder = 'desc'; | 272 columns[1].defaultOrder = 'desc'; |
268 columns[2].renderFunction = self.renderType_.bind(self); | 273 columns[2].renderFunction = self.renderStatus_.bind(self); |
269 columns[3].renderFunction = self.renderDate_.bind(self); | 274 columns[3].renderFunction = self.renderType_.bind(self); |
270 columns[3].defaultOrder = 'desc'; | 275 columns[4].renderFunction = self.renderDate_.bind(self); |
276 columns[4].defaultOrder = 'desc'; | |
271 | 277 |
272 var columnModel = new FileTableColumnModel(columns); | 278 var columnModel = new FileTableColumnModel(columns); |
273 | 279 |
274 self.columnModel = columnModel; | 280 self.columnModel = columnModel; |
275 self.setDateTimeFormat(true); | 281 self.setDateTimeFormat(true); |
276 self.setRenderFunction(self.renderTableRow_.bind(self, | 282 self.setRenderFunction(self.renderTableRow_.bind(self, |
277 self.getRenderFunction())); | 283 self.getRenderFunction())); |
278 | 284 |
279 self.scrollBar_ = new MainPanelScrollBar(); | 285 self.scrollBar_ = new MainPanelScrollBar(); |
280 self.scrollBar_.initialize(self, self.list); | 286 self.scrollBar_.initialize(self, self.list); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 } else if (externalProps.hosted) { | 516 } else if (externalProps.hosted) { |
511 div.textContent = '--'; | 517 div.textContent = '--'; |
512 return; | 518 return; |
513 } | 519 } |
514 } | 520 } |
515 | 521 |
516 div.textContent = util.bytesToString(filesystemProps.size); | 522 div.textContent = util.bytesToString(filesystemProps.size); |
517 }; | 523 }; |
518 | 524 |
519 /** | 525 /** |
526 * Render the Status column of the detail table. | |
527 * | |
528 * @param {Entry} entry The Entry object to render. | |
529 * @param {string} columnId The id of the column to be rendered. | |
530 * @param {cr.ui.Table} table The table doing the rendering. | |
531 * @return {!HTMLDivElement} Created element. | |
532 * @private | |
533 */ | |
534 FileTable.prototype.renderStatus_ = function(entry, columnId, table) { | |
535 var div = /** @type {!HTMLDivElement} */ ( | |
536 this.ownerDocument.createElement('div')); | |
537 div.className = 'status'; | |
538 if (entry) { | |
539 this.updateStatus_(div, entry); | |
540 } | |
541 | |
542 return div; | |
543 }; | |
544 | |
545 /** | |
546 * Returns the status of the entry w.r.t. the given import destination. | |
547 * @param {!Entry} entry | |
548 * @param {!importer.Destination} destination | |
549 * @return {!Promise<string>} The import status - will be 'imported', 'copied', | |
550 * or 'unknown'. | |
551 */ | |
552 FileTable.prototype.getImportStatus_ = function(entry, destination) { | |
553 if (!entry.isFile) { | |
554 // Our import history doesn't deal with directories. | |
555 // TODO(kenobi): May need to revisit this if the above assumption changes. | |
556 return Promise.resolve('unknown'); | |
557 } | |
558 // For the compiler. | |
559 var fileEntry = /** @type {!FileEntry} */ (entry); | |
560 | |
561 return this.historyLoader_.getHistory() | |
562 .then( | |
563 /** @param {!importer.ImportHistory} history */ | |
564 function(history) { | |
565 return Promise.all([ | |
566 history.wasImported(fileEntry, destination), | |
567 history.wasCopied(fileEntry, destination) | |
568 ]); | |
569 }) | |
570 .then( | |
571 /** @param {!Array<boolean>} status */ | |
572 function(status) { | |
573 if (status[0]) { | |
574 return 'imported'; | |
575 } else if (status[1]) { | |
576 return 'copied'; | |
577 } else { | |
578 return 'unknown'; | |
579 } | |
580 }); | |
581 }; | |
582 | |
583 /** | |
584 * Render the status icon of the detail table. | |
585 * | |
586 * @param {!HTMLDivElement} div | |
587 * @param {!Entry} entry The Entry object to render. | |
588 * @private | |
589 */ | |
590 FileTable.prototype.updateStatus_ = function(div, entry) { | |
591 var icon = /** @type {!HTMLDivElement} */ | |
592 (this.ownerDocument.createElement('div')); | |
593 icon.className = 'status-icon'; | |
594 div.appendChild(icon); | |
595 | |
596 this.getImportStatus_(entry, importer.Destination.GOOGLE_DRIVE).then( | |
597 /** @param {string} status */ | |
598 function(status) { | |
599 icon.setAttribute('file-status-icon', status); | |
600 }); | |
601 }; | |
602 | |
603 /** | |
520 * Render the Type column of the detail table. | 604 * Render the Type column of the detail table. |
521 * | 605 * |
522 * @param {Entry} entry The Entry object to render. | 606 * @param {Entry} entry The Entry object to render. |
523 * @param {string} columnId The id of the column to be rendered. | 607 * @param {string} columnId The id of the column to be rendered. |
524 * @param {cr.ui.Table} table The table doing the rendering. | 608 * @param {cr.ui.Table} table The table doing the rendering. |
525 * @return {!HTMLDivElement} Created element. | 609 * @return {!HTMLDivElement} Created element. |
526 * @private | 610 * @private |
527 */ | 611 */ |
528 FileTable.prototype.renderType_ = function(entry, columnId, table) { | 612 FileTable.prototype.renderType_ = function(entry, columnId, table) { |
529 var div = /** @type {!HTMLDivElement} */ | 613 var div = /** @type {!HTMLDivElement} */ |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 * Updates the file metadata in the table item. | 679 * Updates the file metadata in the table item. |
596 * | 680 * |
597 * @param {Element} item Table item. | 681 * @param {Element} item Table item. |
598 * @param {Entry} entry File entry. | 682 * @param {Entry} entry File entry. |
599 */ | 683 */ |
600 FileTable.prototype.updateFileMetadata = function(item, entry) { | 684 FileTable.prototype.updateFileMetadata = function(item, entry) { |
601 this.updateDate_( | 685 this.updateDate_( |
602 /** @type {!HTMLDivElement} */ (item.querySelector('.date')), entry); | 686 /** @type {!HTMLDivElement} */ (item.querySelector('.date')), entry); |
603 this.updateSize_( | 687 this.updateSize_( |
604 /** @type {!HTMLDivElement} */ (item.querySelector('.size')), entry); | 688 /** @type {!HTMLDivElement} */ (item.querySelector('.size')), entry); |
689 this.updateStatus_( | |
690 /** @type {!HTMLDivElement} */ (item.querySelector('.status')), entry); | |
605 }; | 691 }; |
606 | 692 |
607 /** | 693 /** |
608 * Updates list items 'in place' on metadata change. | 694 * Updates list items 'in place' on metadata change. |
609 * @param {string} type Type of metadata change. | 695 * @param {string} type Type of metadata change. |
610 * @param {Array.<Entry>} entries Entries to update. | 696 * @param {Array.<Entry>} entries Entries to update. |
611 */ | 697 */ |
612 FileTable.prototype.updateListItemsMetadata = function(type, entries) { | 698 FileTable.prototype.updateListItemsMetadata = function(type, entries) { |
613 var urls = util.entriesToURLs(entries); | 699 var urls = util.entriesToURLs(entries); |
614 var forEachCell = function(selector, callback) { | 700 var forEachCell = function(selector, callback) { |
(...skipping 12 matching lines...) Expand all Loading... | |
627 }); | 713 }); |
628 forEachCell('.table-row-cell > .size', function(item, entry, unused) { | 714 forEachCell('.table-row-cell > .size', function(item, entry, unused) { |
629 this.updateSize_(item, entry); | 715 this.updateSize_(item, entry); |
630 }); | 716 }); |
631 } else if (type === 'external') { | 717 } else if (type === 'external') { |
632 // The cell name does not matter as the entire list item is needed. | 718 // The cell name does not matter as the entire list item is needed. |
633 forEachCell('.table-row-cell > .date', function(item, entry, listItem) { | 719 forEachCell('.table-row-cell > .date', function(item, entry, listItem) { |
634 var props = this.metadataCache_.getCached(entry, 'external'); | 720 var props = this.metadataCache_.getCached(entry, 'external'); |
635 filelist.updateListItemExternalProps(listItem, props); | 721 filelist.updateListItemExternalProps(listItem, props); |
636 }); | 722 }); |
723 } else if (type === 'import-history') { | |
mtomasz
2015/01/14 00:34:34
Is it method ever called with this type?
Ben Kwa
2015/01/14 16:19:34
Yes, code was added to the FileManager to call thi
| |
724 forEachCell('.table-row-cell > .status', function(item, entry, unused) { | |
725 this.updateStatus_(item, entry); | |
726 }); | |
637 } | 727 } |
638 }; | 728 }; |
639 | 729 |
640 /** | 730 /** |
641 * Renders table row. | 731 * Renders table row. |
642 * @param {function(Entry, cr.ui.Table)} baseRenderFunction Base renderer. | 732 * @param {function(Entry, cr.ui.Table)} baseRenderFunction Base renderer. |
643 * @param {Entry} entry Corresponding entry. | 733 * @param {Entry} entry Corresponding entry. |
644 * @return {HTMLLIElement} Created element. | 734 * @return {HTMLLIElement} Created element. |
645 * @private | 735 * @private |
646 */ | 736 */ |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 return; | 866 return; |
777 | 867 |
778 if (externalProps.customIconUrl) | 868 if (externalProps.customIconUrl) |
779 iconDiv.style.backgroundImage = 'url(' + externalProps.customIconUrl + ')'; | 869 iconDiv.style.backgroundImage = 'url(' + externalProps.customIconUrl + ')'; |
780 else | 870 else |
781 iconDiv.style.backgroundImage = ''; // Back to the default image. | 871 iconDiv.style.backgroundImage = ''; // Back to the default image. |
782 | 872 |
783 if (li.classList.contains('directory')) | 873 if (li.classList.contains('directory')) |
784 iconDiv.classList.toggle('shared', externalProps.shared); | 874 iconDiv.classList.toggle('shared', externalProps.shared); |
785 }; | 875 }; |
OLD | NEW |