Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 8720006: Moving file selection checkbox to the field name. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review fix. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we 5 // Setting the src of an img to an empty string can crash the browser, so we
6 // use an empty 1x1 gif instead. 6 // use an empty 1x1 gif instead.
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,'
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D';
9 9
10 var g_slideshow_data = null; 10 var g_slideshow_data = null;
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 new cr.ui.table.TableColumn('cachedMtime_', 1157 new cr.ui.table.TableColumn('cachedMtime_',
1158 str('DATE_COLUMN_LABEL'), 21) 1158 str('DATE_COLUMN_LABEL'), 21)
1159 ]; 1159 ];
1160 1160
1161 columns[0].renderFunction = this.renderName_.bind(this); 1161 columns[0].renderFunction = this.renderName_.bind(this);
1162 columns[1].renderFunction = this.renderSize_.bind(this); 1162 columns[1].renderFunction = this.renderSize_.bind(this);
1163 columns[2].renderFunction = this.renderType_.bind(this); 1163 columns[2].renderFunction = this.renderType_.bind(this);
1164 columns[3].renderFunction = this.renderDate_.bind(this); 1164 columns[3].renderFunction = this.renderDate_.bind(this);
1165 1165
1166 if (this.showCheckboxes_) { 1166 if (this.showCheckboxes_) {
1167 columns.unshift(new cr.ui.table.TableColumn('checkbox_', '', 3.6));
1168 columns[0].renderFunction = this.renderCheckbox_.bind(this);
1169 columns[0].headerRenderFunction = 1167 columns[0].headerRenderFunction =
1170 this.renderCheckboxColumnHeader_.bind(this); 1168 this.renderNameColumnHeader_.bind(this, columns[0].name);
1171 } 1169 }
1172 1170
1173 this.table_ = this.dialogDom_.querySelector('.detail-table'); 1171 this.table_ = this.dialogDom_.querySelector('.detail-table');
1174 cr.ui.Table.decorate(this.table_); 1172 cr.ui.Table.decorate(this.table_);
1175 1173
1176 this.table_.selectionModel = new this.selectionModelClass_(); 1174 this.table_.selectionModel = new this.selectionModelClass_();
1177 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); 1175 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns);
1178 1176
1179 this.table_.addEventListener( 1177 this.table_.addEventListener(
1180 'dblclick', this.onDetailDoubleClick_.bind(this)); 1178 'dblclick', this.onDetailDoubleClick_.bind(this));
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 if (this.selection && this.selection.entries.indexOf(entry) != -1) { 1544 if (this.selection && this.selection.entries.indexOf(entry) != -1) {
1547 // Our DOM nodes get discarded as soon as we're scrolled out of view, 1545 // Our DOM nodes get discarded as soon as we're scrolled out of view,
1548 // so we have to make sure the check state is correct when we're brought 1546 // so we have to make sure the check state is correct when we're brought
1549 // back to life. 1547 // back to life.
1550 input.checked = true; 1548 input.checked = true;
1551 } 1549 }
1552 1550
1553 return input; 1551 return input;
1554 }; 1552 };
1555 1553
1556 FileManager.prototype.renderCheckboxColumnHeader_ = function(table) { 1554 FileManager.prototype.renderNameColumnHeader_ = function(name, table) {
1557 var input = this.document_.createElement('input'); 1555 var input = this.document_.createElement('input');
1558 input.setAttribute('type', 'checkbox'); 1556 input.setAttribute('type', 'checkbox');
1559 input.setAttribute('tabindex', -1); 1557 input.setAttribute('tabindex', -1);
1560 input.id = 'select-all-checkbox'; 1558 input.id = 'select-all-checkbox';
1561 input.checked = this.areAllItemsSelected(); 1559 input.checked = this.areAllItemsSelected();
1562 1560
1563 var self = this; 1561 var self = this;
1564 input.addEventListener('click', function(event) { 1562 input.addEventListener('click', function(event) {
1565 if (self.areAllItemsSelected()) 1563 if (self.areAllItemsSelected())
1566 table.selectionModel.unselectAll(); 1564 table.selectionModel.unselectAll();
1567 else 1565 else
1568 table.selectionModel.selectAll(); 1566 table.selectionModel.selectAll();
1569 event.preventDefault(); 1567 event.preventDefault();
1568 event.stopPropagation();
1570 }); 1569 });
1571 1570
1572 return input; 1571 var fragment = this.document_.createDocumentFragment();
1572 fragment.appendChild(input);
1573 fragment.appendChild(this.document_.createTextNode(name));
1574 return fragment;
1573 }; 1575 };
1574 1576
1575 /** 1577 /**
1576 * Check if all items in the current list are selected. 1578 * Check if all items in the current list are selected.
1577 * @return {boolean} True if all items are selected. 1579 * @return {boolean} True if all items are selected.
1578 */ 1580 */
1579 FileManager.prototype.areAllItemsSelected = function() { 1581 FileManager.prototype.areAllItemsSelected = function() {
1580 return this.selection && 1582 return this.selection && this.dataModel_.length > 0 &&
1581 this.dataModel_.length == this.selection.totalCount; 1583 this.dataModel_.length == this.selection.totalCount;
1582 }; 1584 };
1583 1585
1584 /** 1586 /**
1585 * Update the thumbnail image to fit/fill the square container. 1587 * Update the thumbnail image to fit/fill the square container.
1586 * 1588 *
1587 * Using webkit center packing does not align the image properly, so we need 1589 * Using webkit center packing does not align the image properly, so we need
1588 * to wait until the image loads and its proportions are known, then manually 1590 * to wait until the image loads and its proportions are known, then manually
1589 * position it at the center. 1591 * position it at the center.
1590 * 1592 *
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 /** 1681 /**
1680 * Render the type column of the detail table. 1682 * Render the type column of the detail table.
1681 * 1683 *
1682 * Invoked by cr.ui.Table when a file needs to be rendered. 1684 * Invoked by cr.ui.Table when a file needs to be rendered.
1683 * 1685 *
1684 * @param {Entry} entry The Entry object to render. 1686 * @param {Entry} entry The Entry object to render.
1685 * @param {string} columnId The id of the column to be rendered. 1687 * @param {string} columnId The id of the column to be rendered.
1686 * @param {cr.ui.Table} table The table doing the rendering. 1688 * @param {cr.ui.Table} table The table doing the rendering.
1687 */ 1689 */
1688 FileManager.prototype.renderIconType_ = function(entry, columnId, table) { 1690 FileManager.prototype.renderIconType_ = function(entry, columnId, table) {
1689 var div = this.document_.createElement('div');
1690 div.className = 'detail-icon-container';
1691
1692 var icon = this.document_.createElement('div'); 1691 var icon = this.document_.createElement('div');
1693 icon.className = 'detail-icon'; 1692 icon.className = 'detail-icon';
1694 this.getIconType(entry); 1693 this.getIconType(entry);
1695 icon.setAttribute('iconType', entry.cachedIconType_); 1694 icon.setAttribute('iconType', entry.cachedIconType_);
1696 div.appendChild(icon); 1695 return icon;
1697
1698 return div;
1699 }; 1696 };
1700 1697
1701 FileManager.prototype.getLabelForRootPath_ = function(path) { 1698 FileManager.prototype.getLabelForRootPath_ = function(path) {
1702 // This hack lets us localize the top level directories. 1699 // This hack lets us localize the top level directories.
1703 if (path == 'Downloads') 1700 if (path == 'Downloads')
1704 return str('DOWNLOADS_DIRECTORY_LABEL'); 1701 return str('DOWNLOADS_DIRECTORY_LABEL');
1705 1702
1706 if (path == 'archive') 1703 if (path == 'archive')
1707 return str('ARCHIVE_DIRECTORY_LABEL'); 1704 return str('ARCHIVE_DIRECTORY_LABEL');
1708 1705
1709 if (path == 'removable') 1706 if (path == 'removable')
1710 return str('REMOVABLE_DIRECTORY_LABEL'); 1707 return str('REMOVABLE_DIRECTORY_LABEL');
1711 1708
1712 return path || str('ROOT_DIRECTORY_LABEL'); 1709 return path || str('ROOT_DIRECTORY_LABEL');
1713 }; 1710 };
1714 1711
1715 /** 1712 /**
1716 * Render the Name column of the detail table. 1713 * Render the Name column of the detail table.
1717 * 1714 *
1718 * Invoked by cr.ui.Table when a file needs to be rendered. 1715 * Invoked by cr.ui.Table when a file needs to be rendered.
1719 * 1716 *
1720 * @param {Entry} entry The Entry object to render. 1717 * @param {Entry} entry The Entry object to render.
1721 * @param {string} columnId The id of the column to be rendered. 1718 * @param {string} columnId The id of the column to be rendered.
1722 * @param {cr.ui.Table} table The table doing the rendering. 1719 * @param {cr.ui.Table} table The table doing the rendering.
1723 */ 1720 */
1724 FileManager.prototype.renderName_ = function(entry, columnId, table) { 1721 FileManager.prototype.renderName_ = function(entry, columnId, table) {
1725 var label = this.document_.createElement('div'); 1722 var label = this.document_.createElement('div');
1723 if (this.showCheckboxes_)
1724 label.appendChild(this.renderCheckbox_(entry));
1726 label.appendChild(this.renderIconType_(entry, columnId, table)); 1725 label.appendChild(this.renderIconType_(entry, columnId, table));
1727 label.entry = entry; 1726 label.entry = entry;
1728 label.className = 'detail-name filename-label'; 1727 label.className = 'detail-name';
1729 if (this.currentDirEntry_.name == '') { 1728 if (this.currentDirEntry_.name == '') {
1730 label.appendChild(this.document_.createTextNode( 1729 label.appendChild(this.document_.createTextNode(
1731 this.getLabelForRootPath_(entry.name))); 1730 this.getLabelForRootPath_(entry.name)));
1732 } else { 1731 } else {
1733 label.appendChild(this.document_.createTextNode(entry.name)); 1732 label.appendChild(this.document_.createTextNode(entry.name));
1734 } 1733 }
1735 1734
1736 return label; 1735 return label;
1737 }; 1736 };
1738 1737
1739 /** 1738 /**
1740 * Render the Size column of the detail table. 1739 * Render the Size column of the detail table.
1741 * 1740 *
1742 * @param {Entry} entry The Entry object to render. 1741 * @param {Entry} entry The Entry object to render.
1743 * @param {string} columnId The id of the column to be rendered. 1742 * @param {string} columnId The id of the column to be rendered.
1744 * @param {cr.ui.Table} table The table doing the rendering. 1743 * @param {cr.ui.Table} table The table doing the rendering.
1745 */ 1744 */
1746 FileManager.prototype.renderSize_ = function(entry, columnId, table) { 1745 FileManager.prototype.renderSize_ = function(entry, columnId, table) {
1747 var div = this.document_.createElement('div'); 1746 var div = this.document_.createElement('div');
1748 div.className = 'detail-size';
1749 1747
1750 div.textContent = '...'; 1748 div.textContent = '...';
1751 cacheEntrySize(entry, function(entry) { 1749 cacheEntrySize(entry, function(entry) {
1752 if (entry.cachedSize_ == -1) { 1750 if (entry.cachedSize_ == -1) {
1753 div.textContent = ''; 1751 div.textContent = '';
1754 } else { 1752 } else {
1755 div.textContent = util.bytesToSi(entry.cachedSize_); 1753 div.textContent = util.bytesToSi(entry.cachedSize_);
1756 } 1754 }
1757 }, null, true); 1755 }, null, true);
1758 1756
1759 return div; 1757 return div;
1760 }; 1758 };
1761 1759
1762 /** 1760 /**
1763 * Render the Type column of the detail table. 1761 * Render the Type column of the detail table.
1764 * 1762 *
1765 * @param {Entry} entry The Entry object to render. 1763 * @param {Entry} entry The Entry object to render.
1766 * @param {string} columnId The id of the column to be rendered. 1764 * @param {string} columnId The id of the column to be rendered.
1767 * @param {cr.ui.Table} table The table doing the rendering. 1765 * @param {cr.ui.Table} table The table doing the rendering.
1768 */ 1766 */
1769 FileManager.prototype.renderType_ = function(entry, columnId, table) { 1767 FileManager.prototype.renderType_ = function(entry, columnId, table) {
1770 var div = this.document_.createElement('div'); 1768 var div = this.document_.createElement('div');
1771 div.className = 'detail-type';
1772 1769
1773 this.cacheEntryFileType(entry, function(entry) { 1770 this.cacheEntryFileType(entry, function(entry) {
1774 var info = entry.cachedFileType_; 1771 var info = entry.cachedFileType_;
1775 if (info.name) { 1772 if (info.name) {
1776 if (info.subtype) 1773 if (info.subtype)
1777 div.textContent = strf(info.name, info.subtype); 1774 div.textContent = strf(info.name, info.subtype);
1778 else 1775 else
1779 div.textContent = str(info.name); 1776 div.textContent = str(info.name);
1780 } else 1777 } else
1781 div.textContent = ''; 1778 div.textContent = '';
1782 }, true); 1779 }, true);
1783 1780
1784 return div; 1781 return div;
1785 }; 1782 };
1786 1783
1787 /** 1784 /**
1788 * Render the Date column of the detail table. 1785 * Render the Date column of the detail table.
1789 * 1786 *
1790 * @param {Entry} entry The Entry object to render. 1787 * @param {Entry} entry The Entry object to render.
1791 * @param {string} columnId The id of the column to be rendered. 1788 * @param {string} columnId The id of the column to be rendered.
1792 * @param {cr.ui.Table} table The table doing the rendering. 1789 * @param {cr.ui.Table} table The table doing the rendering.
1793 */ 1790 */
1794 FileManager.prototype.renderDate_ = function(entry, columnId, table) { 1791 FileManager.prototype.renderDate_ = function(entry, columnId, table) {
1795 var div = this.document_.createElement('div'); 1792 var div = this.document_.createElement('div');
1796 div.className = 'detail-date';
1797 1793
1798 div.textContent = '...'; 1794 div.textContent = '...';
1799 1795
1800 var self = this; 1796 var self = this;
1801 cacheEntryDate(entry, function(entry) { 1797 cacheEntryDate(entry, function(entry) {
1802 if (isSystemDirEntry(self.currentDirEntry_) && 1798 if (isSystemDirEntry(self.currentDirEntry_) &&
1803 entry.cachedMtime_.getTime() == 0) { 1799 entry.cachedMtime_.getTime() == 0) {
1804 // Mount points for FAT volumes have this time associated with them. 1800 // Mount points for FAT volumes have this time associated with them.
1805 // We'd rather display nothing than this bogus date. 1801 // We'd rather display nothing than this bogus date.
1806 div.textContent = ''; 1802 div.textContent = '';
(...skipping 2153 matching lines...) Expand 10 before | Expand all | Expand 10 after
3960 }); 3956 });
3961 }, onError); 3957 }, onError);
3962 3958
3963 function onError(err) { 3959 function onError(err) {
3964 console.log('Error while checking free space: ' + err); 3960 console.log('Error while checking free space: ' + err);
3965 setTimeout(doCheck, 1000 * 60); 3961 setTimeout(doCheck, 1000 * 60);
3966 } 3962 }
3967 } 3963 }
3968 } 3964 }
3969 })(); 3965 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/css/file_manager.css ('k') | chrome/browser/resources/file_manager/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698