[Libreoffice-commits] online.git: Branch 'libreoffice-6-2' - loleaflet/js loleaflet/src

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Apr 9 12:25:04 UTC 2019


 loleaflet/js/toolbar.js                      |    2 -
 loleaflet/src/control/Control.AlertDialog.js |   47 +++++++++++++++++++++++++++
 loleaflet/src/errormessages.js               |    2 +
 3 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit 1767dcdb2a8195ba3b40bcf67876e3425fc4ae7c
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Thu Mar 28 11:49:56 2019 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Tue Apr 9 14:13:20 2019 +0200

    Introduce warning when leaving the editor
    
    Change-Id: Id9fe06015b45f37ae415f8e3607434d984a6074f

diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js
index ea740e610..bb9b73fac 100644
--- a/loleaflet/js/toolbar.js
+++ b/loleaflet/js/toolbar.js
@@ -2212,7 +2212,7 @@ function setupToolbar(e) {
 	});
 
 	map.on('hyperlinkclicked', function (e) {
-		window.open(e.url, '_blank');
+		map.fire('warn', {url: e.url, map: map, cmd: 'openlink'});
 	});
 
 	map.on('cellformula', function (e) {
diff --git a/loleaflet/src/control/Control.AlertDialog.js b/loleaflet/src/control/Control.AlertDialog.js
index d63c80432..bb4c61685 100644
--- a/loleaflet/src/control/Control.AlertDialog.js
+++ b/loleaflet/src/control/Control.AlertDialog.js
@@ -24,6 +24,53 @@ L.Control.AlertDialog = L.Control.extend({
 		else if (e.cmd == 'load' && e.kind == 'docunloading') {
 			// Handled by transparently retrying.
 			return;
+		} else if (e.cmd == 'openlink') {
+			var url = e.url;
+			var messageText = window.errorMessages.leaving;
+
+			var isLinkValid = true;
+			if (url.trim().toLowerCase().startsWith('javascript:')) {
+				isLinkValid = false;
+				messageText = window.errorMessages.invalidLink;
+				messageText = messageText.replace('%url', url);
+			}
+
+			var buttonsList = [];
+
+			if (isLinkValid) {
+				buttonsList.push({
+					text: _('Open link'),
+					type: 'button',
+					className: 'vex-dialog-button-primary',
+					click: function openClick () {
+						window.open(url, '_blank');
+						vex.close(vex.dialogID);
+						vex.dialogID = 0;
+					}
+				});
+			}
+
+			buttonsList.push({
+				text: _('Edit'),
+				type: 'button',
+				className: 'vex-dialog-button-secondary',
+				click: function editClick () {
+					e.map.toggleCommandState('HyperlinkDialog');
+					vex.close(vex.dialogID);
+					vex.dialogID = 0;
+				}
+			});
+
+			vex.dialog.open({
+				message: messageText,
+				showCloseButton: true,
+				buttons: buttonsList,
+				callback: function() {},
+				beforeClose: function () {
+					e.map.focus();
+					e.map.enable(true);
+				}
+			});
 		} else if (e.cmd && e.kind) {
 			var msg = _('The server encountered a %0 error while parsing the %1 command.');
 			msg = msg.replace('%0', e.kind);
diff --git a/loleaflet/src/errormessages.js b/loleaflet/src/errormessages.js
index 3381b9126..0baa1e626 100644
--- a/loleaflet/src/errormessages.js
+++ b/loleaflet/src/errormessages.js
@@ -21,6 +21,8 @@ errorMessages.wrongwopisrc = _('Wrong or missing WOPISrc parameter, please conta
 errorMessages.sessionexpiry = _('Your session will expire in %time. Please save your work and refresh the session (or webpage) to continue.');
 errorMessages.sessionexpired = _('Your session has been expired. Further changes to document might not be saved. Please refresh the session (or webpage) to continue.');
 errorMessages.faileddocloading = _('Failed to load the document. Please ensure the file type is supported and not corrupted, and try again.');
+errorMessages.invalidLink = _('Invalid link: \'%url\'');
+errorMessages.leaving = _('You are leaving the editor, are you sure you want to proceed?');
 
 errorMessages.storage = {
 	loadfailed: _('Failed to read document from storage. Please contact your storage server (%storageserver) administrator.'),


More information about the Libreoffice-commits mailing list