[Libreoffice-commits] online.git: loleaflet/src
Pranav Kant
pranavk at collabora.co.uk
Mon Feb 22 20:23:50 UTC 2016
loleaflet/src/core/Socket.js | 40 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)
New commits:
commit 98fbc0c4a4718255fb0e2aafaa36df2be279d1fb
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Feb 4 23:13:52 2016 +0530
loleaflet: Handle password protected documents
Change-Id: Ife7923869710999de83365dc2c6be33ed42c2f3b
Reviewed-on: https://gerrit.libreoffice.org/21895
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index cf8a531..f3c7dd7 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -2,7 +2,7 @@
* L.Socket contains methods for the communication with the server
*/
-/* global _ */
+/* global _ vex */
L.Socket = L.Class.extend({
ProtocolVersionNumber: '0.1',
@@ -63,6 +63,9 @@ L.Socket = L.Class.extend({
if (this._map.options.timestamp) {
msg += ' timestamp=' + this._map.options.timestamp;
}
+ if (this._map._docPassword) {
+ msg += ' password=' + this._map._docPassword;
+ }
if (this._map.options.renderingOptions) {
var options = {
'rendering': this._map.options.renderingOptions
@@ -95,6 +98,7 @@ L.Socket = L.Class.extend({
textMsg = String.fromCharCode.apply(null, imgBytes.subarray(0, index));
}
+ var command = this.parseServerCmd(textMsg);
if (textMsg.startsWith('loolserver ')) {
// This must be the first message.
if (this._map._docLayer) {
@@ -105,6 +109,39 @@ L.Socket = L.Class.extend({
this.fire('error', {msg: _('Unsupported server version.')});
}
}
+ else if (textMsg.startsWith('error:') && command.errorCmd === 'load') {
+ var errorKind = command.errorKind;
+ var passwordNeeded = false;
+ if (errorKind.startsWith('passwordrequired')) {
+ passwordNeeded = true;
+ var msg = '';
+ var passwordType = errorKind.split(':')[1];
+ if (passwordType === 'to-view') {
+ msg += _('Document requires password to view.');
+ }
+ else if (passwordType === 'to-modify') {
+ msg += _('Document requires password to modify.');
+ msg += ' ';
+ msg += _('Hit Cancel to open in view-only mode.');
+ }
+ } else if (errorKind.startsWith('wrongpassword')) {
+ passwordNeeded = true;
+ msg = _('Wrong password provided. Please try again.');
+ }
+
+ if (passwordNeeded) {
+ // Ask the user for password
+ vex.dialog.open({
+ message: msg,
+ input: '<input name="password" type="password" required />',
+ callback: L.bind(function(data) {
+ this._map._docPassword = data.password;
+ this._onOpen();
+ }, this)
+ });
+ return;
+ }
+ }
else if (!textMsg.startsWith('tile:') && !textMsg.startsWith('renderfont:')) {
// log the tile msg separately as we need the tile coordinates
L.Log.log(textMsg, L.INCOMING);
@@ -135,7 +172,6 @@ L.Socket = L.Class.extend({
tileHeightTwips = Math.round(tileHeightTwips * scale);
}
- var command = this.parseServerCmd(textMsg);
var docLayer = null;
if (command.type === 'text') {
docLayer = new L.WriterTileLayer('', {
More information about the Libreoffice-commits
mailing list