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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sun Jul 12 17:14:36 UTC 2020


 loleaflet/src/control/Control.ColumnHeader.js       |    4 ++--
 loleaflet/src/control/Control.ContextMenu.js        |    2 +-
 loleaflet/src/control/Control.Header.js             |    2 +-
 loleaflet/src/control/Control.LokDialog.js          |    2 +-
 loleaflet/src/control/Control.Menubar.js            |   16 ++++++++--------
 loleaflet/src/control/Control.MobileTopBar.js       |    2 +-
 loleaflet/src/control/Control.MobileWizard.js       |    2 +-
 loleaflet/src/control/Control.NotebookbarBuilder.js |    2 +-
 loleaflet/src/control/Control.PartsPreview.js       |    2 +-
 loleaflet/src/control/Control.PresentationBar.js    |    2 +-
 loleaflet/src/control/Control.RowHeader.js          |    4 ++--
 loleaflet/src/control/Control.SearchBar.js          |    4 ++--
 loleaflet/src/control/Control.Tabs.js               |    2 +-
 loleaflet/src/control/Control.Toolbar.js            |   12 ++++++------
 loleaflet/src/control/Parts.js                      |    2 +-
 loleaflet/src/control/Permission.js                 |   19 +++++++++++++++----
 loleaflet/src/control/Ruler.js                      |    4 ++--
 loleaflet/src/control/Toolbar.js                    |   12 ++++++------
 loleaflet/src/layer/marker/Annotation.js            |    4 ++--
 loleaflet/src/layer/marker/TextInput.js             |    2 +-
 loleaflet/src/layer/tile/CanvasTileLayer.js         |    2 +-
 loleaflet/src/layer/tile/GridLayer.js               |    2 +-
 loleaflet/src/layer/tile/TileLayer.TableOverlay.js  |    2 +-
 loleaflet/src/layer/tile/TileLayer.js               |   18 +++++++++---------
 loleaflet/src/map/Map.js                            |    4 ++--
 loleaflet/src/map/handler/Map.Keyboard.js           |    4 ++--
 loleaflet/src/map/handler/Map.Mouse.js              |    2 +-
 loleaflet/src/map/handler/Map.TouchGesture.js       |    4 ++--
 loleaflet/src/map/handler/Map.WOPI.js               |    4 ++--
 29 files changed, 77 insertions(+), 66 deletions(-)

