diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 4764619edc..a49fff5d95 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; @@ -564,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) { @@ -587,6 +589,13 @@ }); }; + var _openDocumentFromBinary = function(doc) { + doc && _sendCommand({ + command: 'openDocumentFromBinary', + data: doc.buffer + }, doc.buffer); + }; + var _showMessage = function(title, msg) { msg = msg || title; _sendCommand({ @@ -846,7 +855,8 @@ setReferenceData : _setReferenceData, setRequestedDocument: _setRequestedDocument, setRequestedSpreadsheet: _setRequestedSpreadsheet, - setReferenceSource: _setReferenceSource + setReferenceSource: _setReferenceSource, + openDocument: _openDocumentFromBinary } }; @@ -897,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); @@ -1107,12 +1123,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 e2efd153d8..fa6733af22 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); }, @@ -156,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), "*"); } }; @@ -169,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; } @@ -386,6 +398,13 @@ if (window.Common === undefined) { _postMessage({ event: 'onPluginsReady' }); }, + saveDocument: function(data) { + data && _postMessage({ + event: 'onSaveDocument', + data: data.buffer + }, data.buffer); + }, + 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 9ce0b1493f..62023a56ee 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(); @@ -463,6 +464,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)); this.appOptions.canRequestClose = this.editorConfig.canRequestClose; @@ -541,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); @@ -1025,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); @@ -1904,6 +1907,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']})) { @@ -2321,7 +2325,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); } @@ -2338,7 +2342,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); } @@ -3158,6 +3162,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/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index f1cd1c5142..0031673547 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -1078,13 +1078,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 4166e14e30..618f3485f1 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; } } diff --git a/apps/pdfeditor/main/app/controller/Main.js b/apps/pdfeditor/main/app/controller/Main.js index 60fb87d7c7..5efa1a0dc8 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(); @@ -400,6 +401,7 @@ define([ this.appOptions.compatibleFeatures = true; 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; @@ -467,6 +469,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); @@ -758,7 +761,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); @@ -1506,6 +1509,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']})) { @@ -1937,7 +1941,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); } @@ -1954,7 +1958,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); } @@ -2448,6 +2452,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 78eeec0122..9248e62e59 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 b0d586e26b..f006de7ada 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 cd2a836501..cc0a20cc64 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,6 +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; @@ -494,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 @@ -662,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); @@ -1486,6 +1489,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']})) { @@ -1855,7 +1859,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); } @@ -1864,7 +1868,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); } @@ -2850,6 +2854,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 b6de3a4dca..526e2061be 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 2c4c245934..27622a0c50 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 86fde891de..041cbdd066 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,6 +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)); @@ -577,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 @@ -1635,6 +1638,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)); @@ -2287,7 +2291,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); @@ -2297,7 +2301,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); } @@ -3490,6 +3494,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 3dc882aae2..aaac71e6eb 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 1bc3cceaad..2fcf3e8160 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; }