remove-leaflet: Control.MobileTopBar

use standard ES6 class

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I316a7dad8b2085938602907f65f1affd4768a1e2
This commit is contained in:
Szymon Kłos 2024-04-04 15:05:27 +02:00 committed by Szymon Kłos
parent 4fd44c73ec
commit 71f191803d
2 changed files with 29 additions and 38 deletions

View file

@ -9,22 +9,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* L.Control.SearchBar
* JSDialog.MobileTopBar - component of top bar on mobile
*/
/* global $ _UNO _ app */
L.Control.MobileTopBar = L.Control.extend({
options: {
doctype: 'text'
},
initialize: function (docType) {
L.setOptions(this, {docType: docType});
},
onAdd: function (map) {
/* global JSDialog $ _UNO _ app */
class MobileTopBar {
constructor(map) {
this.map = map;
this.docType = map.getDocType();
this.parentContainer = document.getElementById('toolbar-up');
L.DomUtil.addClass(this.parentContainer, 'ui-toolbar');
@ -40,13 +32,13 @@ L.Control.MobileTopBar = L.Control.extend({
map.on('updatepermission', this.onUpdatePermission, this);
map.on('commandstatechanged', this.onCommandStateChanged, this);
},
}
getToolItems: function(docType) {
getToolItems() {
var isReadOnlyMode = app.map ? app.map.isReadOnlyMode() : true;
var canUserWrite = !app.isReadOnly();
if (docType == 'text') {
if (this.docType == 'text') {
return [
{type: 'toolitem', id: 'signstatus', command: '.uno:Signature', w2icon: '', text: _UNO('.uno:Signature'), visible: false},
{type: 'toolitem', id: 'undo', text: _UNO('.uno:Undo'), command: '.uno:Undo', enabled: false},
@ -66,7 +58,7 @@ L.Control.MobileTopBar = L.Control.extend({
{type: 'customtoolitem', id: 'comment_wizard', command: 'comment_wizard', w2icon: 'viewcomments'},
{type: 'menubutton', id: 'userlist:UsersListMenu', visible: false},
];
} else if (docType == 'spreadsheet') {
} else if (this.docType == 'spreadsheet') {
return [
{type: 'toolitem', id: 'signstatus', command: '.uno:Signature', w2icon: '', text: _UNO('.uno:Signature'), visible: false},
{type: 'toolitem', id: 'undo', text: _UNO('.uno:Undo'), command: '.uno:Undo', enabled: false},
@ -79,7 +71,7 @@ L.Control.MobileTopBar = L.Control.extend({
{type: 'customtoolitem', id: 'comment_wizard', command: 'comment_wizard', w2icon: 'viewcomments'},
{type: 'menubutton', id: 'userlist:UsersListMenu', visible: false},
];
} else if (docType == 'presentation') {
} else if (this.docType == 'presentation') {
return [
{type: 'toolitem', id: 'signstatus', command: '.uno:Signature', w2icon: '', text: _UNO('.uno:Signature'), visible: false},
{type: 'toolitem', id: 'undo', text: _UNO('.uno:Undo'), command: '.uno:Undo', enabled: false},
@ -88,10 +80,10 @@ L.Control.MobileTopBar = L.Control.extend({
{type: 'customtoolitem', id: 'mobile_wizard', command: 'mobile_wizard'},
{type: 'customtoolitem', id: 'insertion_mobile_wizard', command: 'insertion_mobile_wizard'},
{type: 'customtoolitem', id: 'comment_wizard', command: 'comment_wizard', w2icon: 'viewcomments'},
{type: 'customtoolitem', id: 'fullscreen-' + docType, text: _UNO('.uno:FullScreen', docType)},
{type: 'customtoolitem', id: 'fullscreen-' + this.docType, text: _UNO('.uno:FullScreen', this.docType)},
{type: 'menubutton', id: 'userlist:UsersListMenu', visible: false},
];
} else if (docType == 'drawing') {
} else if (this.docType == 'drawing') {
return [
{type: 'toolitem', id: 'signstatus', command: '.uno:Signature', w2icon: '', text: _UNO('.uno:Signature'), visible: false},
{type: 'toolitem', id: 'undo', text: _UNO('.uno:Undo'), command: '.uno:Undo', enabled: false},
@ -103,40 +95,40 @@ L.Control.MobileTopBar = L.Control.extend({
{type: 'menubutton', id: 'userlist:UsersListMenu', visible: false},
];
}
},
}
create: function() {
var items = this.getToolItems(this.options.docType);
create() {
var items = this.getToolItems();
this.builder.build(this.parentContainer, items);
},
}
showItem(command, show) {
this.builder.executeAction(this.parentContainer, {
'control_id': command,
'action_type': show ? 'show' : 'hide'
});
},
}
enableItem(command, enable) {
this.builder.executeAction(this.parentContainer, {
'control_id': command,
'action_type': enable ? 'enable' : 'disable'
});
},
}
showSigningItem: function (icon, text) {
showSigningItem(icon, text) {
this.builder.updateWidget(this.parentContainer,
{type: 'toolitem', id: 'signstatus', command: '.uno:Signature', noLabel: true, w2icon: icon, text: text ? text : _UNO('.uno:Signature')});
},
}
selectItem(command, select) {
this.builder.executeAction(this.parentContainer, {
'control_id': command,
'action_type': select ? 'select' : 'unselect'
});
},
}
onUpdatePermission: function(e) {
onUpdatePermission(e) {
var toolbarButtons = ['next', 'prev', 'mobile_wizard', 'insertion_mobile_wizard', 'comment_wizard'];
if (e.perm === 'edit') {
toolbarButtons.forEach((id) => {
@ -152,9 +144,9 @@ L.Control.MobileTopBar = L.Control.extend({
this.showItem('PermissionMode', true);
}
}
},
}
onCommandStateChanged: function(e) {
onCommandStateChanged(e) {
var commandName = e.commandName;
var state = e.state;
@ -168,9 +160,9 @@ L.Control.MobileTopBar = L.Control.extend({
this.enableItem(id, false);
}
}
},
});
}
}
L.control.mobileTopBar = function (docType) {
return new L.Control.MobileTopBar(docType);
JSDialog.MobileTopBar = function (map) {
return new MobileTopBar(map);
};

View file

@ -291,8 +291,7 @@ L.Control.UIManager = L.Control.extend({
if (window.mode.isMobile()) {
$('#mobile-edit-button').show();
this.map.mobileBottomBar = JSDialog.MobileBottomBar(this.map);
this.map.mobileTopBar = L.control.mobileTopBar(docType);
this.map.addControl(this.map.mobileTopBar);
this.map.mobileTopBar = JSDialog.MobileTopBar(this.map);
this.map.mobileSearchBar = L.control.searchBar(this.map);
} else if (enableNotebookbar) {
this.createNotebookbarControl(docType);