From f34273ed897376805e5937be592d3600baa2aeb5 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 9 Dec 2022 14:22:18 +0300 Subject: [PATCH] Refresh file on reconnect --- apps/api/documents/api.js | 10 +++++++- apps/common/Gateway.js | 8 ++++++ .../main/app/controller/Main.js | 25 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index a91876013..cc9975b14 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -752,6 +752,13 @@ }); }; + var _refreshFile = function(data) { + _sendCommand({ + command: 'refreshFile', + data: data + }); + }; + var _serviceCommand = function(command, data) { _sendCommand({ command: 'internalCommand', @@ -787,7 +794,8 @@ requestClose : _requestClose, grabFocus : _grabFocus, blurFocus : _blurFocus, - setReferenceData : _setReferenceData + setReferenceData : _setReferenceData, + refreshFile : _refreshFile } }; diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index 438ccce82..2ed9e87ca 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -142,6 +142,10 @@ if (window.Common === undefined) { 'setReferenceData': function(data) { $me.trigger('setreferencedata', data); + }, + + 'refreshFile': function(data) { + $me.trigger('refreshfile', data); } }; @@ -359,6 +363,10 @@ if (window.Common === undefined) { _postMessage({ event: 'onPluginsReady' }); }, + requestRefreshFile: function() { + _postMessage({ event: 'onRequestRefreshFile' }); + }, + 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 15f9631a9..fcf31e7d9 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -226,6 +226,9 @@ define([ Common.NotificationCenter.on('showerror', _.bind(this.onError, this)); Common.NotificationCenter.on('editing:disable', _.bind(this.onEditingDisable, this)); + Common.Gateway.on('refreshfile', _.bind(this.onRefreshFile, this)); + this.api.asc_registerCallback('asc_onRequestRefreshFile', _.bind(this.onRequestRefreshFile, this)); + this.isShowOpenDialog = false; // Initialize api gateway @@ -2995,6 +2998,28 @@ define([ } }, + onRequestRefreshFile: function() { + Common.Gateway.requestRefreshFile(); + }, + + onRefreshFile: function(data) { + if (data) { + var docInfo = new Asc.asc_CDocInfo(); + if (data.document) { + docInfo.put_Id(data.document.key); + docInfo.put_Url(data.document.url); + docInfo.put_Title(data.document.title); + data.document.title && Common.Gateway.metaChange({title: data.document.title}); + } + if (data.editorConfig) { + docInfo.put_CallbackUrl(data.editorConfig.callbackUrl); + } + if (data.token) + docInfo.put_Token(data.token); + this.api.asc_setDocInfo(docInfo); + } + }, + 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',