loleaflet/dist/toolbar/toolbar.js     |   22 ++++++++++++++---
 loleaflet/reference.html              |   33 ++++++++++++++++++++++++++
 loleaflet/src/map/handler/Map.WOPI.js |   42 ++++++++++++++++++++++++++++++++--
 3 files changed, 91 insertions(+), 6 deletions(-)

New commits:
commit 3867bbe56ecceab8e0d3e4f1c85b83de08000f17
Author: Pranav Kant <pran...@collabora.co.uk>
Date:   Wed Jun 7 12:57:07 2017 +0530

    Allow adding custom buttons to our toolbar from host; save result resp.
    
    ... with no functionality attached to it except notifying the WOPI host
    that button was clicked. Host is supposed to do the action thereafter
    itself.
    
    Also, notify the host when a save succeeds or fails.
    
    Change-Id: I0daa2690af2259233840ea7ab4326b9b80d5fa87

diff --git a/loleaflet/dist/toolbar/toolbar.js 
b/loleaflet/dist/toolbar/toolbar.js
index d44a5df6..3344e8cc 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -210,7 +210,11 @@ function onClick(id, item, subItem) {
        if (item.disabled) {
                return;
        }
-       if (item.uno) {
+
+       if (item.postmessage && item.type === 'button') {
+               map.fire('postMessage', {msgId: 'Clicked_Button', args: {Id: 
item.id} });
+       }
+       else if (item.uno) {
                if (item.unosheet && map.getDocType() === 'spreadsheet') {
                        map.toggleCommandState(item.unosheet);
                }
@@ -1422,9 +1426,19 @@ map.on('updateparts pagenumberchanged', function (e) {
 map.on('commandresult', function (e) {
        var commandName = e.commandName;
 
-       if (commandName === '.uno:Save' && e.success === true) {
-               // Saved a new version; the document is modified.
-               map._everModified = true;
+       if (commandName === '.uno:Save') {
+               if (e.success) {
+                       // Saved a new version; the document is modified.
+                       map._everModified = true;
+               }
+               var postMessageObj = {
+                       success: e.success
+               };
+               if (!e.success) {
+                       // add the result reason string if failed
+                       postMessageObj['result'] = e.result && e.result.value;
+               }
+               map.fire('postMessage', {msgId: 'Action_Save_Resp', args: 
postMessageObj});
        }
        else if ((commandName === '.uno:Undo' || commandName === '.uno:Redo') &&
                e.success === true && e.result.value && !isNaN(e.result.value)) 
{ /*UNDO_CONFLICT*/
diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 0db570d3..8276ab70 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -2896,6 +2896,7 @@ WOPI host to editor
                <td><code>
                    <nobr>DontTerminateEdit: &lt;boolean&gt;</nobr>
                    <nobr>DontSaveIfUnmodified: &lt;boolean&gt;</nobr>
+                   <nobr>Notify: &lt;boolean&gt;</nobr>
                </code></td>
                <td>Saves the document.<br/>
                <code>DontTerminateEdit</code> is relevant for spreadsheets 
where saving
@@ -2905,6 +2906,9 @@ WOPI host to editor
                <code>DontSaveIfUnmodified</code> prevents loolwsd to save the 
file back to storage if document is
                unmodified (only cursor position changed etc.) but still saved. 
This can be helpful
                to prevent creating unnecessary file revisions.
+               <code>Notify</code> when present and set to true notifies the
+               host when document is saved. See <code>Action_Save_Resp</code>
+               for details.
                </td>
        </tr>
        <tr>
@@ -2927,6 +2931,35 @@ WOPI host to editor
        </tr>
 </table>
 
+Actions response
+(WOPI editor to host)
+<table data-id='postmessage-actions-response'>
+       <tr>
+               <th>MessageId</th>
+               <th>Values</th>
+               <th>Description</th>
+       </tr>
+       <tr>
+               <td><code><b>Action_Save_Resp</b></code></td>
+               <td><code>
+                   <nobr>success: &lt;boolean&gt;</nobr>
+                   <nobr>result: &lt;string&gt;</nobr>
+               </code></td>
+               <td>Acknowledgement when save finishes.<br/>
+               <code>success</code> tells if LOOL was able to save the document
+               successfully. When this is false, then another
+               parameter, <code>result</code> is present which contains the
+               reason that document was not saved.
+               In case, document was not saved because it was not modified,
+               then this parameter contains the string 'unmodified'. In this
+               case, WOPI hosts can be sure that there are no changes pending
+               in the document to be saved to the storage.
+               This response is only emitted if <code>Notify</code> parameter
+               is mentioned by <code>Action_Save</code> PostMessage API.
+               </td>
+       </tr>
+</table>
+
 
 <h2 id="marker">Marker</h2>
 
diff --git a/loleaflet/src/map/handler/Map.WOPI.js 
b/loleaflet/src/map/handler/Map.WOPI.js
index fcb454ec..d187e2a6 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -2,7 +2,7 @@
  * L.WOPI contains WOPI related logic
  */
 
-/* global title */
+/* global title w2ui toolbarUpMobileItems resizeToolbar */
 L.Map.WOPI = L.Handler.extend({
        // If the CheckFileInfo call fails on server side, we won't have any 
PostMessageOrigin.
        // So use '*' because we still needs to send 'close' message to the 
parent frame which
@@ -100,7 +100,36 @@ L.Map.WOPI = L.Handler.extend({
                }
 
                var msg = JSON.parse(e.data);
-               if (msg.MessageId === 'Set_Settings') {
+               if (msg.MessageId === 'Insert_Button') {
+                       if (msg.Values) {
+                               if (msg.Values.id && 
!w2ui['toolbar-up'].get(msg.Values.id)
+                                  && msg.Values.imgurl) {
+                                       // add the css rule for the image
+                                       $('html > head > 
style').append('.w2ui-icon.' + msg.Values.id + '{background: url(' + 
msg.Values.imgurl + ')}');
+
+                                       // add the item to the toolbar
+                                       w2ui['toolbar-up'].insert('save', [
+                                               {
+                                                       type: 'button',
+                                                       id: msg.Values.id,
+                                                       img: msg.Values.id,
+                                                       hint: 
_(msg.Values.hint), /* "Try" to localize ! */
+                                                       postmessage: true /* 
Notify the host back when button is clicked */
+                                               }
+                                       ]);
+                                       if (msg.Values.mobile)
+                                       {
+                                               // Add to our list of items to 
preserve when in mobile mode
+                                               // FIXME: Wrap the toolbar in a 
class so that we don't make use
+                                               // global variables and 
functions like this
+                                               var idx = 
toolbarUpMobileItems.indexOf('save');
+                                               
toolbarUpMobileItems.splice(idx, 0, msg.Values.id);
+                                       }
+                                       resizeToolbar();
+                               }
+                       }
+               }
+               else if (msg.MessageId === 'Set_Settings') {
                        if (msg.Values) {
                                var alwaysActive = msg.Values.AlwaysActive;
                                this._map.options.alwaysActive = !!alwaysActive;
@@ -126,6 +155,7 @@ L.Map.WOPI = L.Handler.extend({
                else if (msg.MessageId === 'Action_Save') {
                        var dontTerminateEdit = msg.Values && 
msg.Values['DontTerminateEdit'];
                        var dontSaveIfUnmodified = msg.Values && 
msg.Values['DontSaveIfUnmodified'];
+                       this._notifySave = msg.Values && msg.Values['Notify'];
 
                        this._map.save(dontTerminateEdit, dontSaveIfUnmodified);
                }
@@ -159,6 +189,14 @@ L.Map.WOPI = L.Handler.extend({
                var msgId = e.msgId;
                var values = e.args || {};
                if (!!this.PostMessageOrigin && window.parent !== window.self) {
+                       // Filter out unwanted save request response
+                       if (msgId === 'Action_Save_Resp') {
+                               if (!this._notifySave)
+                                       return;
+
+                               this._notifySave = false;
+                       }
+
                        var msg = {
                                'MessageId': msgId,
                                'SendTime': Date.now(),
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to