From 0c2987a6d123b961e049a2fad405c84049ae0d1d Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 22 Mar 2018 17:01:01 +0100 Subject: [PATCH] Import template in existing pads --- customize.dist/translations/messages.fr.js | 2 + customize.dist/translations/messages.js | 2 + www/common/common-ui-elements.js | 50 ++++++++++++++++++++-- www/common/sframe-app-framework.js | 3 ++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 47bce2af8..911ee3821 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -145,6 +145,8 @@ define(function () { out.useTemplate = "Commencer avec un modèle?"; out.useTemplateOK = 'Choisir un modèle (Entrée)'; 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"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 6ab51d35d..4e81182e9 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -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.useTemplateOK = 'Pick a template (Enter)'; 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"; diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index e25c3ee2e..8cadc5c31 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -482,13 +482,44 @@ define([ 'class': 'fa fa-upload cp-toolbar-icon-import', title: Messages.importButtonTitle, }).append($('', {'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 .click(common.prepareFeedback(type)) .click(importContent('text/plain', function (content, file) { callback(content, file); }, {accept: data ? data.accept : undefined})); - } + //} break; case 'upload': button = $('