[Libreoffice-commits] online.git: 2 commits - loleaflet/dist
Tor Lillqvist
tml at collabora.com
Wed Mar 28 11:31:10 UTC 2018
loleaflet/dist/framed.html | 65 ++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 58 insertions(+), 7 deletions(-)
New commits:
commit fc9a46304451fdb1a4c07e0cb2a4566e19cf60e5
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Jan 19 21:17:15 2018 +0200
Add another demo for the Python script in iframe thing: Add a named range
(FIXME: Add input fields for the position, size, and name of the range
and pass them to the Python script.)
Change-Id: I56125e60f4266587297e2f06b00d666d442f270b
diff --git a/loleaflet/dist/framed.html b/loleaflet/dist/framed.html
index aa764dd3b..146bde7b6 100644
--- a/loleaflet/dist/framed.html
+++ b/loleaflet/dist/framed.html
@@ -81,6 +81,24 @@
'*');
}
+ function callAddNamedRange() {
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
+ // FIXME: Add parameters for the position, size, and name of the range
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript',
+ 'SendTime': Date.now(),
+ 'ScriptFile': 'NamedRanges.py',
+ 'Function': 'DefineNamedRange',
+ 'Values': {'sheet': {'type': 'string', 'value': 'Sheet1'},
+ 'x0': {'type': 'long', 'value': '2'},
+ 'y0': {'type': 'long', 'value': '3'},
+ 'width': {'type': 'long', 'value': '2'},
+ 'height': {'type': 'long', 'value': '2'},
+ 'name': {'type': 'string', 'value': 'N' + Date.now().toString()}
+ }
+ }),
+ '*');
+ }
+
function receiveMessage(event) {
var msg = JSON.parse(event.data);
console.log('==== framed.html receiveMessage: ' + event.data);
@@ -135,6 +153,11 @@
<textarea name="result" value="" rows="10" "cols="80"></textarea>
</form>
+ <form id="get-named-ranges-form">
+ <!-- FIXME: Add input fields for the position, size, and name of the range -->
+ Click <button onclick="callAddNamedRange(); return false;">here</button> to add a new named range.
+ </form>
+
<!-- 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
commit 6eef0bd90bf9aab94dc23265c96f56b6db3b9e8f
Author: Tor Lillqvist <tml at collabora.com>
Date: Fri Jan 19 18:02:13 2018 +0200
Add another demo for the iframe thing: Get list of named ranges in document
Change-Id: I3a8f4c05999a8c76df77686ecf55b6a49124c0cf
diff --git a/loleaflet/dist/framed.html b/loleaflet/dist/framed.html
index f45054d4f..aa764dd3b 100644
--- a/loleaflet/dist/framed.html
+++ b/loleaflet/dist/framed.html
@@ -50,7 +50,7 @@
<title>Online Editor</title>
<script>
- function callPythonScript() {
+ function callSetCellColor() {
window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
var x = document.forms[0].elements['x'].value;
var y = document.forms[0].elements['y'].value;
@@ -70,6 +70,17 @@
'*');
}
+ function callGetNamedRanges() {
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript',
+ 'SendTime': Date.now(),
+ 'ScriptFile': 'NamedRanges.py',
+ 'Function': 'GetNamedRanges',
+ 'Values': null
+ }),
+ '*');
+ }
+
function receiveMessage(event) {
var msg = JSON.parse(event.data);
console.log('==== framed.html receiveMessage: ' + event.data);
@@ -78,14 +89,26 @@
msg.MessageId === 'CallPythonScript-Result' &&
msg.hasOwnProperty('Values') &&
msg.Values.hasOwnProperty('commandName') &&
- msg.Values.commandName === 'vnd.sun.star.script:SetCellColor.py$SetCellColor?language=Python&location=share' &&
msg.Values.hasOwnProperty('success') &&
msg.Values.success == 'true' &&
msg.Values.hasOwnProperty('result') &&
msg.Values.result.hasOwnProperty('value')) {
- document.forms[0].elements['result'].readOnly = false;
- document.forms[0].elements['result'].value = msg.Values.result.value;
- document.forms[0].elements['result'].readOnly = true;
+ if (msg.Values.commandName === 'vnd.sun.star.script:SetCellColor.py$SetCellColor?language=Python&location=share') {
+ document.forms['cell-colour-form'].elements['result'].readOnly = false;
+ document.forms['cell-colour-form'].elements['result'].value = msg.Values.result.value;
+ document.forms['cell-colour-form'].elements['result'].readOnly = true;
+ }
+ else if (msg.Values.commandName === 'vnd.sun.star.script:NamedRanges.py$GetNamedRanges?language=Python&location=share') {
+ document.forms['get-named-ranges-form'].elements['result'].readOnly = false;
+ var index = 0;
+ var result = '';
+ while (msg.Values.result.value.hasOwnProperty(index.toString())) {
+ result += msg.Values.result.value[index.toString()].value + "\n";
+ index++;
+ }
+ document.forms['get-named-ranges-form'].elements['result'].value = result;
+ document.forms['get-named-ranges-form'].elements['result'].readOnly = true;
+ }
}
}
window.addEventListener("message", receiveMessage, false);
@@ -98,15 +121,20 @@
<body style="user-select: none;">
<p>
- <form id="frm1">
+ <form id="cell-colour-form">
Cell: (<input type="number" name="x" min="0" max="20" value="0">, <input type="number" name="y" min="0" max="20" value="0">),
colour: <input type="text" name="color" value="#008000">
<br>
- Click <button onclick="callPythonScript(); return false;">here</button>
+ Click <button onclick="callSetCellColor(); return false;">here</button>
to send message to iframe below. It returned <input type="text" name="result" value="" readonly>.
</form>
</p>
+ <form id="get-named-ranges-form">
+ Click <button onclick="callGetNamedRanges(); return false;">here</button> to get a list of named ranges in the document:
+ <textarea name="result" value="" rows="10" "cols="80"></textarea>
+ </form>
+
<!-- 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
More information about the Libreoffice-commits
mailing list