From 0a543ae6eaf60a5ccb218279955aedb0a5c08fac Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 29 Jan 2020 16:40:46 +0100 Subject: [PATCH] Enable onlyoffice reconnection --- www/common/onlyoffice/app-oo.less | 9 +++++++++ www/common/onlyoffice/inner.js | 33 ++++++++++++++++++++----------- www/common/outer/onlyoffice.js | 23 +++++++++++++-------- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/www/common/onlyoffice/app-oo.less b/www/common/onlyoffice/app-oo.less index aa4bd4f8f..2971165a0 100644 --- a/www/common/onlyoffice/app-oo.less +++ b/www/common/onlyoffice/app-oo.less @@ -62,6 +62,15 @@ body.cp-app-sheet, body.cp-app-oodoc, body.cp-app-ooslide { background-color: lightgrey; display: flex; flex-flow: column; + position: relative; + } + #cp-app-oo-offline { + position: absolute; + top: 0; + bottom: 0; + right: 0; + left: 0; + background-color: rgba(255,255,255,0.5); } #ooframe { flex: 1; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 71f43f3a1..a99b69a76 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -601,12 +601,6 @@ define([ }); }; var handleChanges = function (obj, send) { - // Allow the changes - send({ - type: "unSaveLock", - index: ooChannel.cpIndex, - time: +new Date() - }); // Send the changes rtChannel.sendMsg({ type: "saveChanges", @@ -616,6 +610,15 @@ define([ excelAdditionalInfo: null }, null, function (err, hash) { if (err) { return void console.error(err); } + // Call unSaveLock to tell onlyoffice that the patch was sent. + // It will allow you to make changes to another cell. + // If there is an error and unSaveLock is not called, onlyoffice + // will try to send the patch again + send({ + type: "unSaveLock", + index: ooChannel.cpIndex, + time: +new Date() + }); // Increment index and update latest hash ooChannel.cpIndex++; ooChannel.lastHash = hash; @@ -748,7 +751,9 @@ define([ }, "events": { "onAppReady": function(/*evt*/) { - var $tb = $('iframe[name="frameEditor"]').contents().find('head'); + var $iframe = $('iframe[name="frameEditor"]').contents(); + $iframe.prop('tabindex', '-1'); + var $tb = $iframe.find('head'); var css = // Old OO '#id-toolbar-full .toolbar-group:nth-child(2), #id-toolbar-full .separator:nth-child(3) { display: none; }' + '#fm-btn-save { display: none !important; }' + @@ -1301,10 +1306,13 @@ define([ }; var setEditable = function (state) { + $('#cp-app-oo-editor').find('#cp-app-oo-offline').remove();; + try { + window.frames[0].editor.asc_setViewMode(!state); + //window.frames[0].editor.setViewModeDisconnect(true); + } catch (e) {} if (!state) { - try { - window.frames[0].editor.setViewModeDisconnect(true); - } catch (e) {} + $('#cp-app-oo-editor').append(h('div#cp-app-oo-offline')); } debug(state); }; @@ -1569,10 +1577,11 @@ define([ setEditable(info.state); if (info.state) { UI.findOKButton().click(); - UI.confirm(Messages.oo_reconnect, function (yes) { + offline = false; + /*UI.confirm(Messages.oo_reconnect, function (yes) { if (!yes) { return; } common.gotoURL(); - }); + });*/ } else { offline = true; UI.findOKButton().click(); diff --git a/www/common/outer/onlyoffice.js b/www/common/outer/onlyoffice.js index 9c1863bc6..681faebd3 100644 --- a/www/common/outer/onlyoffice.js +++ b/www/common/outer/onlyoffice.js @@ -53,7 +53,7 @@ define([ // all our client IDs. if (chan.clients) { chan.clients.forEach(function (cl) { - if (ctx.clients[cl] && !ctx.clients[cl].id) { + if (ctx.clients[cl]) { ctx.clients[cl].id = wc.myID + '-' + cl; } }); @@ -189,15 +189,22 @@ define([ if (!c) { return void cb({ error: 'NOT_IN_CHANNEL' }); } var chan = ctx.channels[c.channel]; if (!chan) { return void cb({ error: 'INVALID_CHANNEL' }); } + // Prepare the callback: broadcast the message to the other local tabs + // if the message is sent + var _cb = function (obj) { + if (obj && obj.error) { return void cb(obj); } + ctx.emit('MESSAGE', { + msg: data.msg + }, chan.clients.filter(function (cl) { + return cl !== clientId; + })); + cb(); + }; + // Send the message if (data.isCp) { - return void chan.sendMsg(data.isCp, cb); + return void chan.sendMsg(data.isCp, _cb); } - chan.sendMsg(data.msg, cb); - ctx.emit('MESSAGE', { - msg: data.msg - }, chan.clients.filter(function (cl) { - return cl !== clientId; - })); + chan.sendMsg(data.msg, _cb); }; var reencrypt = function (ctx, data, cId, cb) {