Sort elements in the trash, add properties in the context menu, fix issue with Edge
This commit is contained in:
@@ -266,7 +266,7 @@ define([
|
||||
var path = pathInput.slice();
|
||||
var key = path.shift();
|
||||
if (typeof root[key] === "undefined") {
|
||||
debug("Unable to find the key '" + key + "' in the root object provided:\n", root);
|
||||
debug("Unable to find the key '" + key + "' in the root object provided:", root);
|
||||
return;
|
||||
}
|
||||
return findElement(root[key], path);
|
||||
@@ -356,6 +356,7 @@ define([
|
||||
log(Messages.fo_moveUnsortedError);
|
||||
return;
|
||||
} else {
|
||||
if (isPathInUnsorted(elementPath)) { console.log('inunsorted'); return; }
|
||||
if (files[UNSORTED].indexOf(element) === -1) {
|
||||
files[UNSORTED].push(element);
|
||||
}
|
||||
@@ -392,6 +393,7 @@ define([
|
||||
// the other elements. We have to move them all and then remove them from unsorted
|
||||
var moveUnsortedElements = exp.moveUnsortedElements = function (paths, newParentPath, cb) {
|
||||
if (!paths || paths.length === 0) { return; }
|
||||
if (isPathInUnsorted(newParentPath)) { return; }
|
||||
var elements = {};
|
||||
// Get the elements
|
||||
paths.forEach(function (p) {
|
||||
@@ -410,7 +412,7 @@ define([
|
||||
files[UNSORTED].splice(idx, 1);
|
||||
}
|
||||
});
|
||||
if(cb) { cb(); }
|
||||
if (cb) { cb(); }
|
||||
};
|
||||
|
||||
var moveElements = exp.moveElements = function (paths, newParentPath, cb) {
|
||||
@@ -472,6 +474,13 @@ define([
|
||||
}
|
||||
// Find the new parent element
|
||||
var newParentEl = findElement(files, newPath);
|
||||
while (newPath.length > 1 && !newParentEl) {
|
||||
newPath.pop();
|
||||
newParentEl = findElement(files, newPath);
|
||||
}
|
||||
if (!newParentEl) {
|
||||
log(Messages.fo_unableToRestore);
|
||||
}
|
||||
var name = getAvailableName(newParentEl, path[1]);
|
||||
// Move the element
|
||||
newParentEl[name] = element;
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
<div id="contentContextMenu" class="contextMenu dropdown clearfix" oncontextmenu="return false;">
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">
|
||||
<li><a tabindex="-1" href="#" class="newfolder" data-localization="fc_newfolder">New folder</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="pad" target="_blank">New pad</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="code" target="_blank">New code</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="slide" target="_blank">New slide</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="poll" target="_blank">New poll</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="pad" data-localization="fc_newpad" target="_blank">New pad</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="code" data-localization="fc_newcode" target="_blank">New code</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="slide" data-localization="fc_newslide" target="_blank">New slide</a></li>
|
||||
<li><a tabindex="-1" href="#" class="newdoc" data-type="poll" data-localization="fc_newpoll" target="_blank">New poll</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="trashTreeContextMenu" class="contextMenu dropdown clearfix" oncontextmenu="return false;">
|
||||
@@ -38,6 +38,7 @@
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">
|
||||
<li><a tabindex="-1" href="#" class="remove" data-localization="fc_remove">Delete permanently</a></li>
|
||||
<li><a tabindex="-1" href="#" class="restore" data-localization="fc_restore">Restore</a></li>
|
||||
<li><a tabindex="-1" href="#" class="properties" data-localization="fc_prop">Properties</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -482,6 +482,7 @@ define([
|
||||
$trashContextMenu.find('li').show();
|
||||
if (path.length > 4) {
|
||||
$trashContextMenu.find('a.restore').parent('li').hide();
|
||||
$trashContextMenu.find('a.properties').parent('li').hide();
|
||||
}
|
||||
openContextMenu(e, $trashContextMenu);
|
||||
return false;
|
||||
@@ -895,7 +896,32 @@ define([
|
||||
});
|
||||
return keys;
|
||||
};
|
||||
|
||||
var sortTrashElements = function (folder, oldkeys, prop, asc) {
|
||||
var root = files[TRASH];
|
||||
var test = folder ? filesOp.isFolder : filesOp.isFile;
|
||||
var keys = oldkeys.filter(function (e) {
|
||||
return test(e.element);
|
||||
});
|
||||
if (keys.length < 2) { return keys; }
|
||||
var mult = asc ? 1 : -1;
|
||||
var getProp = function (el, prop) {
|
||||
if (prop && !folder) {
|
||||
var element = el.element;
|
||||
var e = filesOp.getFileData(element);
|
||||
if (prop === 'atime' || prop === 'ctime') {
|
||||
return new Date(e[prop]);
|
||||
}
|
||||
return e.title.toLowerCase();
|
||||
}
|
||||
return el.name.toLowerCase();
|
||||
};
|
||||
keys.sort(function(a, b) {
|
||||
if (getProp(a, prop) < getProp(b, prop)) { return mult * -1; }
|
||||
if (getProp(a, prop) > getProp(b, prop)) { return mult * 1; }
|
||||
return 0;
|
||||
});
|
||||
return keys;
|
||||
};
|
||||
// Unsorted element are represented by "href" in an array: they don't have a filename
|
||||
// and they don't hav a hierarchical structure (folder/subfolders)
|
||||
var displayUnsorted = function ($container) {
|
||||
@@ -955,20 +981,14 @@ define([
|
||||
};
|
||||
|
||||
var displayTrashRoot = function ($list, $folderHeader, $fileHeader) {
|
||||
var filesList = [];
|
||||
var root = files[TRASH];
|
||||
// Elements in the trash are JS arrays (several elements can have the same name)
|
||||
[true,false].forEach(function (folder) {
|
||||
var testElement = filesOp.isFile;
|
||||
if (!folder) {
|
||||
testElement = filesOp.isFolder;
|
||||
}
|
||||
var root = files[TRASH];
|
||||
if (folder) {
|
||||
if (filesOp.hasSubfolder(root, true)) { $list.append($folderHeader); }
|
||||
else { return; }
|
||||
} else {
|
||||
if (filesOp.hasFile(root, true)) { $list.append($fileHeader); }
|
||||
else { return; }
|
||||
}
|
||||
Object.keys(root).forEach(function (key) {
|
||||
if (!$.isArray(root[key])) {
|
||||
logError("Trash element has a wrong type", root[key]);
|
||||
@@ -977,12 +997,26 @@ define([
|
||||
root[key].forEach(function (el, idx) {
|
||||
if (testElement(el.element)) { return; }
|
||||
var spath = [key, idx, 'element'];
|
||||
var $element = createElement([TRASH], spath, root, folder);
|
||||
$list.append($element);
|
||||
filesList.push({
|
||||
element: el.element,
|
||||
spath: spath,
|
||||
name: key
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var sortedFolders = sortTrashElements(true, filesList, null, !files[SORT_FOLDER_DESC]);
|
||||
var sortedFiles = sortTrashElements(false, filesList, files[SORT_FILE_BY], !files[SORT_FILE_DESC]);
|
||||
if (filesOp.hasSubfolder(root, true)) { $list.append($folderHeader); }
|
||||
sortedFolders.forEach(function (f) {
|
||||
var $element = createElement([TRASH], f.spath, root, true);
|
||||
$list.append($element);
|
||||
});
|
||||
if (filesOp.hasFile(root, true)) { $list.append($fileHeader); }
|
||||
sortedFiles.forEach(function (f) {
|
||||
var $element = createElement([TRASH], f.spath, root, false);
|
||||
$list.append($element);
|
||||
});
|
||||
};
|
||||
|
||||
// Display the selected directory into the content part (rightside)
|
||||
@@ -1300,6 +1334,11 @@ define([
|
||||
filesOp.restoreTrash(path, refresh);
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass("properties")) {
|
||||
if (path.length !== 4) { return; }
|
||||
var element = filesOp.getTrashElementData(path);
|
||||
Cryptpad.alert(Messages.fm_originalPath + ":<br>" + element.path.join('/'));
|
||||
}
|
||||
module.hideMenu();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user