Context menu support for multi-select options in drive
parent
e1c02fd8a4
commit
3f7dea8f7e
|
@ -353,24 +353,44 @@ define([
|
|||
},0);
|
||||
};
|
||||
|
||||
var filterContextMenu = function ($menu, $element) {
|
||||
var path = $element.data('path');
|
||||
var filterContextMenu = function ($menu, paths) {
|
||||
//var path = $element.data('path');
|
||||
|
||||
var hide = [];
|
||||
if (!APP.editable) {
|
||||
hide.push($menu.find('a.editable'));
|
||||
}
|
||||
if (!isOwnDrive()) {
|
||||
hide.push($menu.find('a.own'));
|
||||
}
|
||||
if ($element.is('.file-element')) {
|
||||
hide.push($menu.find('a.newfolder'));
|
||||
} else {
|
||||
hide.push($menu.find('a.open_ro'));
|
||||
}
|
||||
if (path && path.length > 4) {
|
||||
var hasFolder = false;
|
||||
paths.forEach(function (p, i) {
|
||||
var path = p.path;
|
||||
var $element = p.element;
|
||||
if (!APP.editable) {
|
||||
hide.push($menu.find('a.editable'));
|
||||
}
|
||||
if (!isOwnDrive()) {
|
||||
hide.push($menu.find('a.own'));
|
||||
}
|
||||
if ($element.is('.file-element')) {
|
||||
// No folder in files
|
||||
hide.push($menu.find('a.newfolder'));
|
||||
} else {
|
||||
if (hasFolder) {
|
||||
// More than 1 folder selected: cannot create a new subfolder
|
||||
hide.push($menu.find('a.newfolder'));
|
||||
}
|
||||
hasFolder = true;
|
||||
hide.push($menu.find('a.open_ro'));
|
||||
}
|
||||
if (path && path.length > 4) {
|
||||
hide.push($menu.find('a.restore'));
|
||||
hide.push($menu.find('a.properties'));
|
||||
}
|
||||
});
|
||||
if (paths.length > 1) {
|
||||
hide.push($menu.find('a.restore'));
|
||||
hide.push($menu.find('a.properties'));
|
||||
hide.push($menu.find('a.rename'));
|
||||
}
|
||||
if (hasFolder && paths.length > 1) {
|
||||
// Cannot open multiple folders
|
||||
hide.push($menu.find('a.open'));
|
||||
}
|
||||
return hide;
|
||||
};
|
||||
|
@ -384,9 +404,35 @@ define([
|
|||
$driveToolbar.find('.path').css('max-width', 'calc(100vw - '+$tree.width()+'px - '+l+'px)');
|
||||
};
|
||||
|
||||
var getSelectedPaths = function ($element) {
|
||||
var paths = [];
|
||||
if ($iframe.find('.selected').length > 1) {
|
||||
var $selected = $iframe.find('.selected');
|
||||
$selected.each(function (idx, elmt) {
|
||||
var ePath = $(elmt).data('path');
|
||||
if (ePath) {
|
||||
paths.push({
|
||||
path: ePath,
|
||||
element: $(elmt)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!paths.length) {
|
||||
var path = $element.data('path');
|
||||
if (!path) { return false; }
|
||||
paths.push({
|
||||
path: path,
|
||||
element: $element
|
||||
});
|
||||
}
|
||||
return paths;
|
||||
};
|
||||
|
||||
var updateContextButton = function () {
|
||||
var $li = $content.find('.selected');
|
||||
if ($li.length !== 1) {
|
||||
if ($li.length === 0) {
|
||||
$li = findDataHolder($tree.find('.element.active'));
|
||||
}
|
||||
var $button = $driveToolbar.find('#contextButton');
|
||||
|
@ -412,13 +458,13 @@ define([
|
|||
var $container = $driveToolbar.find('#contextButtonsContainer');
|
||||
if (!$container.length) { return; }
|
||||
$container.html('');
|
||||
var $element = $li;
|
||||
var $element = $li.length === 1 ? $li : $($li[0]);
|
||||
var paths = getSelectedPaths($element);
|
||||
var $menu = $element.data('context');
|
||||
var path = $element.data('path');
|
||||
if (!$menu || !path) { return; }
|
||||
if (!$menu) { return; }
|
||||
var actions = [];
|
||||
var $actions = $menu.find('a');
|
||||
var toHide = filterContextMenu($menu, $element);
|
||||
var toHide = filterContextMenu($menu, paths);
|
||||
$actions = $actions.filter(function (i, el) {
|
||||
for (var j = 0; j < toHide.length; j++) {
|
||||
if ($(el).is(toHide[j])) { return false; }
|
||||
|
@ -433,8 +479,9 @@ define([
|
|||
} else {
|
||||
$a.text($(el).text());
|
||||
}
|
||||
$(el).data('path', path);
|
||||
$(el).data('element', $element);
|
||||
$(el).data('paths', paths);
|
||||
//$(el).data('path', path);
|
||||
//:$(el).data('element', $element);
|
||||
$container.append($a);
|
||||
$a.click(function() { $(el).click(); });
|
||||
});
|
||||
|
@ -460,6 +507,9 @@ define([
|
|||
$element.removeClass("selected");
|
||||
}
|
||||
updateContextButton();
|
||||
if ($iframe.find('.selected').length > 1) {
|
||||
module.hideMenu();
|
||||
}
|
||||
};
|
||||
|
||||
// Open the selected context menu on the closest "li" element
|
||||
|
@ -475,10 +525,9 @@ define([
|
|||
return false;
|
||||
}
|
||||
|
||||
var path = $element.data('path');
|
||||
if (!path) { return false; }
|
||||
var paths = getSelectedPaths($element);
|
||||
|
||||
var toHide = filterContextMenu($menu, $element);
|
||||
var toHide = filterContextMenu($menu, paths);
|
||||
toHide.forEach(function ($a) {
|
||||
$a.parent('li').hide();
|
||||
});
|
||||
|
@ -495,10 +544,13 @@ define([
|
|||
return true;
|
||||
}
|
||||
|
||||
onElementClick(undefined, $element);
|
||||
if (paths.length === 1) {
|
||||
onElementClick(undefined, $element);
|
||||
}
|
||||
|
||||
$menu.find('a').data('path', path);
|
||||
$menu.find('a').data('element', $element);
|
||||
$menu.find('a').data('paths', paths);
|
||||
//$menu.find('a').data('path', path);
|
||||
//$menu.find('a').data('element', $element);
|
||||
return false;
|
||||
};
|
||||
|
||||
|
@ -515,6 +567,7 @@ define([
|
|||
};
|
||||
|
||||
var openTrashTreeContextMenu = function (e) {
|
||||
removeSelected();
|
||||
$trashTreeContextMenu.find('li').show();
|
||||
openContextMenu(e, $trashTreeContextMenu);
|
||||
return false;
|
||||
|
@ -1690,62 +1743,76 @@ define([
|
|||
|
||||
$contextMenu.on("click", "a", function(e) {
|
||||
e.stopPropagation();
|
||||
var path = $(this).data('path');
|
||||
var $element = $(this).data('element');
|
||||
if (!$element || !path || path.length < 2) {
|
||||
var paths = $(this).data('paths');
|
||||
//var path = $(this).data('path');
|
||||
//var $element = $(this).data('element');
|
||||
if (paths.length === 0) {
|
||||
log(Messages.fm_forbidden);
|
||||
debug("Directory context menu on a forbidden or unexisting element. ", $element, path);
|
||||
debug("Directory context menu on a forbidden or unexisting element. ", paths);
|
||||
return;
|
||||
}
|
||||
if ($(this).hasClass("rename")) {
|
||||
displayRenameInput($element, path);
|
||||
if (paths.length !== 1) { return; }
|
||||
displayRenameInput(paths[0].element, paths[0].path);
|
||||
}
|
||||
else if($(this).hasClass("delete")) {
|
||||
moveElements([path], [TRASH], false, refresh);
|
||||
var pathsList = [];
|
||||
paths.forEach(function (p) { pathsList.push(p.path); });
|
||||
moveElements(pathsList, [TRASH], false, refresh);
|
||||
}
|
||||
else if ($(this).hasClass('open')) {
|
||||
$element.click();
|
||||
$element.dblclick();
|
||||
paths.forEach(function (p) {
|
||||
var $element = p.element;
|
||||
$element.click();
|
||||
$element.dblclick();
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass('open_ro')) {
|
||||
var el = filesOp.findElement(files, path);
|
||||
if (filesOp.isFolder(el)) { return; }
|
||||
var roUrl = getReadOnlyUrl(el);
|
||||
openFile(roUrl);
|
||||
paths.forEach(function (p) {
|
||||
var el = filesOp.findElement(files, p.path);
|
||||
if (filesOp.isFolder(el)) { return; }
|
||||
var roUrl = getReadOnlyUrl(el);
|
||||
openFile(roUrl, false);
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass('newfolder')) {
|
||||
if (paths.length !== 1) { return; }
|
||||
var onCreated = function (info) {
|
||||
module.newFolder = info.newPath;
|
||||
module.displayDirectory(path);
|
||||
};
|
||||
filesOp.createNewFolder(path, null, onCreated);
|
||||
filesOp.createNewFolder(paths[0].path, null, onCreated);
|
||||
}
|
||||
module.hideMenu();
|
||||
});
|
||||
|
||||
$defaultContextMenu.on("click", "a", function(e) {
|
||||
e.stopPropagation();
|
||||
var path = $(this).data('path');
|
||||
var $element = $(this).data('element');
|
||||
if (!$element || !path || path.length < 2) {
|
||||
var paths = $(this).data('paths');
|
||||
if (paths.length === 0) {
|
||||
log(Messages.fm_forbidden);
|
||||
debug("Directory context menu on a forbidden or unexisting element. ", $element, path);
|
||||
debug("Context menu on a forbidden or unexisting element. ", paths);
|
||||
return;
|
||||
}
|
||||
if ($(this).hasClass('open')) {
|
||||
$element.dblclick();
|
||||
paths.forEach(function (p) {
|
||||
var $element = p.element;
|
||||
$element.dblclick();
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass('open_ro')) {
|
||||
var el = filesOp.findElement(files, path);
|
||||
if (filesOp.isPathInFilesData(path)) {
|
||||
el = el.href;
|
||||
}
|
||||
if (!el || filesOp.isFolder(el)) { return; }
|
||||
var roUrl = getReadOnlyUrl(el);
|
||||
openFile(roUrl);
|
||||
paths.forEach(function (p) {
|
||||
var el = filesOp.findElement(files, p.path);
|
||||
if (filesOp.isPathInFilesData(p.path)) { el = el.href; }
|
||||
if (!el || filesOp.isFolder(el)) { return; }
|
||||
var roUrl = getReadOnlyUrl(el);
|
||||
openFile(roUrl, false);
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass('delete')) {
|
||||
moveElements([path], [TRASH], false, refresh);
|
||||
var pathsList = [];
|
||||
paths.forEach(function (p) { pathsList.push(p.path); });
|
||||
moveElements(pathsList, [TRASH], false, refresh);
|
||||
}
|
||||
module.hideMenu();
|
||||
});
|
||||
|
@ -1770,11 +1837,10 @@ define([
|
|||
|
||||
$trashTreeContextMenu.on('click', 'a', function (e) {
|
||||
e.stopPropagation();
|
||||
var path = $(this).data('path');
|
||||
var $element = $(this).data('element');
|
||||
if (!$element || !filesOp.comparePath(path, [TRASH])) {
|
||||
var paths = $(this).data('paths');
|
||||
if (paths.length !== 1 || !paths[0].element || !filesOp.comparePath(paths[0].path, [TRASH])) {
|
||||
log(Messages.fm_forbidden);
|
||||
debug("Trash tree context menu on a forbidden or unexisting element. ", $element, path);
|
||||
debug("Trash tree context menu on a forbidden or unexisting element. ", paths);
|
||||
return;
|
||||
}
|
||||
if ($(this).hasClass("empty")) {
|
||||
|
@ -1788,22 +1854,34 @@ define([
|
|||
|
||||
$trashContextMenu.on('click', 'a', function (e) {
|
||||
e.stopPropagation();
|
||||
var path = $(this).data('path');
|
||||
var $element = $(this).data('element');
|
||||
if (!$element || !path || path.length < 2) {
|
||||
var paths = $(this).data('paths');
|
||||
if (paths.length === 0) {
|
||||
log(Messages.fm_forbidden);
|
||||
debug("Trash context menu on a forbidden or unexisting element. ", $element, path);
|
||||
debug("Trash context menu on a forbidden or unexisting element. ", paths);
|
||||
return;
|
||||
}
|
||||
var name = path[path.length - 1];
|
||||
var path = paths[0].path;
|
||||
var name = paths[0].path[paths[0].path.length - 1];
|
||||
if ($(this).hasClass("remove")) {
|
||||
if (path.length === 4) { name = path[1]; }
|
||||
Cryptpad.confirm(Messages._getKey("fm_removePermanentlyDialog", [name]), function(res) {
|
||||
if (paths.length === 1) {
|
||||
if (path.length === 4) { name = path[1]; }
|
||||
Cryptpad.confirm(Messages._getKey("fm_removePermanentlyDialog", [name]), function(res) {
|
||||
if (!res) { return; }
|
||||
filesOp.removeFromTrash(path, refresh);
|
||||
});
|
||||
return;
|
||||
}
|
||||
var pathsList = [];
|
||||
paths.forEach(function (p) { pathsList.push(p.path); });
|
||||
var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]);
|
||||
Cryptpad.confirm(msg, function(res) {
|
||||
if (!res) { return; }
|
||||
filesOp.removeFromTrash(path, refresh);
|
||||
filesOp.deletePathsPermanently(pathsList);
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass("restore")) {
|
||||
if (paths.length !== 1) { return; }
|
||||
if (path.length === 4) { name = path[1]; }
|
||||
Cryptpad.confirm(Messages._getKey("fm_restoreDialog", [name]), function(res) {
|
||||
if (!res) { return; }
|
||||
|
@ -1811,6 +1889,7 @@ define([
|
|||
});
|
||||
}
|
||||
else if ($(this).hasClass("properties")) {
|
||||
if (paths.length !== 1) { return; }
|
||||
if (path.length !== 4) { return; }
|
||||
var element = filesOp.getTrashElementData(path);
|
||||
var sPath = stringifyPath(element.path);
|
||||
|
|
Loading…
Reference in New Issue