From 3f8b6d3b8afe15dec65d15807b8caf7ee62101ec Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 4 Jun 2018 16:02:58 +0200 Subject: [PATCH] Fix default title issues when using a template --- www/common/common-ui-elements.js | 1 - www/common/cryptpad-common.js | 20 ++++++++++++++++++++ www/common/sframe-common-title.js | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 3c1c9c7ab..bf3315f33 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -626,7 +626,6 @@ define([ } } sframeChan.query('Q_SAVE_AS_TEMPLATE', { - title: title, toSave: toSave }, function () { UI.alert(Messages.templateSaved); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index f91f050e8..9131b34c6 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -446,6 +446,26 @@ define([ }).nThen(function () { Crypt.get(parsed.hash, function (err, val) { if (err) { throw new Error(err); } + try { + // Try to fix the title before importing the template + var parsed = JSON.parse(val); + var meta; + if (Array.isArray(parsed) && typeof(parsed[3]) === "object") { + meta = parsed[3].metadata; // pad + } else if (parsed.info) { + meta = parsed.info; // poll + } else { + meta = parsed.metadata; + } + if (typeof(meta) === "object") { + meta.defaultTitle = meta.title || meta.defaultTitle; + delete meta.users; + delete meta.title; + } + val = JSON.stringify(parsed); + } catch (e) { + console.log("Can't fix template title", e); + } Crypt.put(parsed2.hash, val, cb, optsPut); }, optsGet); }); diff --git a/www/common/sframe-common-title.js b/www/common/sframe-common-title.js index 317944993..0a838ef34 100644 --- a/www/common/sframe-common-title.js +++ b/www/common/sframe-common-title.js @@ -42,6 +42,9 @@ define([ exp.updateTitle = function (newTitle, cb) { cb = cb || $.noop; if (newTitle === exp.title) { return void cb(); } + if (newTitle === exp.defaultTitle) { + newTitle = ""; + } metadataMgr.updateTitle(newTitle); titleUpdated = cb; }; @@ -51,7 +54,9 @@ define([ if ($title) { $title.find('span.cp-toolbar-title-value').text(md.title || md.defaultTitle); $title.find('input').val(md.title || md.defaultTitle); + $title.find('input').prop('placeholder', md.defaultTitle); } + exp.defaultTitle = md.defaultTitle; exp.title = md.title; }); metadataMgr.onTitleChange(function (title) {