diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 273a3d06d..207d00336 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -430,6 +430,7 @@ define([ common.mailbox.sendTo("SHARE_PAD", { href: href, password: config.password, + isTemplate: config.isTemplate, name: myName, title: title }, { diff --git a/www/common/notifications.js b/www/common/notifications.js index 7a90b2e0c..84beb4991 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -4,8 +4,10 @@ define([ '/common/common-hash.js', '/common/common-interface.js', '/common/common-ui-elements.js', + '/common/common-constants.js', '/customize/messages.js', -], function ($, h, Hash, UI, UIElements, Messages) { + '/bower_components/nthen/index.js' +], function ($, h, Hash, UI, UIElements, Constants, Messages, nThen) { var handlers = {}; @@ -83,11 +85,16 @@ define([ common.openURL(msg.content.href); defaultDismiss(common, data)(); }; - if (!msg.content.password) { return void todo(); } - common.getSframeChannel().query('Q_SESSIONSTORAGE_PUT', { - key: 'newPadPassword', - value: msg.content.password - }, todo); + nThen(function (waitFor) { + if (msg.content.isTemplate) { + common.sessionStorage.put(Constants.newPadPathKey, ['template'], waitFor()); + } + if (msg.content.password) { + common.sessionStorage.put('newPadPassword', msg.content.password, waitFor()); + } + }).nThen(function () { + todo(); + }); }; if (!content.archived) { content.dismissHandler = defaultDismiss(common, data); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 81ea43d81..13229969d 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -272,23 +272,25 @@ define([ var parsed = Utils.Hash.parsePadUrl(window.location.href); if (!parsed.type) { throw new Error(); } var defaultTitle = Utils.Hash.getDefaultName(parsed); - var edPublic; + var edPublic, isTemplate; var forceCreationScreen = cfg.useCreationScreen && sessionStorage[Utils.Constants.displayPadCreationScreen]; delete sessionStorage[Utils.Constants.displayPadCreationScreen]; var updateMeta = function () { //console.log('EV_METADATA_UPDATE'); - var metaObj, isTemplate; + var metaObj; nThen(function (waitFor) { Cryptpad.getMetadata(waitFor(function (err, m) { if (err) { console.log(err); } metaObj = m; edPublic = metaObj.priv.edPublic; // needed to create an owned pad })); - Cryptpad.isTemplate(window.location.href, waitFor(function (err, t) { - if (err) { console.log(err); } - isTemplate = t; - })); + if (typeof(isTemplate) === "undefined") { + Cryptpad.isTemplate(window.location.href, waitFor(function (err, t) { + if (err) { console.log(err); } + isTemplate = t; + })); + } }).nThen(function (/*waitFor*/) { metaObj.doc = { defaultTitle: defaultTitle, @@ -735,6 +737,7 @@ define([ var initShareModal = function (cfg) { cfg.hashes = hashes; cfg.password = password; + cfg.isTemplate = isTemplate; // cfg.hidden means pre-loading the filepicker while keeping it hidden. // if cfg.hidden is true and the iframe already exists, do nothing if (!ShareModal.$iframe) { diff --git a/www/drive/inner.js b/www/drive/inner.js index f69c36060..fd7723bca 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3601,6 +3601,7 @@ define([ hash: parsed.hash, password: data.password }, + isTemplate: paths[0].path[0] === 'template', title: data.title, common: common }; diff --git a/www/share/inner.js b/www/share/inner.js index d50bb9a9c..a7543e115 100644 --- a/www/share/inner.js +++ b/www/share/inner.js @@ -43,6 +43,7 @@ define([ origin: origin, pathname: pathname, password: priv.password, + isTemplate: priv.isTemplate, hashes: hashes, common: common, title: data.title, diff --git a/www/share/main.js b/www/share/main.js index 3f51fbb50..5b1c4fb38 100644 --- a/www/share/main.js +++ b/www/share/main.js @@ -91,6 +91,7 @@ define([ feedbackAllowed: Utils.Feedback.state, hashes: config.data.hashes, password: config.data.password, + isTemplate: config.data.isTemplate, file: config.data.file, }; for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }