Add templates for OnlyOffice in the PCS

pull/1/head
yflory 4 years ago
parent 073025b4e4
commit a16b43b25c

@ -2094,7 +2094,7 @@ define([
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
var privateData = metadataMgr.getPrivateData(); var privateData = metadataMgr.getPrivateData();
var type = metadataMgr.getMetadataLazy().type; var type = metadataMgr.getMetadataLazy().type || privateData.app;
var fromFileData = privateData.fromFileData; var fromFileData = privateData.fromFileData;
var $body = $('body'); var $body = $('body');

@ -113,6 +113,7 @@ define([
}; };
var getEditor = function () { var getEditor = function () {
if (!window.frames || !window.frames[0]) { return; }
return window.frames[0].editor || window.frames[0].editorCell; return window.frames[0].editor || window.frames[0].editorCell;
}; };
@ -1852,14 +1853,15 @@ define([
var loadTemplate = function (href, pw, parsed) { var loadTemplate = function (href, pw, parsed) {
APP.history = true; APP.history = true;
APP.template = true; APP.template = true;
getEditor().setViewModeDisconnect(); var editor = getEditor();
if (editor) { editor.setViewModeDisconnect(); }
var content = parsed.content; var content = parsed.content;
// Get checkpoint // Get checkpoint
var hashes = content.hashes || {}; var hashes = content.hashes || {};
var idx = sortCpIndex(hashes); var idx = sortCpIndex(hashes);
var lastIndex = idx[idx.length - 1]; var lastIndex = idx[idx.length - 1];
var lastCp = hashes[lastIndex]; var lastCp = hashes[lastIndex] || {};
// Current cp or initial hash (invalid hash ==> initial hash) // Current cp or initial hash (invalid hash ==> initial hash)
var toHash = lastCp.hash || 'NONE'; var toHash = lastCp.hash || 'NONE';
@ -2231,11 +2233,18 @@ define([
openRtChannel(function () { openRtChannel(function () {
setMyId(); setMyId();
oldHashes = JSON.parse(JSON.stringify(content.hashes)); oldHashes = JSON.parse(JSON.stringify(content.hashes));
loadDocument(newDoc, useNewDefault);
initializing = false; initializing = false;
common.openPadChat(APP.onLocal);
if (APP.startWithTemplate) {
var template = APP.startWithTemplate;
loadTemplate(template.href, template.password, template.content);
return;
}
loadDocument(newDoc, useNewDefault);
setEditable(!readOnly); setEditable(!readOnly);
UI.removeLoadingScreen(); UI.removeLoadingScreen();
common.openPadChat(APP.onLocal);
}); });
}; };
@ -2359,8 +2368,11 @@ define([
})); }));
SFCommon.create(waitFor(function (c) { APP.common = common = c; })); SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
common.getSframeChannel().on('EV_OO_TEMPLATE', function (data) {
APP.startWithTemplate = data;
});
common.handleNewFile(waitFor, { common.handleNewFile(waitFor, {
noTemplates: true //noTemplates: true
}); });
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
andThen(common); andThen(common);

@ -1646,6 +1646,7 @@ define([
rtConfig.metadata.validateKey = (secret.keys && secret.keys.validateKey) || undefined; rtConfig.metadata.validateKey = (secret.keys && secret.keys.validateKey) || undefined;
Utils.rtConfig = rtConfig; Utils.rtConfig = rtConfig;
var templatePw;
nThen(function(waitFor) { nThen(function(waitFor) {
if (data.templateId) { if (data.templateId) {
if (data.templateId === -1) { if (data.templateId === -1) {
@ -1654,11 +1655,34 @@ define([
} }
Cryptpad.getPadData(data.templateId, waitFor(function (err, d) { Cryptpad.getPadData(data.templateId, waitFor(function (err, d) {
data.template = d.href; data.template = d.href;
templatePw = d.password;
})); }));
} }
}).nThen(function () { }).nThen(function () {
var cryptputCfg = $.extend(true, {}, rtConfig, {password: password}); var cryptputCfg = $.extend(true, {}, rtConfig, {password: password});
if (data.template) { if (data.template) {
// Start OO with a template...
// Cryptget and give href, password and content to inner
if (parsed.type === "sheet") {
var then = function () {
startRealtime(rtConfig);
cb();
};
var _parsed = Utils.Hash.parsePadUrl(data.template);
Cryptget.get(_parsed.hash, function (err, val) {
if (err || !val) { return void then(); }
try {
var parsed = JSON.parse(val);
sframeChan.event('EV_OO_TEMPLATE', {
href: data.template,
password: templatePw,
content: parsed
});
} catch (e) { console.error(e); }
then();
}, {password: templatePw});
return;
}
// Pass rtConfig to useTemplate because Cryptput will create the file and // Pass rtConfig to useTemplate because Cryptput will create the file and
// we need to have the owners and expiration time in the first line on the // we need to have the owners and expiration time in the first line on the
// server // server

Loading…
Cancel
Save