From ecf7e28b9a0d2f27e2c7d7207e262765a888d04a Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 17 Feb 2021 16:38:02 +0100 Subject: [PATCH] Enable strict collaborative mode in OnlyOffice with support for Undo/Redo #195 --- www/common/onlyoffice/inner.js | 84 ++++++++++++++----- .../apps/spreadsheeteditor/main/app.js | 18 ++-- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 577c1d286..5f19879b3 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -73,6 +73,11 @@ define([ return JSONSortify(obj); }; + var supportsXLSX = function () { + return !(typeof(Atomics) === "undefined" || typeof (SharedArrayBuffer) === "undefined"); + }; + + var toolbar; @@ -1107,7 +1112,8 @@ define([ Channel.create(msgEv, postMsg, function (chan) { APP.chan = chan; - var send = ooChannel.send = function (obj) { + var send = ooChannel.send = function (obj, force) { + if (APP.onStrictSaveChanges && !force) { return; } // can't push to OO before reloading cp debug(obj, 'toOO'); chan.event('CMD', obj); }; @@ -1124,7 +1130,7 @@ define([ send({ type: "saveLock", saveLock: false - }); + }, true); } break; case "getLock": @@ -1135,6 +1141,18 @@ define([ send({ type: "message" }); break; case "saveChanges": + // If we have unsaved data before reloading for a checkpoint... + if (APP.onStrictSaveChanges) { + APP.unsavedChanges = { + type: "saveChanges", + changes: parseChanges(obj.changes), + changesIndex: ooChannel.cpIndex || 0, + locks: getUserLock(getId()), + excelAdditionalInfo: null + }; + APP.onStrictSaveChanges(); + return; + } // We're sending our changes to netflux handleChanges(obj, send); // If we're alone, clean up the medias @@ -1223,27 +1241,29 @@ define([ $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; }' + + //'#id-toolbar-full .toolbar-group:nth-child(2), #id-toolbar-full .separator:nth-child(3) { display: none; }' + + //'#fm-btn-save { display: none !important; }' + '#panel-settings-general tr.autosave { display: none !important; }' + '#panel-settings-general tr.coauth { display: none !important; }' + - '#header { display: none !important; }' + + //'#header { display: none !important; }' + '#title-doc-name { display: none !important; }' + + '#title-user-name { display: none !important; }' + + (supportsXLSX() ? '' : '#slot-btn-dt-print { display: none !important; }') + // New OO: '#asc-gen566 { display: none !important; }' + // Insert image from url 'section[data-tab="ins"] .separator:nth-last-child(2) { display: none !important; }' + // separator '#slot-btn-insequation { display: none !important; }' + // Insert equation - '.toolbar .tabs .ribtab:not(.canedit) { display: none !important; }' + // Switch collaborative mode - '#app-title { display: none !important; }' + // OnlyOffice logo + doc title + //'.toolbar .tabs .ribtab:not(.canedit) { display: none !important; }' + // Switch collaborative mode '#fm-btn-info { display: none !important; }' + // Author name, doc title, etc. in "File" (menu entry) '#panel-info { display: none !important; }' + // Same but content '#image-button-from-url { display: none !important; }' + // Inline image settings: replace with url '#file-menu-panel .devider { display: none !important; }' + // separator in the "File" menu - '#file-menu-panel { top: 28px !important; }' + // Position of the "File" menu '#left-btn-spellcheck, #left-btn-about { display: none !important; }'+ 'div.btn-users.dropdown-toggle { display: none; !important }'; if (readOnly) { css += '#toolbar { display: none !important; }'; + //css += '#app-title { display: none !important; }'; // OnlyOffice logo + doc title + //css += '#file-menu-panel { top: 28px !important; }'; // Position of the "File" menu } $('