[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-cd-4' - loleaflet/html loleaflet/reference.html loleaflet/src test/data
Ashod Nakashian (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jul 1 15:01:06 UTC 2019
loleaflet/html/framed.doc.html | 24 +++++++++++++++++++++++-
loleaflet/reference.html | 15 +++++++++++++++
loleaflet/src/map/Map.js | 6 +++++-
test/data/empty.odt |binary
4 files changed, 43 insertions(+), 2 deletions(-)
New commits:
commit 08f9439cdf32d668b04af0912fa2cff18dda6a0c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Sat Jun 29 10:52:11 2019 -0400
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Mon Jul 1 17:00:46 2019 +0200
leaflet: fire Doc_ModifiedStatus with modified state of the document
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 at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
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
index 208d2f874..6b0747507 100644
Binary files a/test/data/empty.odt and b/test/data/empty.odt differ
More information about the Libreoffice-commits
mailing list