diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 48db66ac3..01c2de994 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -689,6 +689,22 @@ }); }; + var _grabFocus = function(data) { + setTimeout(function(){ + _sendCommand({ + command: 'grabFocus', + data: data + }); + }, 10); + }; + + var _blurFocus = function(data) { + _sendCommand({ + command: 'blurFocus', + data: data + }); + }; + var _serviceCommand = function(command, data) { _sendCommand({ command: 'internalCommand', @@ -721,7 +737,9 @@ setMailMergeRecipients: _setMailMergeRecipients, setRevisedFile : _setRevisedFile, setFavorite : _setFavorite, - requestClose : _requestClose + requestClose : _requestClose, + grabFocus : _grabFocus, + blurFocus : _blurFocus } }; diff --git a/apps/api/wopi/editor-wopi.ejs b/apps/api/wopi/editor-wopi.ejs index bd3c942e9..93a97f491 100644 --- a/apps/api/wopi/editor-wopi.ejs +++ b/apps/api/wopi/editor-wopi.ejs @@ -65,7 +65,8 @@ div { var postMessageOrigin; var lang = "en-US"; var startTime; - var editNotificationPostMessage; + var documentChanged; + var sendNotificationTimer; var innerAlert = function (message) { if (console && console.log) @@ -75,11 +76,11 @@ div { var commandMap = { 'Blur_Focus': function (data) { innerAlert('Blur_Focus'); -// docEditor.blurFocus(); + docEditor.blurFocus(); }, 'Grab_Focus': function (data) { innerAlert('Grab_Focus'); -// docEditor.grabFocus(); + docEditor.grabFocus(); }, 'Host_PostmessageReady': function (data) { innerAlert('Host_PostmessageReady'); @@ -101,7 +102,6 @@ div { }; var _onMessage = function(msg) { - // TODO: check message origin if (msg.origin !== postMessageOrigin) return; var data = msg.data; @@ -118,9 +118,9 @@ div { } if (cmd) { - handler = commandMap[cmd.command]; + handler = commandMap[cmd.MessageId]; if (handler) { - handler.call(this, cmd.data); + handler.call(this, cmd); } } }; @@ -140,9 +140,18 @@ div { innerAlert("App ready"); }; + var sendEditNotification = function () { + documentChanged && _postMessage('Edit_Notification', {}); + documentChanged = false; + }; + var onDocumentStateChange = function (event) { - if (editNotificationPostMessage && event.data) { - _postMessage('Edit_Notification', {}); + if (event.data) { + documentChanged = true; + if (sendNotificationTimer===undefined) { + sendNotificationTimer = setInterval(sendEditNotification, 30000); + sendEditNotification(); + } } }; @@ -226,7 +235,7 @@ div { }, events: { "onAppReady": onAppReady, - "onDocumentStateChange": onDocumentStateChange, + "onDocumentStateChange": fileInfo.EditNotificationPostMessage ? onDocumentStateChange : undefined, 'onRequestEditRights': fileInfo.EditModePostMessage ? onRequestEditRights : undefined, "onError": onError, "onRequestClose": fileInfo. ClosePostMessage ? onRequestClose : undefined, @@ -236,8 +245,9 @@ div { }; postMessageOrigin = fileInfo.PostMessageOrigin; + if (postMessageOrigin && (typeof postMessageOrigin === 'string') && postMessageOrigin.charAt(postMessageOrigin.length-1)=='/') + postMessageOrigin = postMessageOrigin.substring(0, postMessageOrigin.length - 1); lang = config.editorConfig.lang; - editNotificationPostMessage = fileInfo.EditNotificationPostMessage; startTime = Date.now(); docEditor = new DocsAPI.DocEditor("iframeEditor", config); diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index 14d7de3b8..436f0032b 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -130,6 +130,14 @@ if (window.Common === undefined) { 'requestClose': function(data) { $me.trigger('requestclose', data); + }, + + 'blurFocus': function(data) { + $me.trigger('blurfocus', data); + }, + + 'grabFocus': function(data) { + $me.trigger('grabfocus', data); } }; diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 10bcb88d7..8206d23a1 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -223,6 +223,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('grabfocus', _.bind(this.onGrabFocus, this)); Common.Gateway.appReady(); // $(window.top).resize(_.bind(this.onDocumentResize, this)); @@ -2530,6 +2531,10 @@ define([ this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30); }, + onGrabFocus: function() { + this.getApplication().getController('DocumentHolder').getView().focus(); + }, + 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/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 899b15388..40bee283d 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -199,6 +199,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('grabfocus', _.bind(this.onGrabFocus, this)); Common.Gateway.appReady(); this.getApplication().getController('Viewport').setApi(this.api); @@ -2327,6 +2328,10 @@ define([ return"#"+("000000"+color.toString(16)).substr(-6); }, + onGrabFocus: function() { + this.getApplication().getController('DocumentHolder').getView().focus(); + }, + // 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/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 987d50054..69e1bdbdd 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -226,6 +226,7 @@ define([ Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this)); Common.Gateway.on('opendocument', _.bind(this.loadDocument, this)); Common.Gateway.on('internalcommand', _.bind(this.onInternalCommand, this)); + Common.Gateway.on('grabfocus', _.bind(this.onGrabFocus, this)); Common.Gateway.appReady(); this.getApplication().getController('Viewport').setApi(this.api); @@ -2524,6 +2525,10 @@ define([ this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30); }, + onGrabFocus: function() { + this.getApplication().getController('DocumentHolder').getView().focus(); + }, + 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',