+
+
+
+
+
+
+
+
+
+
`
+
+export class TopBar extends WithTemplate {
+ constructor(umap, parent) {
+ super()
+ this._umap = umap
+ this._menu = new ContextMenu({ className: 'dark', fixed: true })
+ this.loadTemplate(TOP_BAR_TEMPLATE)
+ this.parent = parent
+ }
+
+ setup() {
+ this.parent.appendChild(this.element)
+ this.elements.name.addEventListener('mouseover', () => {
+ this._umap.tooltip.open({
+ content: translate('Edit the title of the map'),
+ anchor: this.elements.name,
+ position: 'bottom',
+ delay: 500,
+ duration: 5000,
+ })
+ })
+ this.elements.share.addEventListener('mouseover', () => {
+ this._umap.tooltip.open({
+ content: translate('Update who can see and edit the map'),
+ anchor: this.elements.share,
+ position: 'bottom',
+ delay: 500,
+ duration: 5000,
+ })
+ })
+ if (this._umap.properties.editMode === 'advanced') {
+ this.elements.name.addEventListener('click', () => this._umap.editCaption())
+ this.elements.share.addEventListener('click', () => this._umap.permissions.edit())
+ }
+ this.elements.user.addEventListener('click', () => {
+ if (this._umap.properties.user?.id) {
+ const actions = [
+ {
+ label: translate('New map'),
+ action: this._umap.urls.get('map_new'),
+ },
+ {
+ label: translate('My maps'),
+ action: this._umap.urls.get('user_dashboard'),
+ },
+ {
+ label: translate('My teams'),
+ action: this._umap.urls.get('user_teams'),
+ },
+ ]
+ if (this._umap.urls.has('user_profile')) {
+ actions.push({
+ label: translate('My profile'),
+ action: this._umap.urls.get('user_profile'),
+ })
+ }
+ this._menu.openBelow(this.elements.user, actions)
+ }
+ })
+
+ const connectedPeers = this._umap.sync.getNumberOfConnectedPeers()
+ this.elements.peers.addEventListener('mouseover', () => {
+ if (!connectedPeers) return
+ this._umap.tooltip.open({
+ content: translate('{connectedPeers} peer(s) currently connected to this map', {
+ connectedPeers: connectedPeers,
+ }),
+ anchor: this.elements.peers,
+ position: 'bottom',
+ delay: 500,
+ duration: 5000,
+ })
+ })
+
+ this.elements.help.addEventListener('click', () => this._umap.showGetStarted())
+ this.elements.cancel.addEventListener('click', () => this._umap.askForReset())
+ this.elements.cancel.addEventListener('mouseover', () => {
+ this._umap.tooltip.open({
+ content: this._umap.help.displayLabel('CANCEL'),
+ anchor: this.elements.cancel,
+ position: 'bottom',
+ delay: 500,
+ duration: 5000,
+ })
+ })
+ this.elements.view.addEventListener('click', () => this._umap.disableEdit())
+ this.elements.view.addEventListener('mouseover', () => {
+ this._umap.tooltip.open({
+ content: this._umap.help.displayLabel('PREVIEW'),
+ anchor: this.elements.view,
+ position: 'bottom',
+ delay: 500,
+ duration: 5000,
+ })
+ })
+ this.elements.save.addEventListener('click', () => this._umap.saveAll())
+ this.elements.save.addEventListener('mouseover', () => {
+ this._umap.tooltip.open({
+ content: this._umap.help.displayLabel('SAVE'),
+ anchor: this.elements.save,
+ position: 'bottom',
+ delay: 500,
+ duration: 5000,
+ })
+ })
+ this.redraw()
+ }
+
+ redraw() {
+ this.elements.peers.hidden = !this._umap.getProperty('syncEnabled')
+ }
+}
+
+const BOTTOM_BAR_TEMPLATE = `
+