Sort elements in the trash, add properties in the context menu, fix issue with Edge

pull/1/head
yflory 8 years ago
parent 19e4a2d044
commit 5a5451d94c

@ -172,6 +172,7 @@ define(function () {
out.fm_lastAccess = "Dernier accès"; out.fm_lastAccess = "Dernier accès";
out.fm_creation = "Création"; out.fm_creation = "Création";
out.fm_forbidden = "Action interdite"; out.fm_forbidden = "Action interdite";
out.fm_originalPath = "Chemin d'origine";
out.fm_emptyTrashDialog = "Êtes-vous sûr de vouloir vider la corbeille ?"; out.fm_emptyTrashDialog = "Êtes-vous sûr de vouloir vider la corbeille ?";
out.fm_removeSeveralPermanentlyDialog = "Êtes-vous sûr de vouloir supprimer ces {0} éléments de manière permanente ?"; out.fm_removeSeveralPermanentlyDialog = "Êtes-vous sûr de vouloir supprimer ces {0} éléments de manière permanente ?";
out.fm_removePermanentlyDialog = "Êtes-vous sûr de vouloir supprimer {0} de la corbeille de manière permanente ?"; out.fm_removePermanentlyDialog = "Êtes-vous sûr de vouloir supprimer {0} de la corbeille de manière permanente ?";
@ -189,10 +190,16 @@ define(function () {
out.fc_restore = "Restaurer"; out.fc_restore = "Restaurer";
out.fc_remove = "Supprimer définitivement"; out.fc_remove = "Supprimer définitivement";
out.fc_empty = "Vider la corbeille"; out.fc_empty = "Vider la corbeille";
out.fc_newpad = "Nouveau pad de texte";
out.fc_newcode = "Nouveau pad de code";
out.fc_newslide = "Nouvelle présentation";
out.fc_newpoll = "Nouveau sondage";
out.fc_prop = "Propriétés";
// fileObject.js (logs) // fileObject.js (logs)
out.fo_moveUnsortedError = "La liste des éléments non triés ne peut pas contenir de dossiers."; out.fo_moveUnsortedError = "La liste des éléments non triés ne peut pas contenir de dossiers.";
out.fo_existingNameError = "Ce nom est déjà utilisé dans ce répertoire. Veuillez en choisir un autre."; out.fo_existingNameError = "Ce nom est déjà utilisé dans ce répertoire. Veuillez en choisir un autre.";
out.fo_moveFolderToChildError = "Vous ne pouvez pas déplacer un dossier dans un de ses descendants"; out.fo_moveFolderToChildError = "Vous ne pouvez pas déplacer un dossier dans un de ses descendants";
out.fo_unableToRestore = "Impossible de restaurer ce fichier à son emplacement d'origine. Vous pouvez essayer de le déplacer à un nouvel emplacement.";
// index.html // index.html

@ -172,6 +172,7 @@ define(function () {
out.fm_lastAccess = "Last access"; out.fm_lastAccess = "Last access";
out.fm_creation = "Creation"; out.fm_creation = "Creation";
out.fm_forbidden = "Forbidden action"; out.fm_forbidden = "Forbidden action";
out.fm_originalPath = "Original path";
out.fm_emptyTrashDialog = "Are you sure you want to empty the trash?"; out.fm_emptyTrashDialog = "Are you sure you want to empty the trash?";
out.fm_removeSeveralPermanentlyDialog = "Are you sure you want to remove these {0} elements from the trash permanently?"; out.fm_removeSeveralPermanentlyDialog = "Are you sure you want to remove these {0} elements from the trash permanently?";
out.fm_removePermanentlyDialog = "Are you sure you want to remove {0} from the trash permanently?"; out.fm_removePermanentlyDialog = "Are you sure you want to remove {0} from the trash permanently?";
@ -189,10 +190,16 @@ define(function () {
out.fc_restore = "Restore"; out.fc_restore = "Restore";
out.fc_remove = "Delete permanently"; out.fc_remove = "Delete permanently";
out.fc_empty = "Empty the trash"; out.fc_empty = "Empty the trash";
out.fc_newpad = "New text pad";
out.fc_newcode = "New code pad";
out.fc_newslide = "New presentation";
out.fc_newpoll = "New poll";
out.fc_prop = "Properties";
// fileObject.js (logs) // fileObject.js (logs)
out.fo_moveUnsortedError = "You can't move a folder to the list of unsorted pads"; out.fo_moveUnsortedError = "You can't move a folder to the list of unsorted pads";
out.fo_existingNameError = "Name already used in that directory. Please choose another one."; out.fo_existingNameError = "Name already used in that directory. Please choose another one.";
out.fo_moveFolderToChildError = "You can't move a folder into one of its descendants"; out.fo_moveFolderToChildError = "You can't move a folder into one of its descendants";
out.fo_unableToRestore = "Unable to restore that file to its original location. You can try to move it to a new location.";
// index.html // index.html

@ -103,7 +103,8 @@ define([
store = Store; store = Store;
}); });
var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; }; // var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; };
var isArray = $.isArray;
var fixHTML = common.fixHTML = function (html) { var fixHTML = common.fixHTML = function (html) {
return html.replace(/</g, '&lt;'); return html.replace(/</g, '&lt;');

@ -266,7 +266,7 @@ define([
var path = pathInput.slice(); var path = pathInput.slice();
var key = path.shift(); var key = path.shift();
if (typeof root[key] === "undefined") { 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;
} }
return findElement(root[key], path); return findElement(root[key], path);
@ -356,6 +356,7 @@ define([
log(Messages.fo_moveUnsortedError); log(Messages.fo_moveUnsortedError);
return; return;
} else { } else {
if (isPathInUnsorted(elementPath)) { console.log('inunsorted'); return; }
if (files[UNSORTED].indexOf(element) === -1) { if (files[UNSORTED].indexOf(element) === -1) {
files[UNSORTED].push(element); files[UNSORTED].push(element);
} }
@ -392,6 +393,7 @@ define([
// the other elements. We have to move them all and then remove them from unsorted // the other elements. We have to move them all and then remove them from unsorted
var moveUnsortedElements = exp.moveUnsortedElements = function (paths, newParentPath, cb) { var moveUnsortedElements = exp.moveUnsortedElements = function (paths, newParentPath, cb) {
if (!paths || paths.length === 0) { return; } if (!paths || paths.length === 0) { return; }
if (isPathInUnsorted(newParentPath)) { return; }
var elements = {}; var elements = {};
// Get the elements // Get the elements
paths.forEach(function (p) { paths.forEach(function (p) {
@ -472,6 +474,13 @@ define([
} }
// Find the new parent element // Find the new parent element
var newParentEl = findElement(files, newPath); 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]); var name = getAvailableName(newParentEl, path[1]);
// Move the element // Move the element
newParentEl[name] = element; newParentEl[name] = element;

@ -23,10 +23,10 @@
<div id="contentContextMenu" class="contextMenu dropdown clearfix" oncontextmenu="return false;"> <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;"> <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="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="pad" data-localization="fc_newpad" 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="code" data-localization="fc_newcode" 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="slide" data-localization="fc_newslide" 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="poll" data-localization="fc_newpoll" target="_blank">New poll</a></li>
</ul> </ul>
</div> </div>
<div id="trashTreeContextMenu" class="contextMenu dropdown clearfix" oncontextmenu="return false;"> <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;"> <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="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="restore" data-localization="fc_restore">Restore</a></li>
<li><a tabindex="-1" href="#" class="properties" data-localization="fc_prop">Properties</a></li>
</ul> </ul>
</div> </div>
</body> </body>

@ -482,6 +482,7 @@ define([
$trashContextMenu.find('li').show(); $trashContextMenu.find('li').show();
if (path.length > 4) { if (path.length > 4) {
$trashContextMenu.find('a.restore').parent('li').hide(); $trashContextMenu.find('a.restore').parent('li').hide();
$trashContextMenu.find('a.properties').parent('li').hide();
} }
openContextMenu(e, $trashContextMenu); openContextMenu(e, $trashContextMenu);
return false; return false;
@ -895,7 +896,32 @@ define([
}); });
return keys; 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 // 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) // and they don't hav a hierarchical structure (folder/subfolders)
var displayUnsorted = function ($container) { var displayUnsorted = function ($container) {
@ -955,20 +981,14 @@ define([
}; };
var displayTrashRoot = function ($list, $folderHeader, $fileHeader) { 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) // Elements in the trash are JS arrays (several elements can have the same name)
[true,false].forEach(function (folder) { [true,false].forEach(function (folder) {
var testElement = filesOp.isFile; var testElement = filesOp.isFile;
if (!folder) { if (!folder) {
testElement = filesOp.isFolder; 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) { Object.keys(root).forEach(function (key) {
if (!$.isArray(root[key])) { if (!$.isArray(root[key])) {
logError("Trash element has a wrong type", root[key]); logError("Trash element has a wrong type", root[key]);
@ -977,12 +997,26 @@ define([
root[key].forEach(function (el, idx) { root[key].forEach(function (el, idx) {
if (testElement(el.element)) { return; } if (testElement(el.element)) { return; }
var spath = [key, idx, 'element']; var spath = [key, idx, 'element'];
var $element = createElement([TRASH], spath, root, folder); filesList.push({
$list.append($element); 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) // Display the selected directory into the content part (rightside)
@ -1300,6 +1334,11 @@ define([
filesOp.restoreTrash(path, refresh); 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(); module.hideMenu();
}); });

Loading…
Cancel
Save