From 5a5451d94c537836c6a292b460e77bd4f2294d4a Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 23 Nov 2016 18:21:45 +0100 Subject: [PATCH] Sort elements in the trash, add properties in the context menu, fix issue with Edge --- customize.dist/translations/messages.fr.js | 7 +++ customize.dist/translations/messages.js | 7 +++ www/common/cryptpad-common.js | 3 +- www/file/fileObject.js | 13 ++++- www/file/inner.html | 9 ++-- www/file/main.js | 63 +++++++++++++++++----- 6 files changed, 83 insertions(+), 19 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 5be6d0ae5..9c64e1f4f 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -172,6 +172,7 @@ define(function () { out.fm_lastAccess = "Dernier accès"; out.fm_creation = "Création"; 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_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 ?"; @@ -189,10 +190,16 @@ define(function () { out.fc_restore = "Restaurer"; out.fc_remove = "Supprimer définitivement"; 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) 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_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 diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index e1369a550..f5f80e4a1 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -172,6 +172,7 @@ define(function () { out.fm_lastAccess = "Last access"; out.fm_creation = "Creation"; out.fm_forbidden = "Forbidden action"; + out.fm_originalPath = "Original path"; 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_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_remove = "Delete permanently"; 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) 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_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 diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index d12e73c04..120be68dc 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -103,7 +103,8 @@ define([ 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) { return html.replace(/ 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; diff --git a/www/file/inner.html b/www/file/inner.html index 88c8e40c7..dc9b5bd44 100644 --- a/www/file/inner.html +++ b/www/file/inner.html @@ -23,10 +23,10 @@ diff --git a/www/file/main.js b/www/file/main.js index 4fb88ec44..46ec7e64f 100644 --- a/www/file/main.js +++ b/www/file/main.js @@ -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 + ":
" + element.path.join('/')); + } module.hideMenu(); });