From b6529a7aaa2abe80dfcf9807534b6dc7d9012452 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 2 Jul 2024 23:08:18 +0300 Subject: [PATCH] Refresh file without reload --- .../main/app/controller/Main.js | 6 +- .../main/app/controller/Main.js | 93 +++++++++++++++++-- .../main/app/controller/Statusbar.js | 7 +- .../main/app/controller/Main.js | 93 +++++++++++++++++-- .../main/app/controller/Statusbar.js | 7 +- 5 files changed, 185 insertions(+), 21 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index b929ae0f85..5a8302caf1 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -786,8 +786,7 @@ define([ }, disableEditing: function(disable, type) { - var app = this.getApplication(), - temp = type==='reconnect' || type==='refresh-file'; + var temp = type==='reconnect' || type==='refresh-file'; Common.NotificationCenter.trigger('editing:disable', disable, { viewMode: disable, reviewMode: false, @@ -1126,6 +1125,7 @@ define([ break; case Asc.c_oAscAsyncAction['RefreshFile']: + title = this.textUpdating; text = this.textUpdating; Common.UI.Menu.Manager.hideAll(); this.disableEditing(true, 'refresh-file'); @@ -3465,7 +3465,7 @@ define([ errorCannotPasteImg: 'We can\'t paste this image from the Clipboard, but you can save it to your device and \ninsert it from there, or you can copy the image without text and paste it into the document.', textTryQuickPrint: 'You have selected Quick print: the entire document will be printed on the last selected or default printer.
Do you want to continue?', textUpdating: 'Updating', - textUpdateVersion: 'The file version has been changed. Please wait...', + textUpdateVersion: 'The file version has been changed. Please wait...' } })(), DE.Controllers.Main || {})) }); \ No newline at end of file diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 17508ed60e..ef24961528 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -199,6 +199,8 @@ define([ Common.NotificationCenter.on('showerror', _.bind(this.onError, this)); Common.NotificationCenter.on('markfavorite', _.bind(this.markFavorite, 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; @@ -653,9 +655,13 @@ define([ if ( id == Asc.c_oAscAsyncAction['Disconnect']) { this._state.timerDisconnect && clearTimeout(this._state.timerDisconnect); - this.disableEditing(false, true); + this.disableEditing(false, 'reconnect'); this.getApplication().getController('Statusbar').hideDisconnectTip(); this.getApplication().getController('Statusbar').setStatusCaption(this.textReconnect); + } else if (id === Asc.c_oAscAsyncAction['RefreshFile']) { + this.disableEditing(false, 'refresh-file'); + this.getApplication().getController('Statusbar').hideDisconnectTip(); + this.getApplication().getController('Statusbar').setStatusCaption(''); } if (type == Asc.c_oAscAsyncActionType.BlockInteraction && !((id == Asc.c_oAscAsyncAction['LoadDocumentFonts'] || id == Asc.c_oAscAsyncAction['ApplyChanges']) && (this.dontCloseDummyComment || this.inTextareaControl || Common.Utils.ModalWindow.isVisible() || this.inFormControl))) { @@ -748,7 +754,7 @@ define([ case Asc.c_oAscAsyncAction['Disconnect']: text = this.textDisconnect; Common.UI.Menu.Manager.hideAll(); - this.disableEditing(true, true); + this.disableEditing(true, 'reconnect'); var me = this; statusCallback = function() { me._state.timerDisconnect = setTimeout(function(){ @@ -757,6 +763,14 @@ define([ }; break; + case Asc.c_oAscAsyncAction['RefreshFile']: + title = this.textUpdating; + text = this.textUpdating; + Common.UI.Menu.Manager.hideAll(); + this.disableEditing(true, 'refresh-file'); + this.getApplication().getController('Statusbar').showDisconnectTip(this.textUpdateVersion); + break; + default: if (typeof action.id == 'string'){ title = action.id; @@ -1068,7 +1082,8 @@ define([ } }, - disableEditing: function(disable, temp) { + disableEditing: function(disable, type) { + var temp = type==='reconnect' || type==='refresh-file'; Common.NotificationCenter.trigger('editing:disable', disable, { viewMode: disable, allowSignature: false, @@ -1082,7 +1097,7 @@ define([ viewport: true, documentHolder: true, toolbar: true - }, temp ? 'reconnect' : 'disconnect'); + }, temp ? type : 'disconnect'); }, onEditingDisable: function(disable, options, type) { @@ -1157,12 +1172,16 @@ define([ buttons: [], closable: false }); + if (this._isDocReady) { // receive after refresh file + this.disableEditing(true); + Common.NotificationCenter.trigger('api:disconnect'); + } return; } if (Asc.c_oLicenseResult.ExpiredLimited === licType) this._state.licenseType = licType; - if ( this.onServerVersion(params.asc_getBuildVersion()) || !this.onLanguageLoaded() ) return; + if ( this.onServerVersion(params.asc_getBuildVersion()) || !this.onLanguageLoaded() || this._isDocReady) return; if (params.asc_getRights() !== Asc.c_oRights.Edit) this.permissions.edit = false; @@ -1891,6 +1910,10 @@ define([ }) } }); + if (this._isDocReady) { // receive after refresh file + this.disableEditing(true); + Common.NotificationCenter.trigger('api:disconnect'); + } return true; } return false; @@ -2337,7 +2360,7 @@ define([ var me = this; Common.Utils.warningDocumentIsLocked({ disablefunc: function (disable) { - me.disableEditing(disable, true); + me.disableEditing(disable, 'reconnect'); }}); }, @@ -2731,6 +2754,60 @@ 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); + if (data.document.title) { + //Common.Gateway.metaChange({title: data.document.title}); + appHeader.setDocumentCaption(data.document.title); + this.updateWindowTitle(true); + this.document.title = data.document.title; + } + } + if (data.editorConfig) { + docInfo.put_CallbackUrl(data.editorConfig.callbackUrl); + } + if (data.token) + docInfo.put_Token(data.token); + + var _user = new Asc.asc_CUserInfo(); // change for guest!! + _user.put_Id(this.appOptions.user.id); + _user.put_FullName(this.appOptions.user.fullname); + _user.put_IsAnonymousUser(!!this.appOptions.user.anonymous); + docInfo.put_UserInfo(_user); + + var _options = $.extend({}, this.document.options, this.editorConfig.actionLink || {}); + docInfo.put_Options(_options); + + docInfo.put_Format(this.document.fileType); + docInfo.put_Lang(this.editorConfig.lang); + docInfo.put_Mode(this.editorConfig.mode); + docInfo.put_Permissions(this.permissions); + docInfo.put_DirectUrl(data.document && data.document.directUrl ? data.document.directUrl : this.document.directUrl); + docInfo.put_VKey(data.document && data.document.vkey ? data.document.vkey : this.document.vkey); + docInfo.put_EncryptedInfo(data.editorConfig && data.editorConfig.encryptionKeys ? data.editorConfig.encryptionKeys : this.editorConfig.encryptionKeys); + + var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); + docInfo.asc_putIsEnabledMacroses(!!enable); + enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins!==false); + docInfo.asc_putIsEnabledPlugins(!!enable); + + 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 + this.editorConfig.coEditing.mode || 'fast'; + docInfo.put_CoEditingMode(coEditMode); + this.api.asc_refreshFile(docInfo); + } + }, + // 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', @@ -3114,7 +3191,9 @@ define([ errorInconsistentExtPdf: 'An error has occurred while opening the file.
The file content corresponds to one of the following formats: pdf/djvu/xps/oxps, but the file has the inconsistent extension: %1.', errorInconsistentExt: 'An error has occurred while opening the file.
The file content does not match the file extension.', errorCannotPasteImg: 'We can\'t paste this image from the Clipboard, but you can save it to your device and \ninsert it from there, or you can copy the image without text and paste it into the presentation.', - textTryQuickPrint: 'You have selected Quick print: the entire document will be printed on the last selected or default printer.
Do you want to continue?' + textTryQuickPrint: 'You have selected Quick print: the entire document will be printed on the last selected or default printer.
Do you want to continue?', + textUpdating: 'Updating', + textUpdateVersion: 'The file version has been changed. Please wait...' } })(), PE.Controllers.Main || {})) }); diff --git a/apps/presentationeditor/main/app/controller/Statusbar.js b/apps/presentationeditor/main/app/controller/Statusbar.js index 89ebab6803..7801f2e109 100644 --- a/apps/presentationeditor/main/app/controller/Statusbar.js +++ b/apps/presentationeditor/main/app/controller/Statusbar.js @@ -235,14 +235,15 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.statusbar); }, - showDisconnectTip: function () { + showDisconnectTip: function (text) { var me = this; + text = text || this.textDisconnect; if (!this.disconnectTip) { var target = this.statusbar.getStatusLabel(); target = target.is(':visible') ? target.parent() : this.statusbar.isVisible() ? this.statusbar.$el : $(document.body); this.disconnectTip = new Common.UI.SynchronizeTip({ target : target, - text : this.textDisconnect, + text : text, placement: 'top', position: this.statusbar.isVisible() ? undefined : {bottom: 0}, showLink: false, @@ -254,6 +255,8 @@ define([ me.disconnectTip = null; } }); + } else { + this.disconnectTip.setText(text); } this.disconnectTip.show(); }, diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 0dab37b057..7f3ee4b9ba 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -219,6 +219,8 @@ define([ Common.NotificationCenter.on('protect:check', _.bind(this.checkProtectedRange, this)); Common.NotificationCenter.on('editing:disable', _.bind(this.onEditingDisable, this)); Common.NotificationCenter.on('showerror', _.bind(this.onError, this)); + Common.Gateway.on('refreshfile', _.bind(this.onRefreshFile, this)); + this.api.asc_registerCallback('asc_onRequestRefreshFile', _.bind(this.onRequestRefreshFile, this)); this.stackLongActions = new Common.IrregularStack({ strongCompare : this._compareActionStrong, @@ -742,9 +744,13 @@ define([ } if ( id == Asc.c_oAscAsyncAction['Disconnect']) { this._state.timerDisconnect && clearTimeout(this._state.timerDisconnect); - this.disableEditing(false, true); + this.disableEditing(false, 'reconnect'); this.getApplication().getController('Statusbar').hideDisconnectTip(); this.getApplication().getController('Statusbar').setStatusCaption(this.textReconnect); + } else if (id === Asc.c_oAscAsyncAction['RefreshFile']) { + this.disableEditing(false, 'refresh-file'); + this.getApplication().getController('Statusbar').hideDisconnectTip(); + this.getApplication().getController('Statusbar').setStatusCaption(''); } }, @@ -826,7 +832,7 @@ define([ title = this.textDisconnect; text = this.textDisconnect; Common.UI.Menu.Manager.hideAll(); - this.disableEditing(true, true); + this.disableEditing(true, 'reconnect'); var me = this; statusCallback = function() { me._state.timerDisconnect = setTimeout(function(){ @@ -835,6 +841,14 @@ define([ }; break; + case Asc.c_oAscAsyncAction['RefreshFile']: + title = this.textUpdating; + text = this.textUpdating; + Common.UI.Menu.Manager.hideAll(); + this.disableEditing(true, 'refresh-file'); + this.getApplication().getController('Statusbar').showDisconnectTip(this.textUpdateVersion); + break; + default: if (typeof action.id == 'string'){ title = action.id; @@ -1153,7 +1167,8 @@ define([ } }, - disableEditing: function(disable, temp) { + disableEditing: function(disable, type) { + var temp = type==='reconnect' || type==='refresh-file'; Common.NotificationCenter.trigger('editing:disable', disable, { viewMode: disable, allowSignature: false, @@ -1169,7 +1184,7 @@ define([ documentHolder: true, toolbar: true, celleditor: {previewMode: true} - }, temp ? 'reconnect' : 'disconnect'); + }, temp ? type : 'disconnect'); }, onEditingDisable: function(disable, options, type) { @@ -1248,12 +1263,16 @@ define([ buttons: [], closable: false }); + if (this._isDocReady) { // receive after refresh file + this.disableEditing(true); + Common.NotificationCenter.trigger('api:disconnect'); + } return; } if (Asc.c_oLicenseResult.ExpiredLimited === licType) this._state.licenseType = licType; - if ( this.onServerVersion(params.asc_getBuildVersion()) || !this.onLanguageLoaded() ) return; + if ( this.onServerVersion(params.asc_getBuildVersion()) || !this.onLanguageLoaded() || this._isDocReady) return; if (params.asc_getRights() !== Asc.c_oRights.Edit) this.permissions.edit = false; @@ -2281,6 +2300,10 @@ define([ }) } }); + if (this._isDocReady) { // receive after refresh file + this.disableEditing(true); + Common.NotificationCenter.trigger('api:disconnect'); + } return true; } return false; @@ -2971,7 +2994,7 @@ define([ var me = this; Common.Utils.warningDocumentIsLocked({ disablefunc: function (disable) { - me.disableEditing(disable, true); + me.disableEditing(disable, 'reconnect'); }}); }, @@ -3316,6 +3339,60 @@ 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); + if (data.document.title) { + //Common.Gateway.metaChange({title: data.document.title}); + this.headerView && this.headerView.setDocumentCaption(data.document.title); + this.updateWindowTitle(true); + this.document.title = data.document.title; + } + } + if (data.editorConfig) { + docInfo.put_CallbackUrl(data.editorConfig.callbackUrl); + } + if (data.token) + docInfo.put_Token(data.token); + + var _user = new Asc.asc_CUserInfo(); // change for guest!! + _user.put_Id(this.appOptions.user.id); + _user.put_FullName(this.appOptions.user.fullname); + _user.put_IsAnonymousUser(!!this.appOptions.user.anonymous); + docInfo.put_UserInfo(_user); + + var _options = $.extend({}, this.document.options, this.editorConfig.actionLink || {}); + docInfo.put_Options(_options); + + docInfo.put_Format(this.document.fileType); + docInfo.put_Lang(this.editorConfig.lang); + docInfo.put_Mode(this.editorConfig.mode); + docInfo.put_Permissions(this.permissions); + docInfo.put_DirectUrl(data.document && data.document.directUrl ? data.document.directUrl : this.document.directUrl); + docInfo.put_VKey(data.document && data.document.vkey ? data.document.vkey : this.document.vkey); + docInfo.put_EncryptedInfo(data.editorConfig && data.editorConfig.encryptionKeys ? data.editorConfig.encryptionKeys : this.editorConfig.encryptionKeys); + + var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); + docInfo.asc_putIsEnabledMacroses(!!enable); + enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins!==false); + docInfo.asc_putIsEnabledPlugins(!!enable); + + 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 + this.editorConfig.coEditing.mode || 'fast'; + docInfo.put_CoEditingMode(coEditMode); + this.api.asc_refreshFile(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', @@ -3756,7 +3833,9 @@ define([ errorInconsistentExtPdf: 'An error has occurred while opening the file.
The file content corresponds to one of the following formats: pdf/djvu/xps/oxps, but the file has the inconsistent extension: %1.', errorInconsistentExt: 'An error has occurred while opening the file.
The file content does not match the file extension.', errorCannotPasteImg: 'We can\'t paste this image from the Clipboard, but you can save it to your device and \ninsert it from there, or you can copy the image without text and paste it into the spreadsheet.', - textTryQuickPrint: 'You have selected Quick print: the entire document will be printed on the last selected or default printer.
Do you want to continue?' + textTryQuickPrint: 'You have selected Quick print: the entire document will be printed on the last selected or default printer.
Do you want to continue?', + textUpdating: 'Updating', + textUpdateVersion: 'The file version has been changed. Please wait...' } })(), SSE.Controllers.Main || {})) }); diff --git a/apps/spreadsheeteditor/main/app/controller/Statusbar.js b/apps/spreadsheeteditor/main/app/controller/Statusbar.js index 239e078767..eb7ca2503d 100644 --- a/apps/spreadsheeteditor/main/app/controller/Statusbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Statusbar.js @@ -812,14 +812,15 @@ define([ return isDragDrop; }, - showDisconnectTip: function () { + showDisconnectTip: function (text) { var me = this; + text = text || this.textDisconnect; if (!this.disconnectTip) { var target = this.statusbar.getStatusLabel(); target = target.is(':visible') ? target.parent() : this.statusbar.isVisible() ? this.statusbar.$el : $(document.body); this.disconnectTip = new Common.UI.SynchronizeTip({ target : target, - text : this.textDisconnect, + text : text, placement: 'top', position: this.statusbar.isVisible() ? undefined : {bottom: 0}, showLink: false, @@ -831,6 +832,8 @@ define([ me.disconnectTip = null; } }); + } else { + this.disconnectTip.setText(text); } this.disconnectTip.show(); },