diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-06-29 10:52:11 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2019-07-01 17:00:46 +0200 |
commit | 08f9439cdf32d668b04af0912fa2cff18dda6a0c (patch) | |
tree | 615fac1bb2adb2d5ab5721460f29fe6b2d79d107 | |
parent | a5d96a2866830f19fbdd7dd33f4e34ba454ec9a9 (diff) |
leaflet: fire Doc_ModifiedStatus with modified state of the documentcd-4.0.5-3
When .uno:ModifiedStatus is received, now Doc_ModifiedStatus
is fired to inform the client of the modified state of the document.
This is useful in case the integration needs to prompt the user to save
before closing the document (which they can catch with the onunload or
onbeforeunload events in the browser, as well as with our
UI_Close when the default handler is disabled).
Includes working sample and documentation.
Change-Id: Ief30483e2f078b0aa9f3c006a1ecb4093375174c
Reviewed-on: https://gerrit.libreoffice.org/74891
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r-- | loleaflet/html/framed.doc.html | 24 | ||||
-rw-r--r-- | loleaflet/reference.html | 15 | ||||
-rw-r--r-- | loleaflet/src/map/Map.js | 6 | ||||
-rw-r--r-- | test/data/empty.odt | bin | 8131 -> 7405 bytes |
4 files changed, 43 insertions, 2 deletions
diff --git a/loleaflet/html/framed.doc.html b/loleaflet/html/framed.doc.html index d89a1a98f..80f842c40 100644 --- a/loleaflet/html/framed.doc.html +++ b/loleaflet/html/framed.doc.html @@ -87,12 +87,30 @@ function receiveMessage(event) { console.log('==== framed.doc.html receiveMessage: ' + event.data); var msg = JSON.parse(event.data); - if (msg && msg.MessageId == 'App_LoadingStatus') { + if (!msg) { + return; + } + if (msg.MessageId == 'App_LoadingStatus') { if (msg.Values) { if (msg.Values.Status == 'Document_Loaded') { window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*'); } } + } else if (msg.MessageId == 'Doc_ModifiedStatus') { + if (msg.Values) { + if (msg.Values.Modified == true) { + document.getElementById("ModifiedStatus").innerHTML = "Modified"; + } + else { + document.getElementById("ModifiedStatus").innerHTML = "Saved"; + } + } + } else if (msg.MessageId == 'Action_Save_Resp') { + if (msg.Values) { + if (msg.Values.success == true) { + document.getElementById("ModifiedStatus").innerHTML = "Saved"; + } + } } } @@ -125,6 +143,10 @@ <button onclick="disable_default_uiaction('UI_Save', false); return false;">Enable default save action</button></br></br> </form> + <p>Modified Status: + <span id="ModifiedStatus">Saved</span> + </p> + <!-- The hostname and pathnames below are obviously specific to my personal environment and need to be changed appropriately. Also the hex string needs to be changed of course, to the right one as diff --git a/loleaflet/reference.html b/loleaflet/reference.html index 80366cc90..d6b1ca0ed 100644 --- a/loleaflet/reference.html +++ b/loleaflet/reference.html @@ -3261,6 +3261,21 @@ Editor to WOPI host Response to this query is sent via <code>Action_SaveAs</code> message. </td> </tr> + <tr> + <td><code><b>Doc_ModifiedStatus</b></code></td> + <td></td> + <td> + Notification to update the modified status of the document. + Values.Modified will be true, if the document has been modified + since the last save, otherwise, it will be false if the document + has been saved. + + Note that this notification may be published without a change + from the prior value, so care must be taken to check the Values.Modified + value and not assume the notifiaction itself implies the + modified state of the document on its own. + </td> + </tr> </table> <h3 id='loleaflet-postmessage-python'>Calling Python scripts</h3> diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index c43f873d9..f0f692c28 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -209,8 +209,12 @@ L.Map = L.Evented.extend({ this._docLoaded = false; this.on('commandstatechanged', function(e) { - if (e.commandName === '.uno:ModifiedStatus') + if (e.commandName === '.uno:ModifiedStatus') { this._everModified = this._everModified || (e.state === 'true'); + + // Fire an event to let the client know whether the document needs saving or not. + this.fire('postMessage', {msgId: 'Doc_ModifiedStatus', args: { Modified: e.state === 'true' }}); + } }, this); this.on('docloaded', function(e) { diff --git a/test/data/empty.odt b/test/data/empty.odt Binary files differindex 208d2f874..6b0747507 100644 --- a/test/data/empty.odt +++ b/test/data/empty.odt |