From 3ad881da79bde5402bf376b11a8cc538392a1dd9 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 1 Mar 2024 22:47:17 +0300 Subject: [PATCH 1/4] [DE] open/save binary file --- apps/api/documents/api.js | 16 ++++++++++++++-- apps/common/Gateway.js | 13 +++++++++++++ apps/documenteditor/main/app/controller/Main.js | 12 ++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index e689381f5c..70d4167d34 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -286,7 +286,8 @@ 'onRequestOpen': , 'onRequestSelectDocument': , // used for compare and combine documents. must call setRequestedDocument method. use instead of onRequestCompareFile/setRevisedFile 'onRequestSelectSpreadsheet': , // used for mailmerge id de. must call setRequestedSpreadsheet method. use instead of onRequestMailMergeRecipients/setMailMergeRecipients - 'onRequestReferenceSource': , // used for external links in sse. must call setReferenceSource method + 'onRequestReferenceSource': , // used for external links in sse. must call setReferenceSource method, + 'onSaveDocument': 'save document from binary' } } @@ -355,6 +356,7 @@ _config.editorConfig.canRequestSelectDocument = _config.events && !!_config.events.onRequestSelectDocument; _config.editorConfig.canRequestSelectSpreadsheet = _config.events && !!_config.events.onRequestSelectSpreadsheet; _config.editorConfig.canRequestReferenceSource = _config.events && !!_config.events.onRequestReferenceSource; + _config.editorConfig.canSaveDocumentToBinary = _config.events && !!_config.events.onSaveDocument; _config.frameEditorId = placeholderId; _config.parentOrigin = window.location.origin; @@ -587,6 +589,15 @@ }); }; + var _openDocumentFromBinary = function(doc) { + _sendCommand({ + command: 'openDocumentFromBinary', + data: { + doc: doc + } + }); + }; + var _showMessage = function(title, msg) { msg = msg || title; _sendCommand({ @@ -846,7 +857,8 @@ setReferenceData : _setReferenceData, setRequestedDocument: _setRequestedDocument, setRequestedSpreadsheet: _setRequestedSpreadsheet, - setReferenceSource: _setReferenceSource + setReferenceSource: _setReferenceSource, + openDocument: _openDocumentFromBinary } }; diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index e2efd153d8..db5c0c1657 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -47,6 +47,10 @@ if (window.Common === undefined) { $me.trigger('opendocument', data); }, + 'openDocumentFromBinary': function(data) { + $me.trigger('opendocumentfrombinary', data); + }, + 'showMessage': function(data) { $me.trigger('showmessage', data); }, @@ -386,6 +390,15 @@ if (window.Common === undefined) { _postMessage({ event: 'onPluginsReady' }); }, + saveDocument: function(data) { + _postMessage({ + event: 'onSaveDocument', + data: { + data: data + } + }); + }, + on: function(event, handler){ var localHandler = function(event, data){ handler.call(me, data) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index fbb551e92d..c7e04428af 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -252,6 +252,7 @@ define([ Common.Gateway.on('init', _.bind(this.loadConfig, this)); Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this)); Common.Gateway.on('opendocument', _.bind(this.loadDocument, this)); + Common.Gateway.on('opendocumentfrombinary', _.bind(this.loadBinary, this)); Common.Gateway.on('grabfocus', _.bind(this.onGrabFocus, this)); Common.Gateway.appReady(); @@ -462,6 +463,7 @@ define([ this.appOptions.uiRtl = !(Common.Controllers.Desktop.isActive() && Common.Controllers.Desktop.uiRtlSupported()) && !Common.Utils.isIE; this.appOptions.disableNetworkFunctionality = !!(window["AscDesktopEditor"] && window["AscDesktopEditor"]["isSupportNetworkFunctionality"] && false === window["AscDesktopEditor"]["isSupportNetworkFunctionality"]()); this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false)); + this.appOptions.canSaveDocumentToBinary = this.editorConfig.canSaveDocumentToBinary; this.appOptions.user.guest && this.appOptions.canRenameAnonymous && Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this)); @@ -1900,6 +1902,7 @@ define([ me.api.asc_registerCallback('asc_onCollaborativeChanges', _.bind(me.onCollaborativeChanges, me)); me.api.asc_registerCallback('asc_OnTryUndoInFastCollaborative',_.bind(me.onTryUndoInFastCollaborative, me)); me.api.asc_registerCallback('asc_onConvertEquationToMath',_.bind(me.onConvertEquationToMath, me)); + me.appOptions.canSaveDocumentToBinary && me.api.asc_registerCallback('asc_onSaveDocument',_.bind(me.onSaveDocumentBinary, me)); /** coauthoring end **/ if (me.stackLongActions.exist({id: ApplyEditRights, type: Asc.c_oAscAsyncActionType['BlockInteraction']})) { @@ -3154,6 +3157,15 @@ define([ } }, + onSaveDocumentBinary: function(data) { + Common.Gateway.saveDocument(data); + }, + + loadBinary: function(data) { + console.log('loadBinary'); + data && data.doc && this.api.asc_openDocumentFromBytes(data.doc); + }, + leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', criticalErrorTitle: 'Error', notcriticalErrorTitle: 'Warning', From f9c24e534cd24546b069660d1e05f44796743105 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 15 Mar 2024 14:12:23 +0300 Subject: [PATCH 2/4] [DE] Hande save binary --- apps/documenteditor/main/app/controller/Main.js | 7 ++++--- apps/documenteditor/main/app/controller/Toolbar.js | 4 ++-- apps/documenteditor/main/app/view/Toolbar.js | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index c7e04428af..a89d22fc47 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -543,6 +543,7 @@ define([ docInfo.put_EncryptedInfo(this.editorConfig.encryptionKeys); docInfo.put_Lang(this.editorConfig.lang); docInfo.put_Mode(this.editorConfig.mode); + docInfo.put_SupportsOnSaveDocument(this.editorConfig.canSaveDocumentToBinary); var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); docInfo.asc_putIsEnabledMacroses(!!enable); @@ -1027,7 +1028,7 @@ define([ if (this.api && this.appOptions.isEdit && !toolbarView._state.previewmode) { var cansave = this.api.asc_isDocumentCanSave(), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isSyncButton = (toolbarView.btnCollabChanges.rendered) ? toolbarView.btnCollabChanges.cmpEl.hasClass('notify') : false, isDisabled = !cansave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; toolbarView.btnSave.setDisabled(isDisabled); @@ -2320,7 +2321,7 @@ define([ var toolbarView = this.getApplication().getController('Toolbar').getView(); if (toolbarView && toolbarView.btnCollabChanges && !toolbarView._state.previewmode) { var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isDisabled = !isModified && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; toolbarView.btnSave.setDisabled(isDisabled); } @@ -2337,7 +2338,7 @@ define([ if (toolbarView && this.api && !toolbarView._state.previewmode) { var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isDisabled = !isCanSave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; toolbarView.btnSave.setDisabled(isDisabled); } diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 0c931ad6d2..3daa205bbf 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -1074,13 +1074,13 @@ define([ if (this.api) { var isModified = this.api.asc_isDocumentCanSave(); var isSyncButton = toolbar.btnCollabChanges && toolbar.btnCollabChanges.cmpEl.hasClass('notify'); - if (!isModified && !isSyncButton && !toolbar.mode.forcesave) + if (!isModified && !isSyncButton && !toolbar.mode.forcesave && !toolbar.mode.canSaveDocumentToBinary) return; this.api.asc_Save(); } - toolbar.btnSave.setDisabled(!toolbar.mode.forcesave); + toolbar.btnSave.setDisabled(!toolbar.mode.forcesave && !toolbar.mode.canSaveDocumentToBinary); Common.NotificationCenter.trigger('edit:complete', toolbar); diff --git a/apps/documenteditor/main/app/view/Toolbar.js b/apps/documenteditor/main/app/view/Toolbar.js index f441542b7b..613792d89a 100644 --- a/apps/documenteditor/main/app/view/Toolbar.js +++ b/apps/documenteditor/main/app/view/Toolbar.js @@ -2949,7 +2949,7 @@ define([ this.synchTooltip.hide(); this.btnCollabChanges.updateHint(this.btnSaveTip); - this.btnSave.setDisabled(!me.mode.forcesave); + this.btnSave.setDisabled(!me.mode.forcesave && !me.mode.canSaveDocumentToBinary); this._state.hasCollaborativeChanges = false; } } From 770b49d646df5a81d16a35012efdb064323a19a5 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 15 Mar 2024 18:16:47 +0300 Subject: [PATCH 3/4] Fix open/save binary file --- apps/api/documents/api.js | 17 +++++++--------- apps/common/Gateway.js | 20 ++++++++++++------- .../main/app/controller/Main.js | 3 +-- apps/pdfeditor/main/app/controller/Main.js | 19 ++++++++++++++---- apps/pdfeditor/main/app/controller/Toolbar.js | 4 ++-- apps/pdfeditor/main/app/view/Toolbar.js | 2 +- .../main/app/controller/Main.js | 19 ++++++++++++++---- .../main/app/controller/Toolbar.js | 4 ++-- .../main/app/view/Toolbar.js | 2 +- .../main/app/controller/Main.js | 17 +++++++++++++--- .../main/app/controller/Toolbar.js | 2 +- .../main/app/view/Toolbar.js | 2 +- 12 files changed, 73 insertions(+), 38 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 70d4167d34..ef13a3b825 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -566,9 +566,9 @@ } }; - var _sendCommand = function(cmd) { + var _sendCommand = function(cmd, buffer) { if (iframe && iframe.contentWindow) - postMessage(iframe.contentWindow, cmd); + postMessage(iframe.contentWindow, cmd, buffer); }; var _init = function(editorConfig) { @@ -590,12 +590,10 @@ }; var _openDocumentFromBinary = function(doc) { - _sendCommand({ + doc && _sendCommand({ command: 'openDocumentFromBinary', - data: { - doc: doc - } - }); + data: doc.buffer + }, doc.buffer); }; var _showMessage = function(title, msg) { @@ -1103,12 +1101,11 @@ return iframe; } - function postMessage(wnd, msg) { + function postMessage(wnd, msg, buffer) { if (wnd && wnd.postMessage && window.JSON) { // TODO: specify explicit origin - wnd.postMessage(window.JSON.stringify(msg), "*"); + buffer ? wnd.postMessage(msg, "*", [buffer]) : wnd.postMessage(window.JSON.stringify(msg), "*"); } - } function extend(dest, src) { diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index db5c0c1657..fa6733af22 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -160,11 +160,11 @@ if (window.Common === undefined) { } }; - var _postMessage = function(msg) { + var _postMessage = function(msg, buffer) { // TODO: specify explicit origin if (window.parent && window.JSON) { msg.frameEditorId = window.frameEditorId; - window.parent.postMessage(window.JSON.stringify(msg), "*"); + buffer ? window.parent.postMessage(msg, "*", [buffer]) : window.parent.postMessage(window.JSON.stringify(msg), "*"); } }; @@ -173,6 +173,14 @@ if (window.Common === undefined) { if (msg.origin !== window.parentOrigin && msg.origin !== window.location.origin && !(msg.origin==="null" && (window.parentOrigin==="file://" || window.location.origin==="file://"))) return; var data = msg.data; + if (data && data.command === 'openDocumentFromBinary') { + handler = commandMap[data.command]; + if (handler) { + handler.call(this, data.data); + } + return; + } + if (Object.prototype.toString.apply(data) !== '[object String]' || !window.JSON) { return; } @@ -391,12 +399,10 @@ if (window.Common === undefined) { }, saveDocument: function(data) { - _postMessage({ + data && _postMessage({ event: 'onSaveDocument', - data: { - data: data - } - }); + data: data.buffer + }, data.buffer); }, on: function(event, handler){ diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index a89d22fc47..0f91d89b21 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -3163,8 +3163,7 @@ define([ }, loadBinary: function(data) { - console.log('loadBinary'); - data && data.doc && this.api.asc_openDocumentFromBytes(data.doc); + data && this.api.asc_openDocumentFromBytes(new Uint8Array(data)); }, leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', diff --git a/apps/pdfeditor/main/app/controller/Main.js b/apps/pdfeditor/main/app/controller/Main.js index bb042fe9d8..9368396029 100644 --- a/apps/pdfeditor/main/app/controller/Main.js +++ b/apps/pdfeditor/main/app/controller/Main.js @@ -202,6 +202,7 @@ define([ Common.Gateway.on('init', _.bind(this.loadConfig, this)); Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this)); Common.Gateway.on('opendocument', _.bind(this.loadDocument, this)); + Common.Gateway.on('opendocumentfrombinary', _.bind(this.loadBinary, this)); Common.Gateway.on('grabfocus', _.bind(this.onGrabFocus, this)); Common.Gateway.appReady(); @@ -401,7 +402,7 @@ define([ this.appOptions.uiRtl = !(Common.Controllers.Desktop.isActive() && Common.Controllers.Desktop.uiRtlSupported()) && !Common.Utils.isIE; this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false)); - + this.appOptions.canSaveDocumentToBinary = this.editorConfig.canSaveDocumentToBinary; this.appOptions.user.guest && this.appOptions.canRenameAnonymous && Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this)); this.appOptions.canRequestClose = this.editorConfig.canRequestClose; @@ -469,6 +470,7 @@ define([ docInfo.put_EncryptedInfo(this.editorConfig.encryptionKeys); docInfo.put_Lang(this.editorConfig.lang); docInfo.put_Mode(this.editorConfig.mode); + docInfo.put_SupportsOnSaveDocument(this.editorConfig.canSaveDocumentToBinary); var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); docInfo.asc_putIsEnabledMacroses(!!enable); @@ -760,7 +762,7 @@ define([ if (this.api && this.appOptions.isEdit && !toolbarView._state.previewmode) { var cansave = this.api.asc_isDocumentCanSave(), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isSyncButton = (toolbarView.btnCollabChanges.rendered) ? toolbarView.btnCollabChanges.cmpEl.hasClass('notify') : false, isDisabled = !cansave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave || !this.appOptions.isPDFEdit && !this.appOptions.isPDFAnnotate; toolbarView.btnSave.setDisabled(isDisabled && !this.appOptions.saveAlwaysEnabled); @@ -1505,6 +1507,7 @@ define([ /** coauthoring begin **/ me.api.asc_registerCallback('asc_onCollaborativeChanges', _.bind(me.onCollaborativeChanges, me)); me.api.asc_registerCallback('asc_OnTryUndoInFastCollaborative',_.bind(me.onTryUndoInFastCollaborative, me)); + me.appOptions.canSaveDocumentToBinary && me.api.asc_registerCallback('asc_onSaveDocument',_.bind(me.onSaveDocumentBinary, me)); /** coauthoring end **/ if (me.stackLongActions.exist({id: ApplyEditRights, type: Asc.c_oAscAsyncActionType['BlockInteraction']})) { @@ -1936,7 +1939,7 @@ define([ var toolbarView = this.getApplication().getController('Toolbar').getView(); if (toolbarView && toolbarView.btnCollabChanges && !toolbarView._state.previewmode) { var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isDisabled = !isModified && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave || !this.appOptions.isPDFEdit && !this.appOptions.isPDFAnnotate; toolbarView.btnSave.setDisabled(isDisabled && !this.appOptions.saveAlwaysEnabled); } @@ -1953,7 +1956,7 @@ define([ if (toolbarView && this.api && !toolbarView._state.previewmode) { var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isDisabled = !isCanSave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave || !this.appOptions.isPDFEdit && !this.appOptions.isPDFAnnotate; toolbarView.btnSave.setDisabled(isDisabled && !this.appOptions.saveAlwaysEnabled); } @@ -2447,6 +2450,14 @@ define([ } }, + onSaveDocumentBinary: function(data) { + Common.Gateway.saveDocument(data); + }, + + loadBinary: function(data) { + data && this.api.asc_openDocumentFromBytes(new Uint8Array(data)); + }, + leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', criticalErrorTitle: 'Error', notcriticalErrorTitle: 'Warning', diff --git a/apps/pdfeditor/main/app/controller/Toolbar.js b/apps/pdfeditor/main/app/controller/Toolbar.js index 66ae82eec1..33f85315ad 100644 --- a/apps/pdfeditor/main/app/controller/Toolbar.js +++ b/apps/pdfeditor/main/app/controller/Toolbar.js @@ -435,11 +435,11 @@ define([ } else if (this.api) { // var isModified = this.api.asc_isDocumentCanSave(); // var isSyncButton = toolbar.btnCollabChanges && toolbar.btnCollabChanges.cmpEl.hasClass('notify'); - // if (!isModified && !isSyncButton && !toolbar.mode.forcesave) + // if (!isModified && !isSyncButton && !toolbar.mode.forcesave && !toolbar.mode.canSaveDocumentToBinary) // return; this.api.asc_Save(); - toolbar.btnSave && toolbar.btnSave.setDisabled(!toolbar.mode.forcesave && !toolbar.mode.saveAlwaysEnabled); + toolbar.btnSave && toolbar.btnSave.setDisabled(!toolbar.mode.forcesave && !toolbar.mode.saveAlwaysEnabled && !toolbar.mode.canSaveDocumentToBinary); Common.component.Analytics.trackEvent('Save'); Common.component.Analytics.trackEvent('ToolBar', 'Save'); } diff --git a/apps/pdfeditor/main/app/view/Toolbar.js b/apps/pdfeditor/main/app/view/Toolbar.js index ce659ef46e..9a6a7d652c 100644 --- a/apps/pdfeditor/main/app/view/Toolbar.js +++ b/apps/pdfeditor/main/app/view/Toolbar.js @@ -815,7 +815,7 @@ define([ this.synchTooltip.hide(); this.btnCollabChanges.updateHint(this.btnSaveTip); - this.btnSave.setDisabled(!me.mode.forcesave || !me.mode.isPDFEdit && !me.mode.isPDFAnnotate && !me.mode.saveAlwaysEnabled); + this.btnSave.setDisabled(!me.mode.forcesave && !me.mode.canSaveDocumentToBinary || !me.mode.isPDFEdit && !me.mode.isPDFAnnotate && !me.mode.saveAlwaysEnabled); this._state.hasCollaborativeChanges = false; } } diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 86e6670f67..21bcc244af 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -227,6 +227,7 @@ define([ Common.Gateway.on('init', _.bind(this.loadConfig, this)); Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this)); Common.Gateway.on('opendocument', _.bind(this.loadDocument, this)); + Common.Gateway.on('opendocumentfrombinary', _.bind(this.loadBinary, this)); Common.Gateway.on('grabfocus', _.bind(this.onGrabFocus, this)); Common.Gateway.appReady(); @@ -411,7 +412,7 @@ define([ this.appOptions.canRequestSharingSettings = this.editorConfig.canRequestSharingSettings; this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false)); this.appOptions.uiRtl = !(Common.Controllers.Desktop.isActive() && Common.Controllers.Desktop.uiRtlSupported()) && !Common.Utils.isIE; - + this.appOptions.canSaveDocumentToBinary = this.editorConfig.canSaveDocumentToBinary; this.appOptions.user.guest && this.appOptions.canRenameAnonymous && Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this)); this.appOptions.canRequestClose = this.editorConfig.canRequestClose; @@ -495,6 +496,7 @@ define([ docInfo.put_EncryptedInfo(this.editorConfig.encryptionKeys); docInfo.put_Lang(this.editorConfig.lang); docInfo.put_Mode(this.editorConfig.mode); + docInfo.put_SupportsOnSaveDocument(this.editorConfig.canSaveDocumentToBinary); var coEditMode = !(this.editorConfig.coEditing && typeof this.editorConfig.coEditing == 'object') ? 'fast' : // fast by default this.editorConfig.mode === 'view' && this.editorConfig.coEditing.change!==false ? 'fast' : // if can change mode in viewer - set fast for using live viewer @@ -663,7 +665,7 @@ define([ application.getController('DocumentHolder').getView().focus(); if (this.api && this.appOptions.isEdit && this.api.asc_isDocumentCanSave) { var cansave = this.api.asc_isDocumentCanSave(), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isSyncButton = (toolbarView.btnCollabChanges.rendered) ? toolbarView.btnCollabChanges.cmpEl.hasClass('notify') : false, isDisabled = !cansave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; toolbarView.btnSave.setDisabled(isDisabled); @@ -1484,6 +1486,7 @@ define([ me.api.asc_registerCallback('asc_onParticipantsChanged', _.bind(me.onAuthParticipantsChanged, me)); me.api.asc_registerCallback('asc_onConnectionStateChanged', _.bind(me.onUserConnection, me)); me.api.asc_registerCallback('asc_onConvertEquationToMath', _.bind(me.onConvertEquationToMath, me)); + me.appOptions.canSaveDocumentToBinary && me.api.asc_registerCallback('asc_onSaveDocument',_.bind(me.onSaveDocumentBinary, me)); /** coauthoring end **/ if (me.stackLongActions.exist({id: ApplyEditRights, type: Asc.c_oAscAsyncActionType['BlockInteraction']})) { @@ -1853,7 +1856,7 @@ define([ var toolbarView = this.getApplication().getController('Toolbar').getView('Toolbar'); if (toolbarView && toolbarView.btnCollabChanges) { var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isDisabled = !isModified && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; toolbarView.btnSave.setDisabled(isDisabled); } @@ -1862,7 +1865,7 @@ define([ var toolbarView = this.getApplication().getController('Toolbar').getView('Toolbar'); if ( toolbarView ) { var isSyncButton = toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isDisabled = !isCanSave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; toolbarView.btnSave.setDisabled(isDisabled); } @@ -2848,6 +2851,14 @@ define([ this._renameDialog.show(); }, + onSaveDocumentBinary: function(data) { + Common.Gateway.saveDocument(data); + }, + + loadBinary: function(data) { + data && this.api.asc_openDocumentFromBytes(new Uint8Array(data)); + }, + // Translation leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', criticalErrorTitle: 'Error', diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 87ec0cff04..2fca91b0c9 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -1155,13 +1155,13 @@ define([ if (this.api && this.api.asc_isDocumentCanSave) { var isModified = this.api.asc_isDocumentCanSave(); var isSyncButton = toolbar.btnCollabChanges && toolbar.btnCollabChanges.cmpEl.hasClass('notify'); - if (!isModified && !isSyncButton && !this.toolbar.mode.forcesave) + if (!isModified && !isSyncButton && !this.toolbar.mode.forcesave && !toolbar.mode.canSaveDocumentToBinary) return; this.api.asc_Save(); } - toolbar.btnSave.setDisabled(!toolbar.mode.forcesave); + toolbar.btnSave.setDisabled(!toolbar.mode.forcesave && !toolbar.mode.canSaveDocumentToBinary); Common.NotificationCenter.trigger('edit:complete', this.toolbar); Common.component.Analytics.trackEvent('Save'); diff --git a/apps/presentationeditor/main/app/view/Toolbar.js b/apps/presentationeditor/main/app/view/Toolbar.js index 953bc8a332..9eb185de17 100644 --- a/apps/presentationeditor/main/app/view/Toolbar.js +++ b/apps/presentationeditor/main/app/view/Toolbar.js @@ -1974,7 +1974,7 @@ define([ if (this.synchTooltip) this.synchTooltip.hide(); this.btnCollabChanges.updateHint(this.btnSaveTip); - this.btnSave.setDisabled(!me.mode.forcesave); + this.btnSave.setDisabled(!me.mode.forcesave && !me.mode.canSaveDocumentToBinary); this._state.hasCollaborativeChanges = false; } diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 207bf0716d..368521659b 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -264,6 +264,7 @@ define([ Common.Gateway.on('init', _.bind(this.loadConfig, this)); Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this)); Common.Gateway.on('opendocument', _.bind(this.loadDocument, this)); + Common.Gateway.on('opendocumentfrombinary', _.bind(this.loadBinary, this)); Common.Gateway.on('internalcommand', _.bind(this.onInternalCommand, this)); Common.Gateway.on('grabfocus', _.bind(this.onGrabFocus, this)); Common.Gateway.appReady(); @@ -466,7 +467,7 @@ define([ this.appOptions.canRequestReferenceData = this.editorConfig.canRequestReferenceData; this.appOptions.canRequestOpen = this.editorConfig.canRequestOpen; this.appOptions.canRequestReferenceSource = this.editorConfig.canRequestReferenceSource; - + this.appOptions.canSaveDocumentToBinary = this.editorConfig.canSaveDocumentToBinary; if (this.appOptions.user.guest && this.appOptions.canRenameAnonymous && !this.appOptions.isEditDiagram && !this.appOptions.isEditMailMerge && !this.appOptions.isEditOle) Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this)); @@ -578,6 +579,7 @@ define([ docInfo.put_Lang(this.editorConfig.lang); docInfo.put_Mode(this.editorConfig.mode); docInfo.put_ReferenceData(data.doc.referenceData); + docInfo.put_SupportsOnSaveDocument(this.editorConfig.canSaveDocumentToBinary); var coEditMode = !(this.editorConfig.coEditing && typeof this.editorConfig.coEditing == 'object') ? 'fast' : // fast by default this.editorConfig.mode === 'view' && this.editorConfig.coEditing.change!==false ? 'fast' : // if can change mode in viewer - set fast for using live viewer @@ -1633,6 +1635,7 @@ define([ me.api.asc_registerCallback('asc_onParticipantsChanged', _.bind(me.onAuthParticipantsChanged, me)); me.api.asc_registerCallback('asc_onConnectionStateChanged', _.bind(me.onUserConnection, me)); me.api.asc_registerCallback('asc_onConvertEquationToMath', _.bind(me.onConvertEquationToMath, me)); + me.appOptions.canSaveDocumentToBinary && me.api.asc_registerCallback('asc_onSaveDocument',_.bind(me.onSaveDocumentBinary, me)); /** coauthoring end **/ if (me.appOptions.isEditDiagram) me.api.asc_registerCallback('asc_onSelectionChanged', _.bind(me.onSelectionChanged, me)); @@ -2285,7 +2288,7 @@ define([ if (this.toolbarView && this.toolbarView.btnCollabChanges && this.api) { var isSyncButton = this.toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, cansave = this.api.asc_isDocumentCanSave(), isDisabled = !cansave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; this.toolbarView.btnSave.setDisabled(isDisabled); @@ -2295,7 +2298,7 @@ define([ onDocumentCanSaveChanged: function (isCanSave) { if (this.toolbarView && this.toolbarView.btnCollabChanges) { var isSyncButton = this.toolbarView.btnCollabChanges.cmpEl.hasClass('notify'), - forcesave = this.appOptions.forcesave, + forcesave = this.appOptions.forcesave || this.appOptions.canSaveDocumentToBinary, isDisabled = !isCanSave && !isSyncButton && !forcesave || this._state.isDisconnected || this._state.fastCoauth && this._state.usersCount>1 && !forcesave; this.toolbarView.btnSave.setDisabled(isDisabled); } @@ -3488,6 +3491,14 @@ define([ }) }, + onSaveDocumentBinary: function(data) { + Common.Gateway.saveDocument(data); + }, + + loadBinary: function(data) { + data && this.api.asc_openDocumentFromBytes(new Uint8Array(data)); + }, + leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', criticalErrorTitle: 'Error', notcriticalErrorTitle: 'Warning', diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 4a6ff58512..40910f424f 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -585,7 +585,7 @@ define([ if (this.api) { var isModified = this.api.asc_isDocumentCanSave(); var isSyncButton = this.toolbar.btnCollabChanges && this.toolbar.btnCollabChanges.cmpEl.hasClass('notify'); - if (!isModified && !isSyncButton && !this.toolbar.mode.forcesave) + if (!isModified && !isSyncButton && !this.toolbar.mode.forcesave && !this.toolbar.mode.canSaveDocumentToBinary) return; this.api.asc_Save(); diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index 4baed947c5..61efec4514 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -3239,7 +3239,7 @@ define([ if (this.synchTooltip) this.synchTooltip.hide(); this.btnCollabChanges.updateHint(this.btnSaveTip); - this.btnSave.setDisabled(!me.mode.forcesave); + this.btnSave.setDisabled(!me.mode.forcesave && !me.mode.canSaveDocumentToBinary); this._state.hasCollaborativeChanges = false; } From cfbcf19033c9f607b2c04bbdd5ceebbdb3d44330 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 18 Mar 2024 13:16:50 +0300 Subject: [PATCH 4/4] Fix saving binary file --- apps/api/documents/api.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index ef13a3b825..42c941fd82 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -907,6 +907,12 @@ var _onMessage = function(msg) { // TODO: check message origin if (msg && window.JSON && _scope.frameOrigin==msg.origin ) { + if (msg.data && msg.data.event === 'onSaveDocument') { + if (_fn) { + _fn.call(_scope, msg.data); + } + return; + } try { var msg = window.JSON.parse(msg.data);