Merge pull request #18310 from hasso/selection-string-fix

Fix the string counting a selected files/dirs
This commit is contained in:
Vincent Petry 2015-08-18 10:43:17 +02:00
commit ffff156965
2 changed files with 18 additions and 10 deletions

View File

@ -1930,6 +1930,8 @@
updateSelectionSummary: function() { updateSelectionSummary: function() {
var summary = this._selectionSummary.summary; var summary = this._selectionSummary.summary;
var canDelete; var canDelete;
var selection;
if (summary.totalFiles === 0 && summary.totalDirs === 0) { if (summary.totalFiles === 0 && summary.totalDirs === 0) {
this.$el.find('#headerName a.name>span:first').text(t('files','Name')); this.$el.find('#headerName a.name>span:first').text(t('files','Name'));
this.$el.find('#headerSize a>span:first').text(t('files','Size')); this.$el.find('#headerSize a>span:first').text(t('files','Size'));
@ -1941,16 +1943,22 @@
canDelete = (this.getDirectoryPermissions() & OC.PERMISSION_DELETE) && this.isSelectedDeletable(); canDelete = (this.getDirectoryPermissions() & OC.PERMISSION_DELETE) && this.isSelectedDeletable();
this.$el.find('.selectedActions').removeClass('hidden'); this.$el.find('.selectedActions').removeClass('hidden');
this.$el.find('#headerSize a>span:first').text(OC.Util.humanFileSize(summary.totalSize)); this.$el.find('#headerSize a>span:first').text(OC.Util.humanFileSize(summary.totalSize));
var selection = '';
if (summary.totalDirs > 0) { var directoryInfo = n('files', '%n folder', '%n folders', summary.totalDirs);
selection += n('files', '%n folder', '%n folders', summary.totalDirs); var fileInfo = n('files', '%n file', '%n files', summary.totalFiles);
if (summary.totalFiles > 0) {
selection += ' & '; if (summary.totalDirs > 0 && summary.totalFiles > 0) {
} var selectionVars = {
} dirs: directoryInfo,
if (summary.totalFiles > 0) { files: fileInfo
selection += n('files', '%n file', '%n files', summary.totalFiles); };
selection = t('files', '{dirs} and {files}', selectionVars);
} else if (summary.totalDirs > 0) {
selection = directoryInfo;
} else {
selection = fileInfo;
} }
this.$el.find('#headerName a.name>span:first').text(selection); this.$el.find('#headerName a.name>span:first').text(selection);
this.$el.find('#modified a>span:first').text(''); this.$el.find('#modified a>span:first').text('');
this.$el.find('table').addClass('multiselect'); this.$el.find('table').addClass('multiselect');

View File

@ -1606,7 +1606,7 @@ describe('OCA.Files.FileList tests', function() {
fileList.findFileEl('One.txt').find('input:checkbox').click(); fileList.findFileEl('One.txt').find('input:checkbox').click();
fileList.findFileEl('Three.pdf').find('input:checkbox').click(); fileList.findFileEl('Three.pdf').find('input:checkbox').click();
fileList.findFileEl('somedir').find('input:checkbox').click(); fileList.findFileEl('somedir').find('input:checkbox').click();
expect($summary.text()).toEqual('1 folder & 2 files'); expect($summary.text()).toEqual('1 folder and 2 files');
}); });
it('Unselecting files hides selection summary', function() { it('Unselecting files hides selection summary', function() {
var $summary = $('#headerName a.name>span:first'); var $summary = $('#headerName a.name>span:first');