Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

pull/1/head
ansuz 8 years ago
commit d25a0893cf

@ -107,6 +107,8 @@ define(function () {
out.newButton = 'Nouveau'; out.newButton = 'Nouveau';
out.newButtonTitle = 'Créer un nouveau pad'; 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.saveTemplateButton = "Sauver en tant que modèle";
out.saveTemplatePrompt = "Choisir un titre pour ce modèle"; out.saveTemplatePrompt = "Choisir un titre pour ce modèle";

@ -109,6 +109,8 @@ define(function () {
out.newButton = 'New'; out.newButton = 'New';
out.newButtonTitle = 'Create a new pad'; 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.saveTemplateButton = "Save as template";
out.saveTemplatePrompt = "Choose a title for the template"; out.saveTemplatePrompt = "Choose a title for the template";

@ -223,7 +223,6 @@ define([
}; };
var handleFile = File.handleFile = function (file, e) { var handleFile = File.handleFile = function (file, e) {
console.log(file);
var reader = new FileReader(); var reader = new FileReader();
reader.onloadend = function () { reader.onloadend = function () {
queue.push({ queue.push({
@ -238,7 +237,13 @@ define([
reader.readAsArrayBuffer(file); 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; var counter = 0;
if (!$hoverArea) { $hoverArea = $area; } if (!$hoverArea) { $hoverArea = $area; }
$hoverArea $hoverArea
@ -267,15 +272,14 @@ define([
var dropped = e.originalEvent.dataTransfer.files; var dropped = e.originalEvent.dataTransfer.files;
counter = 0; counter = 0;
$hoverArea.removeClass('hovering'); $hoverArea.removeClass('hovering');
onFileDrop(dropped, e);
Array.prototype.slice.call(dropped).forEach(function (d) {
todo(d, e);
});
}); });
}; };
var createUploader = function ($area, $hover, $body) { var createUploader = function ($area, $hover, $body) {
createAreaHandlers($area, null, handleFile); if (!config.noHandlers) {
createAreaHandlers($area, null);
}
createTableContainer($body); createTableContainer($body);
}; };

@ -585,25 +585,26 @@ define([
return pad; 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) { if (!contains && href) {
var data = makePad(href, name); var data = makePad(href, name);
getStore().pushData(data, function (e, id) { getStore().pushData(data, function (e, id) {
if (e) { if (e) {
if (e === 'E_OVER_LIMIT') { if (e === 'E_OVER_LIMIT') {
common.alert(Messages.pinLimitNotPinned, null, true); common.alert(Messages.pinLimitNotPinned, null, true);
return;
} }
else { return void cb(e); } return void cb(e);
} }
getStore().addPad(id, common.initialPath); getStore().addPad(id, common.initialPath);
cb(err, recent);
}); });
} return;
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);
});
} }
cb(err, recent); cb(err, recent);
}); });

@ -96,6 +96,10 @@ define([
} else { } else {
styleToolbar($container); styleToolbar($container);
} }
$container.on('drop dragover', function (e) {
e.preventDefault();
e.stopPropagation();
});
return $toolbar; return $toolbar;
}; };

@ -205,6 +205,17 @@ define([
var $trashTreeContextMenu = $iframe.find("#trashTreeContextMenu"); var $trashTreeContextMenu = $iframe.find("#trashTreeContextMenu");
var $trashContextMenu = $iframe.find("#trashContextMenu"); 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 // TOOLBAR
/* add a "change username" button */ /* add a "change username" button */
@ -954,23 +965,7 @@ define([
if (filesOp.isPathIn(newPath, [TRASH]) && paths.length && paths[0][0] === TRASH) { if (filesOp.isPathIn(newPath, [TRASH]) && paths.length && paths[0][0] === TRASH) {
return; 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: // Drag & drop:
// The data transferred is a stringified JSON containing the path of the dragged element // 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)); 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) { var onDrop = function (ev) {
ev.preventDefault(); ev.preventDefault();
$iframe.find('.droppable').removeClass('droppable'); $iframe.find('.droppable').removeClass('droppable');
var data = ev.dataTransfer.getData("text"); 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; var oldPaths = JSON.parse(data).path;
if (!oldPaths) { return; } if (!oldPaths) { return; }
// Dropped elements can be moved from the same file manager or imported from another one. // 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 // A moved element should be removed from its previous location
var movedPaths = []; var movedPaths = [];
@ -1032,8 +1044,7 @@ define([
} }
}); });
var $el = findDataHolder($(ev.target)); var newPath = findDropPath(ev.target);
var newPath = $el.data('path');
if (!newPath) { return; } if (!newPath) { return; }
if (movedPaths && movedPaths.length) { if (movedPaths && movedPaths.length) {
moveElements(movedPaths, newPath, null, refresh); moveElements(movedPaths, newPath, null, refresh);
@ -1069,6 +1080,8 @@ define([
e.preventDefault(); e.preventDefault();
}); });
$element.on('drop', function (e) { $element.on('drop', function (e) {
e.preventDefault();
e.stopPropagation();
onDrop(e.originalEvent); onDrop(e.originalEvent);
}); });
$element.on('dragenter', function (e) { $element.on('dragenter', function (e) {
@ -1087,6 +1100,7 @@ define([
} }
}); });
}; };
addDragAndDropHandlers($content, null, true, true);
// In list mode, display metadata from the filesData object // 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 // _WORKGROUP_ : Do not display title, atime and ctime columns since we don't have files data
@ -1427,6 +1441,30 @@ define([
return $block; return $block;
}; };
var createUploadButton = function () {
var inTrash = filesOp.isPathIn(currentPath, [TRASH]);
var $icon = $('<span>', {
'class': 'fa fa-upload'
});
var $input = $('<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 = $('<button>', {
'class': 'btn btn-primary new',
title: Messages.uploadButtonTitle
}).append($icon).append(' '+Messages.uploadButton).click(function () {
$input.click();
});
return $button;
};
var hideNewButton = function () { var hideNewButton = function () {
$iframe.find('.dropdown-bar-content').hide(); $iframe.find('.dropdown-bar-content').hide();
}; };
@ -1863,6 +1901,7 @@ define([
// NewButton can be undefined if we're in read only mode // NewButton can be undefined if we're in read only mode
$toolbar.find('.leftside').append(createNewButton(isInRoot)); $toolbar.find('.leftside').append(createNewButton(isInRoot));
$toolbar.find('.leftside').append(createUploadButton());
var $folderHeader = getFolderListHeader(); var $folderHeader = getFolderListHeader();
@ -2375,8 +2414,7 @@ define([
var name = paths[0].path[paths[0].path.length - 1]; var name = paths[0].path[paths[0].path.length - 1];
if ($(this).hasClass("remove")) { if ($(this).hasClass("remove")) {
if (paths.length === 1) { if (paths.length === 1) {
if (path.length === 4) { name = path[1]; } Cryptpad.confirm(Messages.fm_removePermanentlyDialog, function(res) {
Cryptpad.confirm(Messages._getKey("fm_removePermanentlyDialog", [name]), function(res) {
if (!res) { return; } if (!res) { return; }
filesOp.delete([path], refresh); filesOp.delete([path], refresh);
}); });
@ -2392,7 +2430,14 @@ define([
} }
else if ($(this).hasClass("restore")) { else if ($(this).hasClass("restore")) {
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
if (path.length === 4) { name = path[1]; } if (path.length === 4) {
var el = filesOp.find(path);
if (filesOp.isFile(el)) {
name = filesOp.getTitle(el);
} else {
name = path[1];
}
}
Cryptpad.confirm(Messages._getKey("fm_restoreDialog", [name]), function(res) { Cryptpad.confirm(Messages._getKey("fm_restoreDialog", [name]), function(res) {
if (!res) { return; } if (!res) { return; }
filesOp.restore(path, refresh); filesOp.restore(path, refresh);
@ -2559,6 +2604,29 @@ define([
if (typeof(cb) === "function") { cb(); } if (typeof(cb) === "function") { cb(); }
}; };
var fmConfig = {
noHandlers: true,
onUploaded: function (ev, data) {
try {
// Get the folder path
var newPath = findDropPath(ev.target);
if (!newPath) { return void refresh(); }
var href = data.url;
// Get the current file location in ROOT
var id = filesOp.getIdFromHref(href);
var paths = filesOp.findFile(id);
if (paths.length !== 1) { return; }
// Try to move and refresh
moveElements([paths[0]], newPath, true);
refresh();
} catch (e) {
console.error(e);
refresh();
}
}
};
APP.FM = Cryptpad.createFileManager(fmConfig);
createReadme(proxy, function () { createReadme(proxy, function () {
refresh(); refresh();
APP.userList.onChange(); APP.userList.onChange();
@ -2657,7 +2725,7 @@ define([
var userList = APP.userList = info.userList; var userList = APP.userList = info.userList;
var config = { var config = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'limit'], displayed: ['useradmin', 'spinner', 'lag', 'state', 'limit', 'newpad'],
userList: { userList: {
list: userList, list: userList,
userNetfluxId: info.myID userNetfluxId: info.myID

@ -77,42 +77,3 @@ body {
z-index: 10000; z-index: 10000;
display: block; display: block;
} }
#uploadStatus {
display: none;
width: 80vw;
margin-top: 50px;
margin-left: 10vw;
border: 1px solid black;
border-collapse: collapse;
}
#uploadStatus tr:nth-child(1) {
background-color: #ccc;
border: 1px solid #999;
}
#uploadStatus tr:nth-child(1) td {
text-align: center;
}
#uploadStatus td {
border-left: 1px solid #BBB;
border-right: 1px solid #BBB;
padding: 0 10px;
}
#uploadStatus .upProgress {
width: 200px;
position: relative;
text-align: center;
}
#uploadStatus .progressContainer {
position: absolute;
width: 0px;
left: 5px;
top: 1px;
bottom: 1px;
background-color: rgba(0, 0, 255, 0.3);
}
#uploadStatus .upCancel {
text-align: center;
}
#uploadStatus .fa.cancel {
color: #ff0073;
}

@ -87,38 +87,3 @@ html, body {
display: block; display: block;
} }
#uploadStatus {
display: none;
width: 80vw;
margin-top: 50px;
margin-left: 10vw;
border: 1px solid black;
border-collapse: collapse;
tr:nth-child(1) {
background-color: #ccc;
border: 1px solid #999;
td { text-align: center; }
}
td {
border-left: 1px solid #BBB;
border-right: 1px solid #BBB;
padding: 0 10px;
}
.upProgress {
width: 200px;
position: relative;
text-align: center;
}
.progressContainer {
position: absolute;
width: 0px;
left: 5px;
top: 1px; bottom: 1px;
background-color: rgba(0,0,255,0.3);
}
.upCancel { text-align: center; }
.fa.cancel {
color: rgb(255, 0, 115);
}
}

@ -511,11 +511,6 @@ define([
if (readOnly) { return; } if (readOnly) { return; }
UserList.getLastName(toolbar.$userNameButton, isNew); UserList.getLastName(toolbar.$userNameButton, isNew);
/*editor.on('dragover', function (e) {
//console.log(editor.coordsChar());
console.log(e);
});*/
var fmConfig = { var fmConfig = {
dropArea: $iframe.find('.CodeMirror'), dropArea: $iframe.find('.CodeMirror'),
body: $iframe.find('body'), body: $iframe.find('body'),

Loading…
Cancel
Save