diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 41423fe57..4c5ba9fc9 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -107,6 +107,8 @@ define(function () { out.newButton = 'Nouveau'; out.newButtonTitle = 'Créer un nouveau pad'; + out.uploadButton = 'Upload'; + out.uploadButtonTitle = 'Uploader un nouveau fichier dans le dossier actuel'; out.saveTemplateButton = "Sauver en tant que modèle"; out.saveTemplatePrompt = "Choisir un titre pour ce modèle"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index c549a6009..ceade6204 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -109,6 +109,8 @@ define(function () { out.newButton = 'New'; out.newButtonTitle = 'Create a new pad'; + out.uploadButton = 'Upload'; + out.uploadButtonTitle = 'Upload a new file to the current folder'; out.saveTemplateButton = "Save as template"; out.saveTemplatePrompt = "Choose a title for the template"; diff --git a/www/common/common-file.js b/www/common/common-file.js index b6c59e581..43d7cff2a 100644 --- a/www/common/common-file.js +++ b/www/common/common-file.js @@ -223,7 +223,6 @@ define([ }; var handleFile = File.handleFile = function (file, e) { - console.log(file); var reader = new FileReader(); reader.onloadend = function () { queue.push({ @@ -238,7 +237,13 @@ define([ reader.readAsArrayBuffer(file); }; - var createAreaHandlers = File.createDropArea = function ($area, $hoverArea, todo) { + var onFileDrop = File.onFileDrop = function (file, e) { + Array.prototype.slice.call(file).forEach(function (d) { + handleFile(d, e); + }); + }; + + var createAreaHandlers = File.createDropArea = function ($area, $hoverArea) { var counter = 0; if (!$hoverArea) { $hoverArea = $area; } $hoverArea @@ -267,15 +272,14 @@ define([ var dropped = e.originalEvent.dataTransfer.files; counter = 0; $hoverArea.removeClass('hovering'); - - Array.prototype.slice.call(dropped).forEach(function (d) { - todo(d, e); - }); + onFileDrop(dropped, e); }); }; var createUploader = function ($area, $hover, $body) { - createAreaHandlers($area, null, handleFile); + if (!config.noHandlers) { + createAreaHandlers($area, null); + } createTableContainer($body); }; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index fba8c8035..49d756168 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -585,25 +585,26 @@ define([ return pad; }); + if (updateWeaker.length > 0) { + updateWeaker.forEach(function (obj) { + // If we have a stronger url, and if all the occurences of the weaker were + // in the trash, add remove them from the trash and add the stronger in root + getStore().restoreHref(obj.n); + }); + } if (!contains && href) { var data = makePad(href, name); getStore().pushData(data, function (e, id) { if (e) { if (e === 'E_OVER_LIMIT') { common.alert(Messages.pinLimitNotPinned, null, true); - return; } - else { return void cb(e); } + return void cb(e); } getStore().addPad(id, common.initialPath); + cb(err, recent); }); - } - if (updateWeaker.length > 0) { - updateWeaker.forEach(function (obj) { - // If we have a stronger url, and if all the occurences of the weaker were - // in the trash, add remove them from the trash and add the stronger in root - getStore().restoreHref(obj.n); - }); + return; } cb(err, recent); }); diff --git a/www/common/toolbar2.js b/www/common/toolbar2.js index 39bfc49e8..b96d072ac 100644 --- a/www/common/toolbar2.js +++ b/www/common/toolbar2.js @@ -96,6 +96,10 @@ define([ } else { styleToolbar($container); } + $container.on('drop dragover', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); return $toolbar; }; diff --git a/www/drive/main.js b/www/drive/main.js index bcba56df6..0d1f6c0e3 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -205,6 +205,17 @@ define([ var $trashTreeContextMenu = $iframe.find("#trashTreeContextMenu"); var $trashContextMenu = $iframe.find("#trashContextMenu"); + $tree.on('drop dragover', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + $driveToolbar.on('drop dragover', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + + + // TOOLBAR /* add a "change username" button */ @@ -954,23 +965,7 @@ define([ if (filesOp.isPathIn(newPath, [TRASH]) && paths.length && paths[0][0] === TRASH) { return; } - // "force" is currently unused but may be configurable by user - if (newPath[0] !== TRASH || force) { - andThen(); - return; - } - var msg = Messages._getKey('fm_removeSeveralDialog', [paths.length]); - if (paths.length === 1) { - var path = paths[0].slice(); - var el = filesOp.find(path); - var name = filesOp.isFile(el) ? getElementName(path) : path.pop(); - msg = Messages._getKey('fm_removeDialog', [name]); - } - Cryptpad.confirm(msg, function (res) { - $(ifrw).focus(); - if (!res) { return; } - andThen(); - }); + andThen(); }; // Drag & drop: // The data transferred is a stringified JSON containing the path of the dragged element @@ -1012,13 +1007,30 @@ define([ ev.dataTransfer.setData("text", stringify(data)); }; + var onFileDrop = APP.onFileDrop = function (file, e) { + APP.FM.onFileDrop(file, e); + }; + var findDropPath = function (target) { + var $target = $(target); + var $el = findDataHolder($target); + var newPath = $el.data('path'); + if ((!newPath || filesOp.isFile(filesOp.find(newPath))) + && $target.parents('#content')) { + newPath = currentPath; + } + return newPath; + }; var onDrop = function (ev) { ev.preventDefault(); $iframe.find('.droppable').removeClass('droppable'); var data = ev.dataTransfer.getData("text"); + + // Don't the the normal drop handler for file upload + var fileDrop = ev.dataTransfer.files; + if (fileDrop.length) { return void onFileDrop(fileDrop, ev); } + var oldPaths = JSON.parse(data).path; if (!oldPaths) { return; } - // Dropped elements can be moved from the same file manager or imported from another one. // A moved element should be removed from its previous location var movedPaths = []; @@ -1032,8 +1044,7 @@ define([ } }); - var $el = findDataHolder($(ev.target)); - var newPath = $el.data('path'); + var newPath = findDropPath(ev.target); if (!newPath) { return; } if (movedPaths && movedPaths.length) { moveElements(movedPaths, newPath, null, refresh); @@ -1069,6 +1080,8 @@ define([ e.preventDefault(); }); $element.on('drop', function (e) { + e.preventDefault(); + e.stopPropagation(); onDrop(e.originalEvent); }); $element.on('dragenter', function (e) { @@ -1087,6 +1100,7 @@ define([ } }); }; + addDragAndDropHandlers($content, null, true, true); // In list mode, display metadata from the filesData object // _WORKGROUP_ : Do not display title, atime and ctime columns since we don't have files data @@ -1427,6 +1441,30 @@ define([ return $block; }; + var createUploadButton = function () { + var inTrash = filesOp.isPathIn(currentPath, [TRASH]); + var $icon = $('', { + 'class': 'fa fa-upload' + }); + var $input = $('', { + 'type': 'file', + 'style': 'display: none;' + }).on('change', function (e) { + var file = e.target.files[0]; + var ev = { + target: $content[0] + }; + APP.FM.handleFile(file, ev); + }); + var $button = $('