Add expand/collapse all feature in drive tree

pull/1/head
ClemDee 6 years ago
parent 73c2964241
commit 634b051d42

@ -383,6 +383,8 @@
"fc_rename": "Renommer", "fc_rename": "Renommer",
"fc_open": "Ouvrir", "fc_open": "Ouvrir",
"fc_open_ro": "Ouvrir (lecture seule)", "fc_open_ro": "Ouvrir (lecture seule)",
"fc_expandAll": "Développer tout",
"fc_collapseAll": "Réduire tout",
"fc_delete": "Déplacer vers la corbeille", "fc_delete": "Déplacer vers la corbeille",
"fc_delete_owned": "Supprimer du serveur", "fc_delete_owned": "Supprimer du serveur",
"fc_restore": "Restaurer", "fc_restore": "Restaurer",

@ -387,6 +387,8 @@
"fc_rename": "Rename", "fc_rename": "Rename",
"fc_open": "Open", "fc_open": "Open",
"fc_open_ro": "Open (read-only)", "fc_open_ro": "Open (read-only)",
"fc_expandAll": "Expand All",
"fc_collapseAll": "Collapse All",
"fc_delete": "Move to trash", "fc_delete": "Move to trash",
"fc_delete_owned": "Delete from the server", "fc_delete_owned": "Delete from the server",
"fc_restore": "Restore", "fc_restore": "Restore",

@ -293,6 +293,14 @@ define([
'tabindex': '-1', 'tabindex': '-1',
'data-icon': faReadOnly, 'data-icon': faReadOnly,
}, Messages.fc_open_ro)), }, Messages.fc_open_ro)),
h('li', h('a.cp-app-drive-context-expandall.dropdown-item', {
'tabindex': '-1',
'data-icon': "expandAll",
}, Messages.fc_expandAll)),
h('li', h('a.cp-app-drive-context-collapseall.dropdown-item', {
'tabindex': '-1',
'data-icon': "collapseAll",
}, Messages.fc_collapseAll)),
h('li', h('a.cp-app-drive-context-download.dropdown-item', { h('li', h('a.cp-app-drive-context-download.dropdown-item', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': faDownload, 'data-icon': faDownload,
@ -878,6 +886,10 @@ define([
paths.forEach(function (p) { paths.forEach(function (p) {
var path = p.path; var path = p.path;
var $element = p.element; var $element = p.element;
if (!$element.closest("#cp-app-drive-tree").length) {
hide.push('expandall');
hide.push('collapseall');
}
if (path.length === 1) { if (path.length === 1) {
// Can't rename or delete root elements // Can't rename or delete root elements
hide.push('delete'); hide.push('delete');
@ -908,6 +920,8 @@ define([
if (containsFolder) { if (containsFolder) {
// More than 1 folder selected: cannot create a new subfolder // More than 1 folder selected: cannot create a new subfolder
hide.push('newfolder'); hide.push('newfolder');
hide.push('expandall');
hide.push('collapseall');
} }
containsFolder = true; containsFolder = true;
hide.push('openro'); hide.push('openro');
@ -918,6 +932,8 @@ define([
if (containsFolder) { if (containsFolder) {
// More than 1 folder selected: cannot create a new subfolder // More than 1 folder selected: cannot create a new subfolder
hide.push('newfolder'); hide.push('newfolder');
hide.push('expandall');
hide.push('collapseall');
} }
containsFolder = true; containsFolder = true;
hide.push('openro'); hide.push('openro');
@ -970,7 +986,7 @@ define([
show = ['newfolder', 'newsharedfolder', 'newdoc']; show = ['newfolder', 'newsharedfolder', 'newdoc'];
break; break;
case 'tree': case 'tree':
show = ['open', 'openro', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', show = ['open', 'openro', 'expandall', 'collapseall', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf',
'newfolder', 'properties', 'hashtag']; 'newfolder', 'properties', 'hashtag'];
break; break;
case 'default': case 'default':
@ -3336,6 +3352,32 @@ define([
openFile(null, href); openFile(null, href);
}); });
} }
else if ($(this).hasClass('cp-app-drive-context-expandall') ||
$(this).hasClass('cp-app-drive-context-collapseall')) {
if (paths.length !== 1) { return; }
var opened = $(this).hasClass('cp-app-drive-context-expandall');
var openRecursive = function (path) {
setFolderOpened(path, opened);
var folderContent = manager.find(path);
var subfolders = [];
for (var k in folderContent) {
if (manager.isFolder(folderContent[k])) {
if (manager.isSharedFolder(folderContent[k])) {
subfolders.push([k].concat(manager.user.userObject.ROOT));
}
else {
subfolders.push(k);
}
}
}
subfolders.forEach(function (p) {
var subPath = path.concat(p);
openRecursive(subPath);
});
};
openRecursive(paths[0].path);
refresh();
}
else if ($(this).hasClass('cp-app-drive-context-download')) { else if ($(this).hasClass('cp-app-drive-context-download')) {
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
el = manager.find(paths[0].path); el = manager.find(paths[0].path);

Loading…
Cancel
Save