From 601226115b64fb4f3a5287e669a51e3362434d4e Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 12 May 2017 18:06:29 +0200 Subject: [PATCH] New anonymous drive --- customize.dist/translations/messages.fr.js | 1 + customize.dist/translations/messages.js | 1 + www/common/common-codemirror.js | 2 -- www/common/cryptpad-common.js | 12 ++++--- www/common/userObject.js | 36 +++++++++++++++++-- www/drive/file.css | 3 ++ www/drive/file.less | 3 ++ www/drive/main.js | 42 ++++++++++++++++------ 8 files changed, 79 insertions(+), 21 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index d8e6f73d2..e2bbdd082 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -32,6 +32,7 @@ define(function () { out.error = "Erreur"; out.saved = "Enregistré"; out.synced = "Tout est enregistré"; + out.deleted = "Pad supprimé de votre CryptDrive"; out.disconnected = 'Déconnecté'; out.synchronizing = 'Synchronisation'; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index afdbdc6b2..15f5dfc2b 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -34,6 +34,7 @@ define(function () { out.error = "Error"; out.saved = "Saved"; out.synced = "Everything is saved"; + out.deleted = "Pad deleted from your CryptDrive"; out.disconnected = 'Disconnected'; out.synchronizing = 'Synchronizing'; diff --git a/www/common/common-codemirror.js b/www/common/common-codemirror.js index d9dfddaf6..bec2b98e4 100644 --- a/www/common/common-codemirror.js +++ b/www/common/common-codemirror.js @@ -149,9 +149,7 @@ define([ left: true, // Open to the left of the button isSelect: true, }; - console.log('here'); var $block = exp.$language = Cryptpad.createDropdown(dropdownConfig); - console.log(exp); $block.find('a').click(function () { setMode($(this).attr('data-value'), $block); onLocal(); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 6b042df41..f91069286 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -743,13 +743,13 @@ define([ common.updatePinLimit = function (cb) { if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); } - rpc.getFileListSize(cb); + rpc.updatePinLimits(cb); }; common.getPinLimit = function (cb) { if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); } - rpc.getFileListSize(cb); - //cb(void 0, typeof(AppConfig.pinLimit) === 'number'? AppConfig.pinLimit: 1000); + cb(void 0, typeof(AppConfig.pinLimit) === 'number'? AppConfig.pinLimit: 1000); + //rpc.getLimit(cb); TODO }; common.isOverPinLimit = function (cb) { @@ -858,7 +858,8 @@ define([ if (callback) { button.click(function() { var href = window.location.href; - common.confirm(Messages.forgetPrompt, function (yes) { + var msg = isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog; + common.confirm(msg, function (yes) { if (!yes) { return; } common.forgetPad(href, function (err) { if (err) { @@ -877,7 +878,8 @@ define([ } else { callback(); } - common.alert(Messages.movedToTrash, undefined, true); + var cMsg = isLoggedIn() ? Messages.movedToTrash : Messages.deleted; + common.alert(cMsg, undefined, true); return; }); }); diff --git a/www/common/userObject.js b/www/common/userObject.js index 49e46147a..51840dca5 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -539,6 +539,7 @@ define([ // ADD var add = exp.add = function (data, path) { + if (!Cryptpad.isLoggedIn()) { return; } if (!data || typeof(data) !== "object") { return; } var href = data.href; var name = data.title; @@ -596,6 +597,18 @@ define([ // FORGET (move with href not path) exp.forget = function (href) { + if (!Cryptpad.isLoggedIn()) { + // delete permanently + var data = getFileData(href); + if (data) { + var i = find([FILES_DATA]).indexOf(data); + if (i !== -1) { + exp.removePadAttribute(href); + spliceFileData(i); + } + } + return; + } var paths = findFile(href); move(paths, [TRASH]); }; @@ -603,7 +616,7 @@ define([ // DELETE // Permanently delete multiple files at once using a list of paths // NOTE: We have to be careful when removing elements from arrays (trash root, unsorted or template) - var removePadAttribute = function (f) { + var removePadAttribute = exp.removePadAttribute = function (f) { if (typeof(f) !== 'string') { console.error("Can't find pad attribute for an undefined pad"); return; @@ -619,7 +632,7 @@ define([ }; var checkDeletedFiles = function () { // Nothing in FILES_DATA for workgroups - if (workgroup) { return; } + if (workgroup || !Cryptpad.isLoggedIn()) { return; } var filesList = getFiles([ROOT, 'hrefArray', TRASH]); var toRemove = []; @@ -654,6 +667,23 @@ define([ var hrefPaths = paths.filter(function(x) { return isPathIn(x, ['hrefArray']); }); var rootPaths = paths.filter(function(x) { return isPathIn(x, [ROOT]); }); var trashPaths = paths.filter(function(x) { return isPathIn(x, [TRASH]); }); + var allFilesPaths = paths.filter(function(x) { return isPathIn(x, [FILES_DATA]); }); + + if (!Cryptpad.isLoggedIn()) { + var toSplice = []; + allFilesPaths.forEach(function (path) { + var el = find(path); + toSplice.push(el); + }); + toSplice.forEach(function (el) { + var i = find([FILES_DATA]).indexOf(el); + if (i === -1) { return; } + removePadAttribute(el.href); + console.log(el.href); + spliceFileData(i); + }); + return; + } var hrefs = []; hrefPaths.forEach(function (path) { @@ -882,7 +912,7 @@ define([ toClean.push(el); return; } - if (rootFiles.indexOf(el.href) === -1) { + if (Cryptpad.isLoggedIn() && rootFiles.indexOf(el.href) === -1) { debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", el); var name = el.title || NEW_FILE_NAME; var newName = getAvailableName(root, name); diff --git a/www/drive/file.css b/www/drive/file.css index fed050db1..2f353a371 100644 --- a/www/drive/file.css +++ b/www/drive/file.css @@ -154,6 +154,9 @@ span.fa-folder-open { min-width: 30px; cursor: pointer; } +#tree #allfilesTree { + margin-top: 0; +} #tree #searchContainer { text-align: center; padding: 5px 0; diff --git a/www/drive/file.less b/www/drive/file.less index fe506ae35..13a8adc6b 100644 --- a/www/drive/file.less +++ b/www/drive/file.less @@ -194,6 +194,9 @@ span { } } } + #allfilesTree { + margin-top: 0; + } #searchContainer { text-align: center; padding: 5px 0; diff --git a/www/drive/main.js b/www/drive/main.js index bf853b443..27671f54e 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -205,7 +205,6 @@ define([ var $trashTreeContextMenu = $iframe.find("#trashTreeContextMenu"); var $trashContextMenu = $iframe.find("#trashContextMenu"); - // TOOLBAR /* add a "change username" button */ @@ -227,10 +226,14 @@ define([ if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); } if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; } + if (!Cryptpad.isLoggedIn()) { + displayedCategories = [FILES_DATA]; + currentPath = [FILES_DATA]; + } + if (!APP.readOnly) { setEditable(true); } - var appStatus = { isReady: true, _onReady: [], @@ -1811,14 +1814,16 @@ define([ module.resetTree(); - // in history mode we want to focus the version number input - if (!history.isHistoryMode && !APP.mobile()) { - var st = $tree.scrollTop() || 0; - $tree.find('#searchInput').focus(); - $tree.scrollTop(st); + if (displayedCategories.indexOf(SEARCH) !== -1) { + // in history mode we want to focus the version number input + if (!history.isHistoryMode && !APP.mobile()) { + var st = $tree.scrollTop() || 0; + $tree.find('#searchInput').focus(); + $tree.scrollTop(st); + } + $tree.find('#searchInput')[0].selectionStart = getSearchCursor(); + $tree.find('#searchInput')[0].selectionEnd = getSearchCursor(); } - $tree.find('#searchInput')[0].selectionStart = getSearchCursor(); - $tree.find('#searchInput')[0].selectionEnd = getSearchCursor(); if (!isWorkgroup()) { setLastOpenedFolder(path); @@ -2310,6 +2315,19 @@ define([ else if ($(this).hasClass('delete')) { var pathsList = []; paths.forEach(function (p) { pathsList.push(p.path); }); + if (!Cryptpad.isLoggedIn()) { + console.log(paths); + var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]); + if (paths.length === 1) { + msg = Messages.fm_removePermanentlyDialog; + } + Cryptpad.confirm(msg, function(res) { + $(ifrw).focus(); + if (!res) { return; } + filesOp.delete(pathsList, refresh); + }); + return; + } moveElements(pathsList, [TRASH], false, refresh); } else if ($(this).hasClass("properties")) { @@ -2432,7 +2450,9 @@ define([ $appContainer.on('keydown', function (e) { // "Del" if (e.which === 46) { - if (filesOp.isPathIn(currentPath, [FILES_DATA])) { return; } // We can't remove elements directly from filesData + if (filesOp.isPathIn(currentPath, [FILES_DATA]) && Cryptpad.isLoggedIn()) { + return; // We can't remove elements directly from filesData + } var $selected = $iframe.find('.selected'); if (!$selected.length) { return; } var paths = []; @@ -2442,7 +2462,7 @@ define([ paths.push($(elmt).data('path')); }); // If we are in the trash or anon pad or if we are holding the "shift" key, delete permanently, - if (isTrash || e.shiftKey) { + if (!Cryptpad.isLoggedIn() || isTrash || e.shiftKey) { var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]); if (paths.length === 1) { msg = Messages.fm_removePermanentlyDialog;