New commits:
commit 859c808029ab3152f8a9618ab459dfbc0f9b9ab3
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Jul 12 12:44:09 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Jul 12 19:14:27 2020 +0200

    Add functions for getting edit or readonly permission, refactor
    
    Instead of always checking the map._permission value, use the
    isPermissionReadOnly and isPermissionEdit functions. Refactor
    the code to use those.
    
    Change-Id: I77ccd278b98a9318344c9b80c17be7cda09f00f8
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98592
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/loleaflet/src/control/Control.ColumnHeader.js b/loleaflet/src/control/Control.ColumnHeader.js
index ea806593c..0bafd515a 100644
--- a/loleaflet/src/control/Control.ColumnHeader.js
+++ b/loleaflet/src/control/Control.ColumnHeader.js
@@ -102,7 +102,7 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 			var menuData = L.Control.JSDialogBuilder.getMenuStructureForMobileWizard(this._menuItem, true, '');
 			(new Hammer(this._canvas, {recognizers: [[Hammer.Press]]}))
 			.on('press', L.bind(function () {
-				if (this._map._permission === 'edit') {
+				if (this._map.isPermissionEdit()) {
 					window.contextMenuWizard = true;
 					this._map.fire('mobilewizard', menuData);
 				}
@@ -449,7 +449,7 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 		this.mouseInit(canvas);
 
 		if ($('.spreadsheet-header-columns').length > 0) {
-			$('.spreadsheet-header-columns').contextMenu(this._map._permission === 'edit');
+			$('.spreadsheet-header-columns').contextMenu(this._map.isPermissionEdit());
 		}
 	},
 
diff --git a/loleaflet/src/control/Control.ContextMenu.js b/loleaflet/src/control/Control.ContextMenu.js
index 82bd501c5..c4449340e 100644
--- a/loleaflet/src/control/Control.ContextMenu.js
+++ b/loleaflet/src/control/Control.ContextMenu.js
@@ -113,7 +113,7 @@ L.Control.ContextMenu = L.Control.extend({
 
 	_onContextMenu: function(obj) {
 		var map = this._map;
-		if (map._permission !== 'edit') {
+		if (!map.isPermissionEdit()) {
 			return;
 		}
 
diff --git a/loleaflet/src/control/Control.Header.js b/loleaflet/src/control/Control.Header.js
index 8dff63acc..bb0d4433f 100644
--- a/loleaflet/src/control/Control.Header.js
+++ b/loleaflet/src/control/Control.Header.js
@@ -269,7 +269,7 @@ L.Control.Header = L.Control.extend({
 	},
 
 	_onPan: function (event) {
-		if (event.pointerType !== 'touch' || this._map._permission !== 'edit')
+		if (event.pointerType !== 'touch' || !this._map.isPermissionEdit())
 			return;
 
 		if (event.type == 'panstart')
diff --git a/loleaflet/src/control/Control.LokDialog.js b/loleaflet/src/control/Control.LokDialog.js
index 1b70b1cc0..a9c16e98f 100644
--- a/loleaflet/src/control/Control.LokDialog.js
+++ b/loleaflet/src/control/Control.LokDialog.js
@@ -993,7 +993,7 @@ L.Control.LokDialog = L.Control.extend({
 	_launchSidebar: function(id, width, height) {
 		console.log('_launchSidebar: start: id: ' + id + ', width: ' + width + ', height: ' + height);
 		if ((window.mode.isMobile() || window.mode.isTablet())
-		    && this._map._permission != 'edit')
+			&& !this._map.isPermissionEdit())
 			return;
 
 		$('#sidebar-dock-wrapper').css('display', 'block');
diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js
index b83a78a55..ff1c36395 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -754,7 +754,7 @@ L.Control.Menubar = L.Control.extend({
 
 		var liItem = L.DomUtil.create('li', '');
 		liItem.id = 'menu-' + e.id;
-		if (this._map._permission === 'readonly') {
+		if (this._map.isPermissionReadOnly()) {
 			L.DomUtil.addClass(liItem, 'readonly');
 		}
 		var aItem = L.DomUtil.create('a', '', liItem);
@@ -850,7 +850,7 @@ L.Control.Menubar = L.Control.extend({
 
 		// The _createFileIcon function shows the Collabora logo in the iOS app case, no
 		// need to delay that until the document has been made editable.
-		if (window.ThisIsTheiOSApp || this._map._permission !== 'readonly') {
+		if (window.ThisIsTheiOSApp || !this._map.isPermissionReadOnly()) {
 			this._createFileIcon();
 		}
 	},
@@ -992,7 +992,7 @@ L.Control.Menubar = L.Control.extend({
 			var type = $(aItem).data('type');
 			var id = $(aItem).data('id');
 			var constChecked = 'lo-menu-item-checked';
-			if (self._map._permission === 'edit') {
+			if (self._map.isPermissionEdit()) {
 				if (type === 'unocommand') { // enable all depending on stored commandStates
 					var data, lang, languageAndCode;
 					var constUno = 'uno';
@@ -1135,7 +1135,7 @@ L.Control.Menubar = L.Control.extend({
 
 		if (id === 'save') {
 			// Save only when not read-only.
-			if (this._map._permission !== 'readonly') {
+			if (!this._map.isPermissionReadOnly()) {
 				this._map.fire('postMessage', {msgId: 'UI_Save'});
 				if (!this._map._disableDefaultAction['UI_Save']) {
 					this._map.save(false, false);
@@ -1225,7 +1225,7 @@ L.Control.Menubar = L.Control.extend({
 		} else if (id === 'repair') {
 			this._map._socket.sendMessage('commandvalues command=.uno:DocumentRepair');
 		} else if (id === 'searchdialog') {
-			if (this._map._permission === 'readonly') {
+			if (this._map.isPermissionReadOnly()) {
 				$('#toolbar-down').hide();
 				$('#toolbar-search').show();
 				$('#mobile-edit-button').hide();
@@ -1341,7 +1341,7 @@ L.Control.Menubar = L.Control.extend({
 		if (menuItem.id === 'signdocument' && (L.DomUtil.get('document-signing-bar') === null)) {
 			return false;
 		}
-		if (this._map._permission === 'readonly' && menuItem.type === 'menu') {
+		if (this._map.isPermissionReadOnly() && menuItem.type === 'menu') {
 			var found = false;
 			for (var j in this.options.allowedReadonlyMenus) {
 				if (this.options.allowedReadonlyMenus[j] === menuItem.id) {
@@ -1352,7 +1352,7 @@ L.Control.Menubar = L.Control.extend({
 			if (!found)
 				return false;
 		}
-		if (this._map._permission === 'readonly') {
+		if (this._map.isPermissionReadOnly()) {
 			switch (menuItem.id) {
 			case 'last-mod':
 			case 'save':
@@ -1426,7 +1426,7 @@ L.Control.Menubar = L.Control.extend({
 			var liItem = L.DomUtil.create('li', '');
 			if (menu[i].id) {
 				liItem.id = 'menu-' + menu[i].id;
-				if (menu[i].id === 'closedocument' && this._map._permission === 'readonly') {
+				if (menu[i].id === 'closedocument' && this._map.isPermissionReadOnly()) {
 					// see corresponding css rule for readonly class usage
 					L.DomUtil.addClass(liItem, 'readonly');
 				}
diff --git a/loleaflet/src/control/Control.MobileTopBar.js b/loleaflet/src/control/Control.MobileTopBar.js
index acfa82c7d..d754f0a19 100644
--- a/loleaflet/src/control/Control.MobileTopBar.js
+++ b/loleaflet/src/control/Control.MobileTopBar.js
@@ -208,7 +208,7 @@ L.Control.MobileTopBar = L.Control.extend({
 		var commandName = e.commandName;
 		var state = e.state;
 
-		if (this.map._permission === 'edit' && (state === 'enabled' || state === 'disabled')) {
+		if (this.map.isPermissionEdit() && (state === 'enabled' || state === 'disabled')) {
 			var id = window.unoCmdToToolbarId(commandName);
 			var toolbar = w2ui['actionbar'];
 
diff --git a/loleaflet/src/control/Control.MobileWizard.js b/loleaflet/src/control/Control.MobileWizard.js
index a44469d7a..61f1017fb 100644
--- a/loleaflet/src/control/Control.MobileWizard.js
+++ b/loleaflet/src/control/Control.MobileWizard.js
@@ -101,7 +101,7 @@ L.Control.MobileWizard = L.Control.extend({
 
 		$('#mobile-wizard').hide();
 		$('#mobile-wizard-content').empty();
-		if (this.map._permission === 'edit') {
+		if (this.map.isPermissionEdit()) {
 			$('#toolbar-down').show();
 		}
 		if (window.ThisIsTheAndroidApp)
diff --git a/loleaflet/src/control/Control.NotebookbarBuilder.js b/loleaflet/src/control/Control.NotebookbarBuilder.js
index 52e1454c8..8f65d0b37 100644
--- a/loleaflet/src/control/Control.NotebookbarBuilder.js
+++ b/loleaflet/src/control/Control.NotebookbarBuilder.js
@@ -479,7 +479,7 @@ L.Control.NotebookbarBuilder = L.Control.JSDialogBuilder.extend({
 		$(control.container).unbind('click');
 		$(control.container).click(function () {
 			// Save only when not read-only.
-			if (builder.map._permission !== 'readonly') {
+			if (!builder.map.isPermissionReadOnly()) {
 				builder.map.fire('postMessage', {msgId: 'UI_Save'});
 				if (!builder.map._disableDefaultAction['UI_Save']) {
 					builder.map.save(false, false);
diff --git a/loleaflet/src/control/Control.PartsPreview.js b/loleaflet/src/control/Control.PartsPreview.js
index a922ada7a..087a1f5db 100644
--- a/loleaflet/src/control/Control.PartsPreview.js
+++ b/loleaflet/src/control/Control.PartsPreview.js
@@ -207,7 +207,7 @@ L.Control.PartsPreview = L.Control.extend({
 		if (!window.mode.isDesktop()) {
 			(new Hammer(img, {recognizers: [[Hammer.Press]]}))
 			.on('press', L.bind(function () {
-				if (this._map._permission === 'edit') {
+				if (this._map.isPermissionEdit()) {
 					setTimeout(function () {
 						w2ui['actionbar'].click('mobile_wizard');
 					}, 0);
diff --git a/loleaflet/src/control/Control.PresentationBar.js b/loleaflet/src/control/Control.PresentationBar.js
index dd10369b0..f91fbcd6b 100644
--- a/loleaflet/src/control/Control.PresentationBar.js
+++ b/loleaflet/src/control/Control.PresentationBar.js
@@ -158,7 +158,7 @@ L.Control.PresentationBar = L.Control.extend({
 		var commandName = e.commandName;
 		var state = e.state;
 
-		if (this.map._permission === 'edit' && (state === 'enabled' || state === 'disabled')) {
+		if (this.map.isPermissionEdit() && (state === 'enabled' || state === 'disabled')) {
 			var id = window.unoCmdToToolbarId(commandName);
 
 			if (id === 'deletepage' || id === 'insertpage' || id === 'duplicatepage') {
diff --git a/loleaflet/src/control/Control.RowHeader.js b/loleaflet/src/control/Control.RowHeader.js
index 14f568187..faadb575d 100644
--- a/loleaflet/src/control/Control.RowHeader.js
+++ b/loleaflet/src/control/Control.RowHeader.js
@@ -99,7 +99,7 @@ L.Control.RowHeader = L.Control.Header.extend({
 			var menuData = L.Control.JSDialogBuilder.getMenuStructureForMobileWizard(this._menuItem, true, '');
 			(new Hammer(this._canvas, {recognizers: [[Hammer.Press]]}))
 			.on('press', L.bind(function () {
-				if (this._map._permission === 'edit') {
+				if (this._map.isPermissionEdit()) {
 					window.contextMenuWizard = true;
 					this._map.fire('mobilewizard', menuData);
 				}
@@ -438,7 +438,7 @@ L.Control.RowHeader = L.Control.Header.extend({
 		this.mouseInit(canvas);
 
 		if ($('.spreadsheet-header-rows').length > 0) {
-			$('.spreadsheet-header-rows').contextMenu(this._map._permission === 'edit');
+			$('.spreadsheet-header-rows').contextMenu(this._map.isPermissionEdit());
 		}
 	},
 
diff --git a/loleaflet/src/control/Control.SearchBar.js b/loleaflet/src/control/Control.SearchBar.js
index d6714002a..14f4ac944 100644
--- a/loleaflet/src/control/Control.SearchBar.js
+++ b/loleaflet/src/control/Control.SearchBar.js
@@ -80,10 +80,10 @@ L.Control.SearchBar = L.Control.extend({
 		}
 		else if (id === 'hidesearchbar') {
 			$('#toolbar-search').hide();
-			if (this.map._permission === 'edit')
+			if (this.map.isPermissionEdit())
 				$('#toolbar-down').show();
 			/** show edit button if only we are able to edit but in readonly mode */
-			if (window.docPermission  === 'edit' && this.map._permission === 'readonly')
+			if (window.docPermission  === 'edit' && this.map.isPermissionReadOnly())
 				$('#mobile-edit-button').show();
 		}
 	},
diff --git a/loleaflet/src/control/Control.Tabs.js b/loleaflet/src/control/Control.Tabs.js
index 505fd51ce..7bb681364 100644
--- a/loleaflet/src/control/Control.Tabs.js
+++ b/loleaflet/src/control/Control.Tabs.js
@@ -131,7 +131,7 @@ L.Control.Tabs = L.Control.extend({
 							return function() {
 								this._tabForContextMenu = j;
 								window.contextMenuWizard = true;
-								if (this._map._permission != 'readonly') this._map.fire('mobilewizard', menuData);
+								if (!this._map.isPermissionReadOnly()) this._map.fire('mobilewizard', menuData);
 							};
 						}(i).bind(this));
 					} else {
diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js
index de0447a39..fa4e52c4b 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -83,7 +83,7 @@ function onClick(e, id, item) {
 	}
 	else if (id === 'save') {
 		// Save only when not read-only.
-		if (map._permission !== 'readonly') {
+		if (!map.isPermissionReadOnly()) {
 			map.fire('postMessage', {msgId: 'UI_Save'});
 			if (!map._disableDefaultAction['UI_Save']) {
 				map.save(false /* An explicit save should terminate cell edit */, false /* An explicit save should save it again */);
@@ -557,10 +557,10 @@ function getColorPickerData(type) {
 }
 
 function onColorPick(id, color) {
-	if (map.getPermission() !== 'edit') {
+	if (!map.isPermissionEdit()) {
 		return;
 	}
-    // no fill or automatic color is -1
+	// no fill or automatic color is -1
 	if (color === '') {
 		color = -1;
 	}
@@ -845,20 +845,20 @@ function onCommandStateChanged(e) {
 		return;
 
 	if (state === 'true') {
-		if (map._permission === 'edit') {
+		if (map.isPermissionEdit()) {
 			toolbar.enable(id);
 		}
 		toolbar.check(id);
 	}
 	else if (state === 'false') {
-		if (map._permission === 'edit') {
+		if (map.isPermissionEdit()) {
 			toolbar.enable(id);
 		}
 		toolbar.uncheck(id);
 	}
 	// Change the toolbar button states if we are in editmode
 	// If in non-edit mode, will be taken care of when permission is changed to 'edit'
-	else if (map._permission === 'edit' && (state === 'enabled' || state === 'disabled')) {
+	else if (map.isPermissionEdit() && (state === 'enabled' || state === 'disabled')) {
 		var toolbarUp = toolbar;
 		if (state === 'enabled') {
 			toolbarUp.enable(id);
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index de3bcdd9f..d112557f7 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -193,7 +193,7 @@ L.Map.include({
 		else if (typeof (page) === 'number' && page >= 0 && page < docLayer._pages) {
 			docLayer._currentPage = page;
 		}
-		if (this._permission !== 'edit' && docLayer._partPageRectanglesPixels.length > docLayer._currentPage) {
+		if (!this.isPermissionEdit() && docLayer._partPageRectanglesPixels.length > docLayer._currentPage) {
 			// we can scroll to the desired page without having a LOK instance
 			var pageBounds = docLayer._partPageRectanglesPixels[docLayer._currentPage];
 			var pos = new L.Point(
diff --git a/loleaflet/src/control/Permission.js b/loleaflet/src/control/Permission.js
index fcc0cdaad..3938fbc49 100644
--- a/loleaflet/src/control/Permission.js
+++ b/loleaflet/src/control/Permission.js
@@ -39,7 +39,7 @@ L.Map.include({
 	},
 
 	_enterEditMode: function (perm) {
-		if (this._permission == 'readonly' && (window.mode.isMobile() || window.mode.isTablet())) {
+		if (this.isPermissionReadOnly() && (window.mode.isMobile() || window.mode.isTablet())) {
 			this.sendInitUNOCommands();
 		}
 		this._permission = perm;
@@ -70,7 +70,7 @@ L.Map.include({
 	},
 
 	enableSelection: function () {
-		if (this._permission === 'edit') {
+		if (this.isPermissionEdit()) {
 			return;
 		}
 		this._socket.sendMessage('requestloksession');
@@ -78,7 +78,7 @@ L.Map.include({
 	},
 
 	disableSelection: function () {
-		if (this._permission === 'edit') {
+		if (this.isPermissionEdit()) {
 			return;
 		}
 		this.dragging.enable();
@@ -94,5 +94,13 @@ L.Map.include({
 	
 	isPermissionEditForComments: function() {
 		return true;
+	},
+	
+	isPermissionReadOnly: function() {
+		return this._permission === 'readonly';
+	},
+	
+	isPermissionEdit: function() {
+		return this._permission === 'edit';
 	}
 });
diff --git a/loleaflet/src/control/Ruler.js b/loleaflet/src/control/Ruler.js
index e717d84e3..707a79dd8 100644
--- a/loleaflet/src/control/Ruler.js
+++ b/loleaflet/src/control/Ruler.js
@@ -494,7 +494,7 @@ L.Control.Ruler = L.Control.extend({
 	},
 
 	_initiateIndentationDrag: function(e) {
-		if (window.ThisIsTheiOSApp && this._map._permission !== 'edit')
+		if (window.ThisIsTheiOSApp && !this._map.isPermissionEdit())
 			return;
 
 		this._map.rulerActive = true;
@@ -521,7 +521,7 @@ L.Control.Ruler = L.Control.extend({
 			e.clientX = e.touches[0].clientX;
 		}
 
-		if (window.ThisIsTheiOSApp && this._map._permission !== 'edit')
+		if (window.ThisIsTheiOSApp && !this._map.isPermissionEdit())
 			return;
 
 		this._map.rulerActive = true;
diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index c2cd5a837..8f2fd291b 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -27,7 +27,7 @@ L.Map.include({
 	},
 
 	applyFont: function (fontName) {
-		if (this.getPermission() === 'edit') {
+		if (this.isPermissionEdit()) {
 			var msg = 'uno .uno:CharFontName {' +
 				'"CharFontName.FamilyName": ' +
 					'{"type": "string", "value": "' + fontName + '"}}';
@@ -36,7 +36,7 @@ L.Map.include({
 	},
 
 	applyFontSize: function (fontSize) {
-		if (this.getPermission() === 'edit') {
+		if (this.isPermissionEdit()) {
 			var msg = 'uno .uno:FontHeight {' +
 				'"FontHeight.Height": ' +
 				'{"type": "float", "value": "' + fontSize + '"}}';
@@ -121,7 +121,7 @@ L.Map.include({
 			this.fire('error', {cmd: 'setStyle', kind: 'incorrectparam'});
 			return;
 		}
-		if (this._permission === 'edit') {
+		if (this.isPermissionEdit()) {
 			var msg = 'uno .uno:StyleApply {' +
 					'"Style":{"type":"string", "value": "' + style + '"},' +
 					'"FamilyName":{"type":"string", "value":"' + familyName + '"}' +
@@ -135,7 +135,7 @@ L.Map.include({
 			this.fire('error', {cmd: 'setLayout', kind: 'incorrectparam'});
 			return;
 		}
-		if (this._permission === 'edit') {
+		if (this.isPermissionEdit()) {
 			var msg = 'uno .uno:AssignLayout {' +
 					'"WhatPage":{"type":"unsigned short", "value": "' + this.getCurrentPartNumber() + '"},' +
 					'"WhatLayout":{"type":"unsigned short", "value": "' + layout + '"}' +
@@ -165,13 +165,13 @@ L.Map.include({
 				break;
 			}
 		}
-		if (this._permission === 'edit' || isAllowedInReadOnly) {
+		if (this.isPermissionEdit() || isAllowedInReadOnly) {
 			this._socket.sendMessage('uno ' + command + (json ? ' ' + JSON.stringify(json) : ''));
 		}
 	},
 
 	toggleCommandState: function (unoState) {
-		if (this._permission === 'edit') {
+		if (this.isPermissionEdit()) {
 			if (!unoState.startsWith('.uno:')) {
 				unoState = '.uno:' + unoState;
 			}
diff --git a/loleaflet/src/layer/marker/Annotation.js b/loleaflet/src/layer/marker/Annotation.js
index fca32fac9..410316f6a 100644
--- a/loleaflet/src/layer/marker/Annotation.js
+++ b/loleaflet/src/layer/marker/Annotation.js
@@ -219,7 +219,7 @@ L.Annotation = L.Layer.extend({
 		this._contentAuthor = L.DomUtil.create(tagDiv, 'loleaflet-annotation-content-author', tdAuthor);
 		this._contentDate = L.DomUtil.create(tagDiv, 'loleaflet-annotation-date', tdAuthor);
 
-		if (this._data.trackchange && this._map._permission !== 'readonly') {
+		if (this._data.trackchange && !this._map.isPermissionReadOnly()) {
 			var tdAccept = L.DomUtil.create(tagTd, 'loleaflet-annotation-menubar', tr);
 			var acceptButton = this._acceptButton = L.DomUtil.create('button', 'loleaflet-redline-accept-button', tdAccept);
 			var tdReject = L.DomUtil.create(tagTd, 'loleaflet-annotation-menubar', tr);
diff --git a/loleaflet/src/layer/marker/TextInput.js b/loleaflet/src/layer/marker/TextInput.js
index 10c665d12..8e7196e96 100644
--- a/loleaflet/src/layer/marker/TextInput.js
+++ b/loleaflet/src/layer/marker/TextInput.js
@@ -161,7 +161,7 @@ L.TextInput = L.Layer.extend({
 		// Clicking or otherwise focusing the map should focus on the clipboard
 		// container in order for the user to input text (and on-screen keyboards
 		// to pop-up), unless the document is read only.
-		if (this._map._permission !== 'edit') {
+		if (!this._map.isPermissionEdit()) {
 			this._setAcceptInput(false);
 			return;
 		}
diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js
index 4c7bd0394..75750ace2 100644
--- a/loleaflet/src/layer/tile/CanvasTileLayer.js
+++ b/loleaflet/src/layer/tile/CanvasTileLayer.js
@@ -1136,7 +1136,7 @@ L.CanvasTileLayer = L.TileLayer.extend({
 		var maxBorderWidth = 5;
 		var tileBorderSrcs;
 
-		if (this._map._permission === 'edit') {
+		if (this._map.isPermissionEdit()) {
 			tilesToFetch = 5;
 			maxBorderWidth = 3;
 		}
diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index 08c3fc2ab..6c52eac86 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -1188,7 +1188,7 @@ L.GridLayer = L.Layer.extend({
 		var maxBorderWidth = 5;
 		var tileBorderSrc;
 
-		if (this._map._permission === 'edit') {
+		if (this._map.isPermissionEdit()) {
 			tilesToFetch = 5;
 			maxBorderWidth = 3;
 		}
diff --git a/loleaflet/src/layer/tile/TileLayer.TableOverlay.js b/loleaflet/src/layer/tile/TileLayer.TableOverlay.js
index 49b556aec..43e408b22 100644
--- a/loleaflet/src/layer/tile/TileLayer.TableOverlay.js
+++ b/loleaflet/src/layer/tile/TileLayer.TableOverlay.js
@@ -213,7 +213,7 @@ L.TileLayer.include({
 		this._updateTableMarkers();
 	},
 	_onTableSelectedMsg: function (textMsg) {
-		if (this._map._permission !== 'edit') {
+		if (!this._map.isPermissionEdit()) {
 			this._clearTableMarkers();
 			return;
 		}
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 92257f195..3cd53c3cf 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1141,7 +1141,7 @@ L.TileLayer = L.GridLayer.extend({
 			this._prevCellCursorXY = new L.Point(-1, -1);
 		}
 
-		if (textMsg.match('EMPTY') || this._map._permission !== 'edit') {
+		if (textMsg.match('EMPTY') || !this._map.isPermissionEdit()) {
 			this._cellCursorTwips = new L.Bounds(new L.Point(0, 0), new L.Point(0, 0));
 			this._cellCursor = L.LatLngBounds.createDefault();
 			this._cellCursorXY = new L.Point(-1, -1);
@@ -1275,7 +1275,7 @@ L.TileLayer = L.GridLayer.extend({
 			this._showURLPopUp(cursorPos, obj.hyperlink.link);
 		}
 
-		if (!this._map.editorHasFocus() && this._map._isCursorVisible && (modifierViewId === this._viewId) && (this._map._permission === 'edit')) {
+		if (!this._map.editorHasFocus() && this._map._isCursorVisible && (modifierViewId === this._viewId) && (this._map.isPermissionEdit())) {
 			// Regain cursor if we had been out of focus and now have input.
 			// Unless the focus is in the Calc Formula-Bar, don't steal the focus.
 			if (!this._map.calcInputBarHasFocus())
@@ -1823,7 +1823,7 @@ L.TileLayer = L.GridLayer.extend({
 	_onTextSelectionEndMsg: function (textMsg) {
 		var rectangles = this._getTextSelectionRectangles(textMsg);
 
-		if (rectangles.length && this._map._permission === 'edit') {
+		if (rectangles.length && this._map.isPermissionEdit()) {
 			var topLeftTwips = rectangles[0].getTopLeft();
 			var bottomRightTwips = rectangles[0].getBottomRight();
 			var oldSelection = this._textSelectionEnd;
@@ -1841,7 +1841,7 @@ L.TileLayer = L.GridLayer.extend({
 	_onTextSelectionStartMsg: function (textMsg) {
 		var rectangles = this._getTextSelectionRectangles(textMsg);
 
-		if (rectangles.length && this._map._permission === 'edit') {
+		if (rectangles.length && this._map.isPermissionEdit()) {
 			var topLeftTwips = rectangles[0].getTopLeft();
 			var bottomRightTwips = rectangles[0].getBottomRight();
 			var oldSelection = this._textSelectionStart;
@@ -1861,7 +1861,7 @@ L.TileLayer = L.GridLayer.extend({
 
 	_onCellSelectionAreaMsg: function (textMsg) {
 		var strTwips = textMsg.match(/\d+/g);
-		if (strTwips != null && this._map._permission === 'edit') {
+		if (strTwips != null && this._map.isPermissionEdit()) {
 			var topLeftTwips = new L.Point(parseInt(strTwips[0]), parseInt(strTwips[1]));
 			var offset = new L.Point(parseInt(strTwips[2]), parseInt(strTwips[3]));
 			var bottomRightTwips = topLeftTwips.add(offset);
@@ -1883,7 +1883,7 @@ L.TileLayer = L.GridLayer.extend({
 
 	_onCellAutoFillAreaMsg: function (textMsg) {
 		var strTwips = textMsg.match(/\d+/g);
-		if (strTwips != null && this._map._permission === 'edit') {
+		if (strTwips != null && this._map.isPermissionEdit()) {
 			var topLeftTwips = new L.Point(parseInt(strTwips[0]), parseInt(strTwips[1]));
 			var offset = new L.Point(parseInt(strTwips[2]), parseInt(strTwips[3]));
 			var bottomRightTwips = topLeftTwips.add(offset);
@@ -2077,7 +2077,7 @@ L.TileLayer = L.GridLayer.extend({
 	},
 
 	_mapOnError: function (e) {
-		if (e.msg && this._map._permission === 'edit') {
+		if (e.msg && this._map.isPermissionEdit()) {
 			this._map.setPermission('view');
 		}
 	},
@@ -2282,7 +2282,7 @@ L.TileLayer = L.GridLayer.extend({
 	// enable or disable blinking cursor and  the cursor overlay depending on
 	// the state of the document (if the falgs are set)
 	_updateCursorAndOverlay: function (/*update*/) {
-		if (this._map._permission === 'edit'
+		if (this._map.isPermissionEdit()
 		&& this._map._isCursorVisible   // only when LOK has told us it is ok
 		&& this._map.editorHasFocus()   // not when document is not focused
 		&& !this._map.isSearching()  	// not when searching within the doc
@@ -2908,7 +2908,7 @@ L.TileLayer = L.GridLayer.extend({
 				this._map.removeLayer(this._graphicMarker);
 			}
 
-			if (this._map._permission !== 'edit') {
+			if (!this._map.isPermissionEdit()) {
 				return;
 			}
 
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index b94489a9f..e74b99e0e 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -200,7 +200,7 @@ L.Map = L.Evented.extend({
 				this._fireInitComplete('doclayerinit');
 			}
 			if ((window.mode.isTablet() || window.mode.isDesktop()) && this._docLayer._docType == 'text') {
-				var interactiveRuler = this._permission === 'edit' ? true : false;
+				var interactiveRuler = this.isPermissionEdit();
 				L.control.ruler({position:'topleft', interactive:interactiveRuler}).addTo(this);
 			}
 
@@ -1544,7 +1544,7 @@ L.Map = L.Evented.extend({
 		if (type === 'click' || type === 'dblclick' || (type === 'mouseup' &&
 					 typeof this._container._wasSingleTap !== 'undefined' &&
 					 this._container._wasSingleTap)) {
-			if (this._permission === 'edit') {
+			if (this.isPermissionEdit()) {
 				this.fire('editorgotfocus');
 				this.focus();
 			}
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index 6ea10c40e..405b73995 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -324,7 +324,7 @@ L.Map.Keyboard = L.Handler.extend({
 			}
 		}
 
-		if (this._map._permission === 'edit') {
+		if (this._map.isPermissionEdit()) {
 			docLayer._resetPreFetching();
 
 			if (this._ignoreKeyEvent(ev)) {
@@ -519,7 +519,7 @@ L.Map.Keyboard = L.Handler.extend({
 			return true;
 		case 83: // s
 			// Save only when not read-only.
-			if (this._map._permission !== 'readonly') {
+			if (!this._map.isPermissionReadOnly()) {
 				this._map.fire('postMessage', {msgId: 'UI_Save'});
 				if (!this._map._disableDefaultAction['UI_Save']) {
 					this._map.save(false /* An explicit save should terminate cell edit */,
diff --git a/loleaflet/src/map/handler/Map.Mouse.js b/loleaflet/src/map/handler/Map.Mouse.js
index cb5b4d91c..0daa13792 100644
--- a/loleaflet/src/map/handler/Map.Mouse.js
+++ b/loleaflet/src/map/handler/Map.Mouse.js
@@ -141,7 +141,7 @@ L.Map.Mouse = L.Handler.extend({
 				this._clickCount = 1;
 				mousePos = docLayer._latLngToTwips(e.latlng);
 				var timeOut = 250;
-				if (this._map._permission === 'edit') {
+				if (this._map.isPermissionEdit()) {
 					timeOut = 0;
 				}
 				this._mouseEventsQueue.push(L.bind(function() {
diff --git a/loleaflet/src/map/handler/Map.TouchGesture.js b/loleaflet/src/map/handler/Map.TouchGesture.js
index 2a17360e2..15bb932d4 100644
--- a/loleaflet/src/map/handler/Map.TouchGesture.js
+++ b/loleaflet/src/map/handler/Map.TouchGesture.js
@@ -350,7 +350,7 @@ L.Map.TouchGesture = L.Handler.extend({
 				acceptInput = (cellCursor && cellCursor.contains(latlng));
 				if (acceptInput) {
 					// Enter cell-edit mode on second tap of a selected cell.
-					if (this._map._permission === 'edit') {
+					if (this._map.isPermissionEdit()) {
 						docLayer.postKeyboardEvent('input', 0, 769); // F2
 						sendMouseEvents = false; // Mouse events will exit editing mode.
 					}
@@ -380,7 +380,7 @@ L.Map.TouchGesture = L.Handler.extend({
 		if (docLayer) {
 			if (docLayer._docType === 'spreadsheet' && !docLayer.hasGraphicSelection()) {
 				// Enter cell-edit mode on double-taping a cell.
-				if (this._map._permission === 'edit') {
+				if (this._map.isPermissionEdit()) {
 					docLayer.postKeyboardEvent('input', 0, 769); // F2
 				}
 			} else {
diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js
index 3e41b7fae..39c1520fe 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -286,7 +286,7 @@ L.Map.WOPI = L.Handler.extend({
 			if (msg.Values) {
 				if (msg.Values.id && !w2ui['editbar'].get(msg.Values.id)
 				    && msg.Values.imgurl) {
-					if (this._map._permission === 'edit') {
+					if (this._map.isPermissionEdit()) {
 						// add the css rule for the image
 						var style = $('html > head > style');
 						if (style.length == 0)
@@ -316,7 +316,7 @@ L.Map.WOPI = L.Handler.extend({
 							toolbarUpMobileItems.splice(idx, 0, msg.Values.id);
 						}
 					}
-					else if (this._map._permission === 'readonly') {
+					else if (this._map.isPermissionReadOnly()) {
 						// Just add a menu entry for it
 						this._map.fire('addmenu', {id: msg.Values.id, label: msg.Values.hint});
 					}
commit 5ecc8e59832f526d99c0597aa552c642d57699b7
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Jul 12 11:58:50 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Jul 12 19:14:17 2020 +0200

    Enable comments editing when in read-only mode
    
    This also prepares the read-only with comments editing mode.
    
    Change-Id: Ida643bb82bd54acff95531df1bd5d34534f5bc79
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98591
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/loleaflet/src/control/Permission.js b/loleaflet/src/control/Permission.js
index 3c1f5e172..fcc0cdaad 100644
--- a/loleaflet/src/control/Permission.js
+++ b/loleaflet/src/control/Permission.js
@@ -54,7 +54,6 @@ L.Map.include({
 		if (this._docLayer._docType === 'text') {
 			this.setZoom(10);
 		}
-
 	},
 
 	_enterReadOnlyMode: function (perm) {
@@ -91,5 +90,9 @@ L.Map.include({
 
 	getPermission: function () {
 		return this._permission;
+	},
+	
+	isPermissionEditForComments: function() {
+		return true;
 	}
 });
diff --git a/loleaflet/src/layer/marker/Annotation.js b/loleaflet/src/layer/marker/Annotation.js
index 1418a8606..fca32fac9 100644
--- a/loleaflet/src/layer/marker/Annotation.js
+++ b/loleaflet/src/layer/marker/Annotation.js
@@ -236,7 +236,7 @@ L.Annotation = L.Layer.extend({
 			}, this);
 		}
 
-		if (this.options.noMenu !== true && this._map._permission !== 'readonly') {
+		if (this.options.noMenu !== true && this._map.isPermissionEditForComments()) {
 			var tdMenu = L.DomUtil.create(tagTd, 'loleaflet-annotation-menubar', tr);
 			var divMenu = this._menu = L.DomUtil.create(tagDiv, this._data.trackchange ? 'loleaflet-annotation-menu-redline' : 'loleaflet-annotation-menu', tdMenu);
 			divMenu.title = _('Open menu');


More information about the Libreoffice-commits mailing list