[Libreoffice-commits] online.git: loleaflet/src

Jan Holesovsky (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 16 09:32:04 UTC 2020


 loleaflet/src/control/Control.Menubar.js |    5 -
 loleaflet/src/control/Toolbar.js         |   88 ++++++++++++++++++-------------
 2 files changed, 53 insertions(+), 40 deletions(-)

New commits:
commit 8133c44f6d2074eeab4e85c42f0d570b764b1cb9
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Apr 15 13:13:27 2020 +0200
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Apr 16 11:31:46 2020 +0200

    Welcome: Rework to handle non-existing welcome message.
    
    And do some small additional amendments, like decrease the retry timeout
    to one day, don't hide the menu entry based on the About dialog, or
    consistently name the cookies.
    
    Change-Id: I4170161a44230b05333798dc68d8c3ffe07e26d4
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92267
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js
index 1d31eee93..ac4a19766 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -1182,7 +1182,7 @@ L.Control.Menubar = L.Control.extend({
 		} else if (id === 'about') {
 			this._map.showLOAboutDialog();
 		} else if (id === 'latest-updates') {
-			this._map.showWelcomeDialog();
+			this._map.showWelcomeDialog(/*calledFromMenu=*/true);
 		} else if (id === 'report-an-issue') {
 			window.open('https://bugs.documentfoundation.org/enter_bug.cgi?product=LibreOffice%20Online', '_blank');
 		} else if (id === 'inserthyperlink') {
@@ -1305,9 +1305,6 @@ L.Control.Menubar = L.Control.extend({
 		if (menuItem.id === 'about' && (L.DomUtil.get('about-dialog') === null)) {
 			return false;
 		}
-		if (menuItem.id === 'latest-updates' && (L.DomUtil.get('about-dialog') === null)) {
-			return false;
-		}
 		if (menuItem.id === 'signdocument' && (L.DomUtil.get('document-signing-bar') === null)) {
 			return false;
 		}
diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 7ba6c0a14..e6f1a7e6f 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -344,7 +344,8 @@ L.Map.include({
 		});
 	},
 
-	showWelcomeDialog: function() {
+	// show the actual welcome dialog with the given data
+	_showWelcomeDialogVex: function(data) {
 		var w;
 		var iw = window.innerWidth;
 		if (iw < 768) {
@@ -356,43 +357,58 @@ L.Map.include({
 		else {
 			w = iw / 5 + 590;
 		}
+
+		// show the dialog
 		var map = this;
-		var welcomeLocation = 'welcome/welcome-' + String.locale + '.html';
-		$.get(welcomeLocation, function(data, textStatus) {
-			if (textStatus !== 'success') {
-				// Welcome dialog disabled in loolwsd.xml or nonexistant for some other reason
-				// Let's check back in a week (60 x 60 x 24 x 7 = 604800 seconds)
-				var welcomeDisabledCookie = 'loolWelcomeDisabled=true; max-age=604800; SameSite=Strict';
-				document.cookie = welcomeDisabledCookie;
-				return;
+		vex.open({
+			unsafeContent: data,
+			showCloseButton: true,
+			escapeButtonCloses: true,
+			overlayClosesOnClick: true,
+			closeAllOnPopState: false,
+			buttons: {},
+			afterOpen: function() {
+				var $vexContent = $(this.contentEl);
+				this.contentEl.style.width = w + 'px';
+				map.enable(false);
+
+				$vexContent.attr('tabindex', -1);
+				$vexContent.focus();
+				// workaround for https://github.com/HubSpot/vex/issues/43
+				$('.vex-overlay').css({ 'pointer-events': 'none'});
+			},
+			beforeClose: function () {
+				map.focus();
+				map.enable(true);
 			}
-			var WSDVerCookie = 'WSDWelcomeVer=' + map._socket.WSDServer.Version;
-			// Cookie will not expire for a year, and it will not be sent to other domains
-			WSDVerCookie += '; max-age=31536000; SameSite=Strict';
-			vex.open({
-				unsafeContent: data,
-				showCloseButton: true,
-				escapeButtonCloses: true,
-				overlayClosesOnClick: true,
-				closeAllOnPopState: false,
-				buttons: {},
-				afterOpen: function() {
-					var $vexContent = $(this.contentEl);
-					this.contentEl.style.width = w + 'px';
-					map.enable(false);
+		});
+	},
 
-					$vexContent.attr('tabindex', -1);
-					$vexContent.focus();
-					// workaround for https://github.com/HubSpot/vex/issues/43
-					$('.vex-overlay').css({ 'pointer-events': 'none'});
-				},
-				beforeClose: function () {
-					map.focus();
-					map.enable(true);
+	showWelcomeDialog: function(calledFromMenu) {
+		console.log('showWelcomeDialog, calledFromMenu: ' + calledFromMenu);
+		var welcomeLocation = 'welcome/welcome-' + String.locale + '.html';
+
+		// try to load the welcome message
+		var map = this;
+		$.get(welcomeLocation)
+			.done(function(data) {
+				map._showWelcomeDialogVex(data);
+				if (!calledFromMenu) {
+					var WSDVerCookie = 'WSDWelcomeVersion=' + map._socket.WSDServer.Version;
+					// Cookie will not expire for a year, and it will not be sent to other domains
+					WSDVerCookie += '; max-age=31536000; SameSite=Strict';
 					document.cookie = WSDVerCookie;
 				}
+			})
+			.fail(function() {
+				// Welcome dialog disabled in loolwsd.xml or nonexistant for some other reason
+				// Let's check back in a day (60 x 60 x 24 = 86400 seconds)
+				var welcomeDisabledCookie = 'WSDWelcomeDisabled=true; max-age=86400; SameSite=Strict';
+				document.cookie = welcomeDisabledCookie;
+
+				if (calledFromMenu)
+					map._showWelcomeDialogVex(_('We are sorry, the information about the latest updates is not available.'));
 			});
-		});
 	},
 
 	getCookie: function(name) {
@@ -408,10 +424,10 @@ L.Map.include({
 	},
 
 	shouldWelcome: function() {
-		var currentVerCookie = this.getCookie('WSDWelcomeVer');
-		var newVerCookie = 'WSDWelcomeVer=' + this._socket.WSDServer.Version;
-		var welcomeDisabledCookie = this.getCookie('loolWelcomeDisabled');
-		var isWelcomeDisabled = welcomeDisabledCookie === 'loolWelcomeDisabled=true';
+		var currentVerCookie = this.getCookie('WSDWelcomeVersion');
+		var newVerCookie = 'WSDWelcomeVersion=' + this._socket.WSDServer.Version;
+		var welcomeDisabledCookie = this.getCookie('WSDWelcomeDisabled');
+		var isWelcomeDisabled = welcomeDisabledCookie === 'WSDWelcomeDisabled=true';
 
 		if (currentVerCookie !== newVerCookie && !isWelcomeDisabled && !L.Browser.cypressTest) {
 			return true;


More information about the Libreoffice-commits mailing list