Commit ac1df3e3 authored by serya@chromium.org's avatar serya@chromium.org

Disabling "Select all" chechbox when the dir is empty.

BUG=chromium-os:20156
TEST=None


Review URL: http://codereview.chromium.org/8788011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112980 0039d316-1c4b-4281-b951-d872f2087c98
parent ff5e9422
...@@ -750,6 +750,9 @@ FileManager.prototype = { ...@@ -750,6 +750,9 @@ FileManager.prototype = {
this.selectionModelClass_ = cr.ui.ListSelectionModel; this.selectionModelClass_ = cr.ui.ListSelectionModel;
} }
this.dataModel_.addEventListener('splice',
this.onDataModelSplice_.bind(this));
this.initTable_(); this.initTable_();
this.initGrid_(); this.initGrid_();
...@@ -853,6 +856,12 @@ FileManager.prototype = { ...@@ -853,6 +856,12 @@ FileManager.prototype = {
setTimeout(function() { successCallback(entry) }, 0); setTimeout(function() { successCallback(entry) }, 0);
}; };
FileManager.prototype.onDataModelSplice_ = function(event) {
var checkbox = this.document_.querySelector('#select-all-checkbox');
if (checkbox)
this.updateSelectAllCheckboxState_(checkbox);
};
/** /**
* Get the file type of the entry, caching the result. * Get the file type of the entry, caching the result.
* *
...@@ -1560,14 +1569,13 @@ FileManager.prototype = { ...@@ -1560,14 +1569,13 @@ FileManager.prototype = {
input.setAttribute('type', 'checkbox'); input.setAttribute('type', 'checkbox');
input.setAttribute('tabindex', -1); input.setAttribute('tabindex', -1);
input.id = 'select-all-checkbox'; input.id = 'select-all-checkbox';
input.checked = this.areAllItemsSelected(); this.updateSelectAllCheckboxState_(input);
var self = this;
input.addEventListener('click', function(event) { input.addEventListener('click', function(event) {
if (self.areAllItemsSelected()) if (input.checked)
table.selectionModel.unselectAll();
else
table.selectionModel.selectAll(); table.selectionModel.selectAll();
else
table.selectionModel.unselectAll();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
}); });
...@@ -1579,12 +1587,12 @@ FileManager.prototype = { ...@@ -1579,12 +1587,12 @@ FileManager.prototype = {
}; };
/** /**
* Check if all items in the current list are selected. * Update check and disable states of the 'Select all' checkbox.
* @return {boolean} True if all items are selected.
*/ */
FileManager.prototype.areAllItemsSelected = function() { FileManager.prototype.updateSelectAllCheckboxState_ = function(checkbox) {
return this.selection && this.dataModel_.length > 0 && checkbox.checked = this.selection && this.dataModel_.length > 0 &&
this.dataModel_.length == this.selection.totalCount; this.dataModel_.length == this.selection.totalCount;
checkbox.disabled = this.dataModel_.length == 0;
}; };
/** /**
...@@ -2941,7 +2949,7 @@ FileManager.prototype = { ...@@ -2941,7 +2949,7 @@ FileManager.prototype = {
var selectAllCheckbox = var selectAllCheckbox =
this.document_.getElementById('select-all-checkbox'); this.document_.getElementById('select-all-checkbox');
if (selectAllCheckbox) if (selectAllCheckbox)
selectAllCheckbox.checked = this.areAllItemsSelected(); this.updateSelectAllCheckboxState_(selectAllCheckbox);
}; };
FileManager.prototype.updateOkButton_ = function(event) { FileManager.prototype.updateOkButton_ = function(event) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment