diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index 46ebabea4..66514d7bd 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -85,6 +85,9 @@ L.Map.include({ }, saveAs: function (url, format, options) { + if (url === undefined || url == null) { + return; + } if (format === undefined || format === null) { format = ''; } @@ -94,7 +97,7 @@ L.Map.include({ this.showBusy(_('Saving...'), false); this._socket.sendMessage('saveas ' + - 'url=' + url + ' ' + + 'url=wopi:' + encodeURIComponent(url) + ' ' + 'format=' + format + ' ' + 'options=' + options); }, diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 367e2f183..d363920e4 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -122,6 +122,12 @@ L.Socket = L.Class.extend({ this.socket.send(msg); }, + _getParameterByName: function(url, name) { + name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); + var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'), results = regex.exec(url); + return results === null ? '' : results[1].replace(/\+/g, ' '); + }, + _onSocketOpen: function () { console.debug('_onSocketOpen:'); this._map._serverRecycling = false; @@ -563,8 +569,29 @@ L.Socket = L.Class.extend({ } else if (textMsg.startsWith('saveas:')) { this._map.hideBusy(); - // var url = command.url; // WOPI url - if needed at some stage - // var name = command.name; TODO dialog that the file was saved as "name" + if (command !== undefined && command.url !== undefined && command.url !== '') { + this.close(); + var url = command.url; + var accessToken = this._getParameterByName(url, 'access_token'); + var accessTokenTtl = this._getParameterByName(url, 'access_token_ttl'); + + if (accessToken !== undefined) { + if (accessTokenTtl === undefined) { + accessTokenTtl = 0; + } + this._map.options.docParams = { 'access_token': accessToken, 'access_token_ttl': accessTokenTtl }; + } + else { + this._map.options.docParams = {}; + } + + // setup for loading the new document, and trigger the load + var docUrl = url.split('?')[0]; + this._map.options.doc = docUrl; + this._map.options.wopiSrc = encodeURIComponent(docUrl); + this._map.loadDocument(); + } + // var name = command.name; - ignored, we get the new name via the wopi's BaseFileName } else if (textMsg.startsWith('statusindicator:')) { //FIXME: We should get statusindicator when saving too, no? diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js index 256f947a0..2a00b05d5 100644 --- a/loleaflet/src/map/handler/Map.WOPI.js +++ b/loleaflet/src/map/handler/Map.WOPI.js @@ -226,7 +226,7 @@ L.Map.WOPI = L.Handler.extend({ if (msg.Values) { if (msg.Values.Filename !== null && msg.Values.Filename !== undefined) { this._map.showBusy(_('Creating copy...'), false); - map.saveAs('wopi:' + msg.Values.Filename); + map.saveAs(msg.Values.Filename); } } }