Remove the unowned pads category

This commit is contained in:
yflory 2017-01-25 14:26:28 +01:00
parent cb85ad3fdf
commit f42665ba49
6 changed files with 89 additions and 87 deletions

View file

@ -202,7 +202,7 @@ define(function () {
out.fm_noname = "Document sans titre";
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 manière permanente ?";
out.fm_removePermanentlyDialog = "Êtes-vous sûr de vouloir supprimer cet élément de manière permanente ?";
out.fm_restoreDialog = "Êtes-vous sûr de vouloir restaurer {0} à son emplacement précédent ?";
out.fm_removeSeveralDialog = "Êtes-vous sûr de vouloir déplacer ces {0} éléments vers la corbeille ?";
out.fm_removeDialog = "Êtes-vous sûr de vouloir déplacer {0} vers la corbeille ?";

View file

@ -199,7 +199,7 @@ define(function () {
out.fm_noname = "Untitled Document";
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} permanently?";
out.fm_removePermanentlyDialog = "Are you sure you want to remove that element permanently?";
out.fm_removeSeveralDialog = "Are you sure you want to move these {0} elements to the trash?";
out.fm_removeDialog = "Are you sure you want to move {0} to the trash?";
out.fm_restoreDialog = "Are you sure you want to restore {0} to its previous location?";

View file

@ -407,7 +407,7 @@ define([
// STORAGE
var setPadAttribute = common.setPadAttribute = function (attr, value, cb, legacy) {
getStore(legacy).set([getHash(), attr].join('.'), value, function (err, data) {
getStore(legacy).setDrive([getHash(), attr].join('.'), value, function (err, data) {
cb(err, data);
});
};
@ -422,7 +422,7 @@ define([
// STORAGE
var getPadAttribute = common.getPadAttribute = function (attr, cb, legacy) {
getStore(legacy).get([getHash(), attr].join('.'), function (err, data) {
getStore(legacy).getDrive([getHash(), attr].join('.'), function (err, data) {
cb(err, data);
});
};
@ -577,7 +577,7 @@ define([
if (!contains) {
var data = makePad(href, name);
if (common.initialPath) {
data.owner = 1; // TODO use owner id here?
data.owner = getStore().getLoginName(); // TODO use owner id here?
}
renamed.push(data);
if (USE_FS_STORE && common.initialPath && typeof(getStore().addPad) === "function") {

View file

@ -8,7 +8,6 @@ define([
var ROOT = "root";
var UNSORTED = "unsorted";
var FILES_DATA = "filesData";
var ANON = "anon"; // virtual path
var TRASH = "trash";
var TEMPLATE = "template";
var NEW_FOLDER_NAME = Messages.fm_newFolder;
@ -58,9 +57,6 @@ define([
var isPathInTrash = exp.isPathInTrash = function (path) {
return path[0] && path[0] === TRASH;
};
var isPathInAnon = exp.isPathInAnon = function (path) {
return path[0] && path[0] === ANON;
};
var isPathInFilesData = exp.isPathInFilesData = function (path) {
return path[0] && path[0] === FILES_DATA;
@ -231,13 +227,6 @@ define([
return ret;
};
/*var getAnonFiles = exp.getAnonFiles = function () {
if (!files[ANON]) {
files[ANON] = [];
}
return files[ANON].slice();
};*///TODO
var removeFileFromRoot = function (root, href) {
if (isFile(root)) { return; }
for (var e in root) {
@ -256,6 +245,17 @@ define([
return path[0] === TRASH && path.length === 4;
};
var removePadAttribute = function (f) {
Object.keys(files).forEach(function (key) {
var hash = f.indexOf('#') !== -1 ? f.slice(f.indexOf('#') + 1) : null;
if (hash && key.indexOf(hash) === 0) {
debug("Deleting pad attribute in the realtime object");
files[key] = undefined;
delete files[key];
}
});
};
var checkDeletedFiles = function () {
// Nothing in FILES_DATA for workgroups
if (workgroup) { return; }
@ -279,14 +279,7 @@ define([
if (idx !== -1) {
debug("Removing", f, "from filesData");
files[FILES_DATA].splice(idx, 1);
Object.keys(files).forEach(function (key) {
var hash = f.href.indexOf('#') !== -1 ? f.href.slice(f.href.indexOf('#') + 1) : null;
if (hash && key.indexOf(hash) === 0) {
debug("Deleting pad attribute in the realtime object");
files[key] = undefined;
delete files[key];
}
});
removePadAttribute(f.href);
}
});
};
@ -297,7 +290,7 @@ define([
var parentEl = exp.findElement(files, parentPath);
if (path.length === 4 && path[0] === TRASH) {
files[TRASH][path[1]].splice(path[2], 1);
} else if (path[0] === UNSORTED) { //TODO || === TEMPLATE
} else if (path[0] === UNSORTED || path[0] === TEMPLATE) {
parentEl.splice(key, 1);
} else {
parentEl[key] = undefined;
@ -375,7 +368,6 @@ define([
};
// Move to trash
// TODO: rename the function
var removeElement = exp.removeElement = function (path, cb, keepOld) {
if (!path || path.length < 2 || path[0] === TRASH) {
debug("Calling removeElement from a wrong path: ", path);
@ -409,7 +401,7 @@ define([
if (isPathInHrefArray(newParentPath)) {
if (isFolder(element)) {
log(Messages.fo_moveUnsortedError); //TODO or template
log(Messages.fo_moveUnsortedError);
return;
} else {
if (elementPath[0] === newParentPath[0]) { return; }
@ -595,6 +587,28 @@ define([
if(cb) { cb(); }
};
var deleteFileData = exp.deleteFileData = function (href, cb) {
if (workgroup) { return; }
var toRemove = [];
files[FILES_DATA].forEach(function (arr) {
var f = arr.href;
if (f === href) {
toRemove.push(arr);
}
});
toRemove.forEach(function (f) {
var idx = files[FILES_DATA].indexOf(f);
if (idx !== -1) {
debug("Removing", f, "from filesData");
files[FILES_DATA].splice(idx, 1);
// Remove the "padAttributes" stored in the realtime object for that pad
removePadAttribute(f.href);
}
});
if(cb) { cb(); }
};
var renameElement = exp.renameElement = function (path, newName, cb) {
if (path.length <= 1) {
@ -791,9 +805,6 @@ define([
us.splice(idx, 1);
});
};
/*var fixAnon = function () {
if (!$.isArray(files[ANON])) { debug("ANON was not an array"); files[FILES_DATA] = []; }
};*/// TODO
var fixFilesData = function () {
if (!$.isArray(files[FILES_DATA])) { debug("FILES_DATA was not an array"); files[FILES_DATA] = []; }
var fd = files[FILES_DATA];
@ -809,8 +820,7 @@ define([
toClean.push(el);
return;
}
if (el.owner
&& rootFiles.indexOf(el.href) === -1
if (rootFiles.indexOf(el.href) === -1
&& unsortedFiles.indexOf(el.href) === -1
&& templateFiles.indexOf(el.href) === -1
&& trashFiles.indexOf(el.href) === -1) {
@ -818,9 +828,6 @@ define([
files[UNSORTED].push(el.href);
return;
}
/*if (!el.owner && anonFiles.indexOf(el.href) === -1) {
files[ANON].push(el.href);
}*/// TODO
});
toClean.forEach(function (el) {
var idx = fd.indexOf(el);

View file

@ -247,6 +247,10 @@ li {
text-align: center;
}
#content .grid li .fa.listonly {
display: none;
}
#content .list li {
display: flex;
flex-flow: row;

View file

@ -45,10 +45,6 @@ define([
var TRASH = "trash";
var TRASH_NAME = Messages.fm_trashName;
// anon: Virtual path, not stored in the object but extracted from FILES_DATA
var ANON = "anon";
var ANON_NAME = Messages.fm_anonName || 'Anon pads......';
var LOCALSTORAGE_LAST = "cryptpad-file-lastOpened";
var LOCALSTORAGE_OPENED = "cryptpad-file-openedFolders";
var LOCALSTORAGE_VIEWMODE = "cryptpad-file-viewMode";
@ -173,7 +169,7 @@ define([
// FILE MANAGER
// _WORKGROUP_ and other people drive : display Documents as main page
var currentPath = module.currentPath = APP.loggedIn ? isOwnDrive() ? getLastOpenedFolder() : [ROOT] : [ANON];
var currentPath = module.currentPath = isOwnDrive() ? getLastOpenedFolder() : [ROOT];
var lastSelectTime;
var selectedElement;
@ -192,6 +188,11 @@ define([
var $folderOpenedIcon = $('<span>', {"class": "fa fa-folder-open folder", style:"color:#FEDE8B;text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;"});
var $folderOpenedEmptyIcon = $folderOpenedIcon.clone();
var $fileIcon = $('<span>', {"class": "fa fa-file-text-o file"});
var $padIcon = $('<span>', {"class": "fa fa-file-word-o file"});
var $codeIcon = $('<span>', {"class": "fa fa-file-code-o file"});
var $slideIcon = $('<span>', {"class": "fa fa-file-powerpoint-o file"});
var $pollIcon = $('<span>', {"class": "fa fa-calendar file"});
var $anonIcon = $('<span>', {"class": "fa fa-user-secret file listonly"});
var $upIcon = $('<span>', {"class": "fa fa-arrow-circle-up"});
var $unsortedIcon = $('<span>', {"class": "fa fa-files-o"});
var $templateIcon = $('<span>', {"class": "fa fa-cubes"});
@ -645,6 +646,22 @@ define([
$span.append($name).append($subfolders).append($files);
};
var getFileIcon = function (href) {
var $icon = $fileIcon.clone();
var data = filesOp.getFileData(href);
if (!data) { return $icon; }
if (href.indexOf('/pad/') !== -1) { $icon = $padIcon.clone() }
else if (href.indexOf('/code/') !== -1) { $icon = $codeIcon.clone() }
else if (href.indexOf('/slide/') !== -1) { $icon = $slideIcon.clone() }
else if (href.indexOf('/poll/') !== -1) { $icon = $pollIcon.clone() }
if (!data.owner) {
$icon = $('<span>').append($anonIcon.clone()).append($icon);
}
return $icon;
};
// Create the "li" element corresponding to the file/folder located in "path"
var createElement = function (path, elPath, root, isFolder) {
// Forbid drag&drop inside the trash
@ -660,7 +677,7 @@ define([
}
var element = filesOp.findElement(files, newPath);
var $icon = $fileIcon.clone();
var $icon = !isFolder ? getFileIcon(element) : undefined;
var spanClass = 'file-element element';
var liClass = 'file-item';
if (isFolder) {
@ -732,7 +749,6 @@ define([
else if (name === TRASH && path.length === 1) { name = TRASH_NAME; }
else if (name === UNSORTED && path.length === 1) { name = UNSORTED_NAME; }
else if (name === TEMPLATE && path.length === 1) { name = TEMPLATE_NAME; }
else if (name === ANON && path.length === 1) { name = ANON_NAME; }
else if (name === FILES_DATA && path.length === 1) { name = FILES_DATA_NAME; }
else if (filesOp.isPathInTrash(path)) { name = getTrashTitle(path); }
var $title = $('<h1>').text(name);
@ -844,7 +860,7 @@ define([
options.push({tag: 'hr'});
}
AppConfig.availablePadTypes.forEach(function (type) {
var path = filesOp.comparePath(currentPath, [ANON]) ? '' : '/#?path=' + encodeURIComponent(currentPath);
var path = '/#?path=' + encodeURIComponent(currentPath);
options.push({
tag: 'a',
attributes: {
@ -1086,7 +1102,7 @@ define([
//return;
}
var idx = files[rootName].indexOf(href);
var $icon = $fileIcon.clone();
var $icon = getFileIcon(href);
var $name = $('<span>', { 'class': 'file-element element' });
addFileData(href, file.title, $name, false);
var $element = $('<li>', {
@ -1108,18 +1124,16 @@ define([
});
};
var displayAllFiles = function ($container, anon) {
var displayAllFiles = function ($container) {
var allfiles = files[FILES_DATA];
if (allfiles.length === 0) { return; }
var $fileHeader = getFileListHeader(false);
$container.append($fileHeader);
var keys = allfiles.filter(function (el) {
return anon && !el.owner || !anon && el.owner;
});
var keys = allfiles;
var sortedFiles = sortElements(false, [FILES_DATA], keys, Cryptpad.getLSAttribute(SORT_FILE_BY), !getSortFileDesc(), false, true);
sortedFiles.forEach(function (file) {
var $icon = $fileIcon.clone();
var $icon = getFileIcon(file.href);
var $name = $('<span>', { 'class': 'file-element element' });
addFileData(file.href, file.title, $name, false);
var $element = $('<li>').append($icon).append($name).dblclick(function () {
@ -1181,7 +1195,7 @@ define([
if (!appStatus.isReady && !force) { return; }
// Only Trash and Root are available in not-owned files manager
if (isWorkgroup() && !filesOp.isPathInTrash(path) && !filesOp.isPathInRoot(path)) {
log("TRANSLATE or REMOVE: Unable to open the selected category, displaying root"); //TODO translate
log("Unable to open the selected category, displaying root"); //TODO translate
currentPath = [ROOT];
displayDirectory(currentPath);
return;
@ -1197,10 +1211,9 @@ define([
var isUnsorted = filesOp.comparePath(path, [UNSORTED]);
var isTemplate = filesOp.comparePath(path, [TEMPLATE]);
var isAllFiles = filesOp.comparePath(path, [FILES_DATA]);
var isAnon = filesOp.comparePath(path, [ANON]);
var root = filesOp.findElement(files, path);
if (typeof(root) === "undefined" && !isAnon) {
if (typeof(root) === "undefined") {
log(Messages.fm_unknownFolderError);
debug("Unable to locate the selected directory: ", path);
var parentPath = path.slice();
@ -1236,12 +1249,9 @@ define([
var $fileHeader = getFileListHeader(true);
if (isUnsorted || isTemplate) {
// 3rd parameter is "draggable": anon pads shouldn't be draggable
displayHrefArray($list, path[0], !isAnon);
displayHrefArray($list, path[0]);
} else if (isAllFiles) {
displayAllFiles($list, false);
} else if (isAnon) {
displayAllFiles($list, true);
displayAllFiles($list);
} else if (isTrashRoot) {
displayTrashRoot($list, $folderHeader, $fileHeader);
} else {
@ -1392,18 +1402,6 @@ define([
$container.append($allfilesList);
};
var createAnonFiles = function ($container, path, anonUser) {
var $icon = $unsortedIcon.clone();
var isOpened = filesOp.comparePath(path, currentPath);
var $allfilesElement = createTreeElement(ANON_NAME, $icon, [ANON], false, false, false, isOpened);
$allfilesElement.addClass('root');
var $allfilesList = $('<ul>', { id: 'anonTree', 'class': 'category2' }).append($allfilesElement);
if (anonUser) {
$allfilesList.removeClass('category2');
}
$container.append($allfilesList);
};
var createTrash = function ($container, path) {
var $icon = filesOp.isFolderEmpty(files[TRASH]) ? $trashEmptyIcon.clone() : $trashIcon.clone();
var isOpened = filesOp.comparePath(path, currentPath);
@ -1426,15 +1424,10 @@ define([
var resetTree = module.resetTree = function () {
$tree.html('');
if (!APP.loggedIn) {
createAnonFiles($tree, [ANON], true);
return;
}
createTree($tree, [ROOT]);
if (!isWorkgroup()) {
createUnsorted($tree, [UNSORTED]);
createTemplate($tree, [TEMPLATE]);
createAnonFiles($tree, [ANON]);
createAllFiles($tree, [FILES_DATA]);
}
createTrash($tree, [TRASH]);
@ -1636,26 +1629,23 @@ define([
var $selected = $iframe.find('.selected');
if (!$selected.length) { return; }
var paths = [];
var isTrash = filesOp.isPathInTrash(currentPath);
$selected.each(function (idx, elmt) {
if (!$(elmt).data('path')) { return; }
paths.push($(elmt).data('path'));
});
// If we are in the trash or if we are holding the "shift" key, delete permanently,
// else move to trash
if (filesOp.isPathInTrash(currentPath) || e.shiftKey) {
var cb = filesOp.removeFromTrash;
if (!filesOp.isPathInTrash(currentPath)) {
// If we are not in the trash, we just have to remove the key from root/unsorted
cb = filesOp.deletePathPermanently;
// If we are in the trash or anon pad or if we are holding the "shift" key, delete permanently,
if (isTrash || e.shiftKey) {
var cb = filesOp.removeFromTrash; // We're in the trash
if (!isTrash) {
cb = filesOp.deletePathPermanently; // We're in root/unsorted/template
}
// If we are already in the trash, delete the elements permanently
var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]);
if (paths.length === 1) { // If we delete only one element, display its name in the popup
var path = paths[0];
var element = filesOp.findElement(files, path);
var name = filesOp.isInTrashRoot(path) ? path[1] : (filesOp.isPathInHrefArray(path) ? filesOp.getTitle(element) : path[path.length - 1]);
msg = Messages._getKey("fm_removePermanentlyDialog", [name]);
if (paths.length === 1) {
msg = Messages.fm_removePermanentlyDialog;
}
Cryptpad.confirm(msg, function(res) {
if (!res) { return; }
paths.forEach(function(p) {
@ -1665,6 +1655,7 @@ define([
});
return;
}
// else move to trash
moveElements(paths, [TRASH], false, refresh);
}
});