loleaflet/src/control/Toolbar.js      |    5 ++++-
 loleaflet/src/core/Socket.js          |   31 +++++++++++++++++++++++++++++--
 loleaflet/src/map/handler/Map.WOPI.js |    2 +-
 3 files changed, 34 insertions(+), 4 deletions(-)

New commits:
commit dd2c950185e3622441929167672df39b9bd40f07
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Fri Nov 3 19:00:58 2017 +0100

    Save As: Reload the newly created document after the Save As.
    
    Change-Id: Ibf979cce4fea13a31ece089394dab296158a159b
    Reviewed-on: https://gerrit.libreoffice.org/44283
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Tested-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index c47e523d..337188a0 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 e5028b69..cc7e8d6c 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -119,6 +119,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;
@@ -560,8 +566,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 f06e30fc..0201e1d0 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -216,7 +216,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);
                                }
                        }
                }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to