Add templates for OnlyOffice in the PCS

pull/1/head
yflory 4 years ago committed by ansuz
parent 26ef547e84
commit 935df47018

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

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

@ -1646,6 +1646,7 @@ define([
rtConfig.metadata.validateKey = (secret.keys && secret.keys.validateKey) || undefined;
Utils.rtConfig = rtConfig;
var templatePw;
nThen(function(waitFor) {
if (data.templateId) {
if (data.templateId === -1) {
@ -1654,11 +1655,34 @@ define([
}
Cryptpad.getPadData(data.templateId, waitFor(function (err, d) {
data.template = d.href;
templatePw = d.password;
}));
}
}).nThen(function () {
var cryptputCfg = $.extend(true, {}, rtConfig, {password: password});
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
// we need to have the owners and expiration time in the first line on the
// server

Loading…
Cancel
Save