Add an upload button to the slide's file picker

pull/1/head
yflory 8 years ago
parent c717d01714
commit 66b076111e

@ -134,8 +134,9 @@ define(function () {
out.filePickerButton = "Intégrer un fichier"; out.filePickerButton = "Intégrer un fichier";
out.filePicker_close = "Fermer"; out.filePicker_close = "Fermer";
out.filePicker_description = "Choisissez un fichier de votre CryptDrive pour l'intégrer"; out.filePicker_description = "Choisissez un fichier de votre CryptDrive pour l'intégrer ou uploadez-en un nouveau";
out.filePicker_filter = "Filtrez les fichiers par leur nom"; out.filePicker_filter = "Filtrez les fichiers par leur nom";
out.or = 'ou';
out.slideOptionsTitle = "Personnaliser la présentation"; out.slideOptionsTitle = "Personnaliser la présentation";
out.slideOptionsButton = "Enregistrer (Entrée)"; out.slideOptionsButton = "Enregistrer (Entrée)";

@ -136,8 +136,9 @@ define(function () {
out.filePickerButton = "Embed a file"; out.filePickerButton = "Embed a file";
out.filePicker_close = "Close"; out.filePicker_close = "Close";
out.filePicker_description = "Choose a file from your CryptDrive to embed it"; out.filePicker_description = "Choose a file from your CryptDrive to embed it or upload a new one";
out.filePicker_filter = "Filter files by name"; out.filePicker_filter = "Filter files by name";
out.or = 'or';
out.slideOptionsTitle = "Customize your slides"; out.slideOptionsTitle = "Customize your slides";
out.slideOptionsButton = "Save (enter)"; out.slideOptionsButton = "Save (enter)";

@ -945,6 +945,25 @@ define([
})); }));
} }
break; break;
case 'upload':
button = $('<button>', {
'class': 'btn btn-primary new',
title: Messages.uploadButtonTitle,
}).append($('<span>', {'class':'fa fa-upload'})).append(' '+Messages.uploadButton);
if (!data.FM) { return; }
var $input = $('<input>', {
'type': 'file',
'style': 'display: none;'
}).on('change', function (e) {
var file = e.target.files[0];
var ev = {
target: data.target
};
data.FM.handleFile(file, ev);
if (callback) { callback(); }
});
button.click(function () { $input.click(); })
break;
case 'template': case 'template':
if (!AppConfig.enableTemplates) { return; } if (!AppConfig.enableTemplates) { return; }
button = $('<button>', { button = $('<button>', {

@ -1439,26 +1439,11 @@ define([
var createUploadButton = function () { var createUploadButton = function () {
var inTrash = filesOp.isPathIn(currentPath, [TRASH]); var inTrash = filesOp.isPathIn(currentPath, [TRASH]);
if (inTrash) { return; } if (inTrash) { return; }
var $icon = $('<span>', { var data = {
'class': 'fa fa-upload' FM: APP.FM,
}); target: $content[0]
var $input = $('<input>', { };
'type': 'file', return Cryptpad.createButton('upload', false, data);
'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 () {

@ -244,6 +244,11 @@ define([
if (to) { window.clearTimeout(to); } if (to) { window.clearTimeout(to); }
to = window.setTimeout(updateContainer, 300); to = window.setTimeout(updateContainer, 300);
}); });
$filter.append(' '+Messages.or+' ');
var data = {FM: APP.FM};
$filter.append(Cryptpad.createButton('upload', false, data, function () {
$block.hide();
}));
updateContainer(); updateContainer();
$body.keydown(function (e) { $body.keydown(function (e) {
if (e.which === 27) { $block.hide(); } if (e.which === 27) { $block.hide(); }
@ -578,27 +583,16 @@ define([
dropArea: $iframe.find('.CodeMirror'), dropArea: $iframe.find('.CodeMirror'),
body: $iframe.find('body'), body: $iframe.find('body'),
onUploaded: function (ev, data) { onUploaded: function (ev, data) {
console.log(ev, data);
/*
TODO: test if getCursor() works
If we can drop a file without updating the cursor, we'll need the following
code to get the cursor position from the drop event
var obj = {
left: ev.originalEvent.pageX,
top: ev.originalEvent.pageY,
};
var cursor = editor.coordsChar(obj);
*/
//var cursor = editor.getCursor(); //var cursor = editor.getCursor();
var cleanName = data.name.replace(/[\[\]]/g, ''); var cleanName = data.name.replace(/[\[\]]/g, '');
var text = '['+cleanName+']('+data.url+')'; var text = '!['+cleanName+']('+data.url+')';
if (data.mediatag) { /*if (data.mediatag) {
text = '!'+text; text = '!'+text;
} }*/
editor.replaceSelection(text); editor.replaceSelection(text);
} }
}; };
Cryptpad.createFileManager(fmConfig); APP.FM = Cryptpad.createFileManager(fmConfig);
}; };
config.onRemote = function () { config.onRemote = function () {

Loading…
Cancel
Save