Import template in existing pads

pull/1/head
yflory 7 years ago
parent d4dfbddaa6
commit 0c2987a6d1

@ -145,6 +145,8 @@ define(function () {
out.useTemplate = "Commencer avec un modèle?"; out.useTemplate = "Commencer avec un modèle?";
out.useTemplateOK = 'Choisir un modèle (Entrée)'; out.useTemplateOK = 'Choisir un modèle (Entrée)';
out.useTemplateCancel = 'Document vierge (Échap)'; out.useTemplateCancel = 'Document vierge (Échap)';
out.template_import = "Importer un modèle";
out.template_empty = "Aucun modèle disponible";
out.previewButtonTitle = "Afficher ou cacher la prévisualisation de Markdown"; out.previewButtonTitle = "Afficher ou cacher la prévisualisation de Markdown";

@ -146,6 +146,8 @@ define(function () {
out.useTemplate = "Start with a template?"; //Would you like to "You have available templates for this type of pad. Do you want to use one?"; out.useTemplate = "Start with a template?"; //Would you like to "You have available templates for this type of pad. Do you want to use one?";
out.useTemplateOK = 'Pick a template (Enter)'; out.useTemplateOK = 'Pick a template (Enter)';
out.useTemplateCancel = 'Start fresh (Esc)'; out.useTemplateCancel = 'Start fresh (Esc)';
out.template_import = "Import a template";
out.template_empty = "No template available";
out.previewButtonTitle = "Display or hide the Markdown preview mode"; out.previewButtonTitle = "Display or hide the Markdown preview mode";

@ -482,13 +482,44 @@ define([
'class': 'fa fa-upload cp-toolbar-icon-import', 'class': 'fa fa-upload cp-toolbar-icon-import',
title: Messages.importButtonTitle, title: Messages.importButtonTitle,
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.importButton)); }).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.importButton));
if (callback) { /*if (data.types) {
// New import button in the toolbar
var importFunction = {
template: function () {
UIElements.openTemplatePicker(common, true);
},
file: function (cb) {
importContent('text/plain', function (content, file) {
cb(content, file);
}, {accept: data ? data.accept : undefined})
}
};
var toImport = [];
Object.keys(data.types).forEach(function (importType) {
if (!importFunction[importType] || !data.types[importType]) { return; }
var option = h('button', importType);
$(option).click(function () {
importFunction[importType](data.types[importType]);
});
toImport.push(options);
});
button.click(common.prepareFeedback(type));
if (toImport.length === 1) {
button.click(function () { $(toImport[0]).click(); });
} else {
Cryptpad.alert(h('p.cp-import-container', toImport));
}
}
else if (callback) {*/
// Old import button, used in settings
button button
.click(common.prepareFeedback(type)) .click(common.prepareFeedback(type))
.click(importContent('text/plain', function (content, file) { .click(importContent('text/plain', function (content, file) {
callback(content, file); callback(content, file);
}, {accept: data ? data.accept : undefined})); }, {accept: data ? data.accept : undefined}));
} //}
break; break;
case 'upload': case 'upload':
button = $('<button>', { button = $('<button>', {
@ -520,6 +551,16 @@ define([
if (data.accept) { $input.attr('accept', data.accept); } if (data.accept) { $input.attr('accept', data.accept); }
button.click(function () { $input.click(); }); button.click(function () { $input.click(); });
break; break;
case 'importtemplate':
button = $('<button>', {
'class': 'fa fa-upload cp-toolbar-icon-import',
title: Messages.template_import,
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.template_import));
button
.click(common.prepareFeedback(type))
.click(function () {
});
break;
case 'template': case 'template':
if (!AppConfig.enableTemplates) { return; } if (!AppConfig.enableTemplates) { return; }
if (!common.isLoggedIn()) { return; } if (!common.isLoggedIn()) { return; }
@ -1742,7 +1783,7 @@ define([
sframeChan.event("EV_FILE_PICKER_OPEN", types); sframeChan.event("EV_FILE_PICKER_OPEN", types);
}; };
UIElements.openTemplatePicker = function (common) { UIElements.openTemplatePicker = function (common, force) {
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
var type = metadataMgr.getMetadataLazy().type; var type = metadataMgr.getMetadataLazy().type;
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
@ -1782,10 +1823,13 @@ define([
if (data) { if (data) {
common.openFilePicker(pickerCfg); common.openFilePicker(pickerCfg);
focus = document.activeElement; focus = document.activeElement;
if (force) { return void onConfirm(true); }
UI.confirm(Messages.useTemplate, onConfirm, { UI.confirm(Messages.useTemplate, onConfirm, {
ok: Messages.useTemplateOK, ok: Messages.useTemplateOK,
cancel: Messages.useTemplateCancel, cancel: Messages.useTemplateCancel,
}); });
} else if (force) {
UI.alert(Messages.template_empty);
} }
}); });
}; };

@ -572,6 +572,9 @@ define([
toolbar.$rightside.append($templateButton); toolbar.$rightside.append($templateButton);
} }
var $importTemplateButton = common.createButton('importtemplate', true, templateObj);
toolbar.$drawer.append($importTemplateButton);
/* add a forget button */ /* add a forget button */
toolbar.$rightside.append(common.createButton('forget', true, {}, function (err) { toolbar.$rightside.append(common.createButton('forget', true, {}, function (err) {
if (err) { return; } if (err) { return; }

Loading…
Cancel
Save