loleaflet/dist/toolbar/toolbar.js | 22 ++++++------ loleaflet/reference.html | 17 ++++++--- loleaflet/src/core/Socket.js | 16 ++------ loleaflet/src/layer/tile/TileLayer.js | 1 loleaflet/src/map/handler/Map.WOPI.js | 61 ++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 28 deletions(-)
New commits: commit 26adebfcb06521bb7023f22ada041298c3c4aa3d Author: Pranav Kant <[email protected]> Date: Tue Nov 15 13:58:25 2016 +0530 tdf#103641: Fix save button visible for presentation Additionally, change the variable name for presentation-toolbar to avoid any future confusion. Also, put the code hiding the save button in onRefresh event so that save button doesn't show up in the UI as soon as we get the wopi properties object from the server. Change-Id: Ib168010c509f55a69aae9752e11321d319f59e99 diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js index 0bb3eee..8ce0d9a 100644 --- a/loleaflet/dist/toolbar/toolbar.js +++ b/loleaflet/dist/toolbar/toolbar.js @@ -732,6 +732,12 @@ function onFormulaBarBlur() { }, 250); } +map.on('wopiprops', function(e) { + if (e.HideSaveOption) { + w2ui['toolbar-up'].hide('save'); + } +}); + map.on('doclayerinit', function () { var toolbar = w2ui['toolbar-up']; var docType = map.getDocType(); @@ -739,12 +745,12 @@ map.on('doclayerinit', function () { if (docType === 'presentation') { toolbar.hide('annotation'); - toolbar = w2ui['presentation-toolbar']; - toolbar.show('presentation'); - toolbar.show('presentationbreak'); - toolbar.show('insertpage'); - toolbar.show('duplicatepage'); - toolbar.show('deletepage'); + var presentationToolbar = w2ui['presentation-toolbar']; + presentationToolbar.show('presentation'); + presentationToolbar.show('presentationbreak'); + presentationToolbar.show('insertpage'); + presentationToolbar.show('duplicatepage'); + presentationToolbar.show('deletepage'); } else if (docType === 'drawing') { toolbar.hide('annotation'); @@ -757,10 +763,6 @@ map.on('doclayerinit', function () { } } - if (map['wopi'].HideSaveOption) { - toolbar.hide('save'); - } - var statusbar = w2ui['toolbar-down']; switch (docType) { case 'spreadsheet': commit d8a202bf1cc2a4cc343833348f08dcfdadbdd409 Author: Pranav Kant <[email protected]> Date: Tue Nov 15 13:48:18 2016 +0530 tdf#103641: Split App_LoadedStatus - Frame_Ready, Document_Loaded Post App_LoadingStatus with 'Status' field as Frame_Ready when we are ready to show the UI. Post Document_Loaded when document is completely loaded after which loleaflet is ready to respond to more document specific queries through post message API. Change-Id: I60a4e9b75e115c748fcee8d449bc8c2d4ffa34a9 diff --git a/loleaflet/reference.html b/loleaflet/reference.html index 529728a..e8bb801 100644 --- a/loleaflet/reference.html +++ b/loleaflet/reference.html @@ -2769,12 +2769,17 @@ Editor to WOPI host <tr> <td><code><b>App_LoadingStatus</b></code></td> <td><code> - <nobr>DocumentLoadedTime: <Number></nobr> - </code></td> - <td>When loleaflet frame is completely ready. Host can start - sending other messages using post message API. - DocumentLoadedTime is timestamp when frame is - ready/loaded.</td> + <nobr>Status: <String></nobr> + <nobr>DocumentLoadedTime: <Timestamp></nobr> + </code></td> + <td>If Status is Frame_Ready, loleaflet frame is loaded and UI + can be shown. <br/> + When Status is Document_Loaded, document has been completely + loaded and host can also start sending document-specific query + messages using post message API such as Get_Views, + Get_Export_Formats etc. DocumentLoadedTime is specified + only in this case. + </td> </tr> </table> WOPI host to editor diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index d504ba6..e8b342b 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -180,18 +180,7 @@ L.Socket = L.Class.extend({ else if (textMsg.startsWith('wopi: ')) { // Handle WOPI related messages var wopiInfo = JSON.parse(textMsg.substring(textMsg.indexOf('{'))); - // Store postmessageorigin property in our WOPI handler, if it exists - if (this._map['wopi'] && !!wopiInfo['PostMessageOrigin']) { - this._map['wopi'].PostMessageOrigin = wopiInfo['PostMessageOrigin']; - this._map['wopi'].DocumentLoadedTime = Date.now(); - // Tell the host that we are ready now - this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {'DocumentLoadedTime': this._map['wopi'].DocumentLoadedTime}}); - } - - this._map['wopi'].HidePrintOption = !!wopiInfo['HidePrintOption']; - this._map['wopi'].HideSaveOption = !!wopiInfo['HideSaveOption']; - this._map['wopi'].HideExportOption = !!wopiInfo['HideExportOption']; - + this._map.fire('wopiprops', wopiInfo); return; } else if (textMsg.startsWith('close: ')) { @@ -412,6 +401,9 @@ L.Socket = L.Class.extend({ } this._map.fire('error', {msg: _('Well, this is embarrassing, we cannot connect to your document. Please try again.'), cmd: 'socket', kind: 'closed', id: 4}); + + // Reset wopi's app loaded so that reconnecting again informs outerframe about initialization again + this._map['wopi'].resetAppLoaded(); }, parseServerCmd: function (msg) { diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 40ad0a3..5e2c3a0 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -820,6 +820,7 @@ L.TileLayer = L.GridLayer.extend({ _onViewInfoMsg: function(textMsg) { textMsg = textMsg.substring('viewinfo: '.length); var viewInfo = JSON.parse(textMsg); + this._map.fire('viewinfo', viewInfo); // A new view var viewIds = []; diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js index 766db04..a47fc09 100644 --- a/loleaflet/src/map/handler/Map.WOPI.js +++ b/loleaflet/src/map/handler/Map.WOPI.js @@ -11,20 +11,81 @@ L.Map.WOPI = L.Handler.extend({ HideSaveOption: false, HideExportOption: false, + _appLoadedConditions: { + doclayerinit: false, + updatepermission: false, + viewinfo: false /* Whether view information has already arrived */ + }, + + _appLoaded: false, + initialize: function(map) { this._map = map; }, addHooks: function() { this._map.on('postMessage', this._postMessage, this); + + // init messages + this._map.on('doclayerinit', this._postLoaded, this); + this._map.on('updatepermission', this._postLoaded, this); + // This indicates that 'viewinfo' message has already arrived + this._map.on('viewinfo', this._postLoaded, this); + + this._map.on('wopiprops', this._setWopiProps, this); L.DomEvent.on(window, 'message', this._postMessageListener, this); }, removeHooks: function() { this._map.off('postMessage', this._postMessage, this); + + // init messages + this._map.off('doclayerinit', this._postLoaded, this); + this._map.off('updatepermission', this._postLoaded, this); + this._map.off('viewinfo', this._postLoaded, this); + + this._map.off('wopiprops', this._setWopiProps, this); L.DomEvent.off(window, 'message', this._postMessageListener, this); }, + _setWopiProps: function(wopiInfo) { + // Store postmessageorigin property, if it exists + if (!!wopiInfo['PostMessageOrigin']) { + this.PostMessageOrigin = wopiInfo['PostMessageOrigin']; + } + + this.HidePrintOption = !!wopiInfo['HidePrintOption']; + this.HideSaveOption = !!wopiInfo['HideSaveOption']; + this.HideExportOption = !!wopiInfo['HideExportOption']; + + this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {Status: 'Frame_Ready'}}); + }, + + resetAppLoaded: function() { + this._appLoaded = false; + for (var key in this._appLoadedConditions) { + this._appLoadedConditions[key] = false; + } + }, + + _postLoaded: function(e) { + if (this._appLoaded) { + return; + } + + if (e.type === 'doclayerinit') { + this.DocumentLoadedTime = Date.now(); + } + this._appLoadedConditions[e.type] = true; + for (var key in this._appLoadedConditions) { + if (!this._appLoadedConditions[key]) + return; + } + + this._appLoaded = true; + this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {Status: 'Document_Loaded', DocumentLoadedTime: this.DocumentLoadedTime}}); + }, + _postMessageListener: function(e) { if (!window.WOPIPostmessageReady) { return; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
