Skip to content

Commit 9c44818

Browse files
committed
jsdialog: inherit from Component in Sidebar Base
Signed-off-by: Szymon Kłos <[email protected]> Change-Id: Ie2547e90349a0ba5af761c278e1cf699e7573066
1 parent b81f837 commit 9c44818

File tree

2 files changed

+37
-45
lines changed

2 files changed

+37
-45
lines changed

browser/src/control/Control.QuickFindPanel.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class QuickFindPanel extends SidebarBase {
2121

2222
onAdd(map: any) {
2323
super.onAdd(map);
24-
this.builder.setWindowId(QUICKFIND_WINDOW_ID);
24+
25+
this.builder?.setWindowId(QUICKFIND_WINDOW_ID);
2526

2627
this.map = map;
2728
this.map.on('quickfind', this.onQuickFind, this);
@@ -99,12 +100,16 @@ class QuickFindPanel extends SidebarBase {
99100
onQuickFind(data: any) {
100101
const quickFindData = data.data;
101102

102-
if (this.container) this.container.innerHTML = '';
103-
else console.error('QuickFind: no container');
103+
if (!this.container) {
104+
app.console.error('QuickFind: no container');
105+
return;
106+
}
107+
108+
this.container.innerHTML = '';
104109

105110
const modifiedData = this.addPlaceholderIfEmpty(quickFindData);
106111

107-
this.builder.build(this.container, [modifiedData], false);
112+
this.builder?.build(this.container, [modifiedData], false);
108113

109114
app.showQuickFind = true;
110115
// this will update the indentation marks for elements like ruler

browser/src/control/Control.SidebarBase.ts

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,30 @@ enum SidebarType {
2121
Navigator = 'navigator',
2222
QuickFind = 'quickfind',
2323
}
24-
abstract class SidebarBase {
24+
abstract class SidebarBase extends JSDialogComponent {
2525
type: SidebarType;
2626

27-
map: any;
28-
29-
container: HTMLDivElement;
3027
documentContainer: HTMLDivElement;
3128
wrapper: HTMLElement;
32-
builder: JSBuilder;
3329

3430
constructor(map: any, type: SidebarType) {
31+
super(map, 'Sidebar', type);
3532
this.type = type;
3633
this.onAdd(map);
3734
}
3835

39-
onAdd(map: any) {
40-
this.map = map;
41-
42-
app.events.on('resize', this.onResize.bind(this));
43-
36+
protected createBuilder() {
4437
this.builder = new window.L.control.jsDialogBuilder({
4538
mobileWizard: this,
46-
map: map,
39+
map: this.map,
4740
cssClass: `jsdialog sidebar`, // use sidebar css for now, maybe have seperate css for navigator later
4841
useScrollAnimation: false, // icon views cause jump on sidebar open
4942
suffix: 'sidebar',
5043
callback: this.callback.bind(this),
5144
});
45+
}
46+
47+
protected setupContainer(parentContainer?: HTMLElement) {
5248
if (!this.container) {
5349
this.container = window.L.DomUtil.createWithId(
5450
'div',
@@ -58,14 +54,20 @@ abstract class SidebarBase {
5854
}
5955
this.wrapper = document.getElementById(`${this.type}-dock-wrapper`);
6056
this.documentContainer = document.querySelector('#document-container');
57+
}
58+
59+
onAdd(map: any) {
60+
this.map = map;
61+
this.createBuilder();
62+
this.setupContainer(undefined);
63+
64+
app.events.on('resize', this.onResize.bind(this));
6165

62-
this.map.on('jsdialogupdate', this.onJSUpdate, this);
63-
this.map.on('jsdialogaction', this.onJSAction, this);
66+
this.registerMessageHandlers();
6467
}
6568

6669
onRemove() {
67-
this.map.off('jsdialogupdate', this.onJSUpdate, this);
68-
this.map.off('jsdialogaction', this.onJSAction, this);
70+
this.unregisterMessageHandlers();
6971
}
7072

7173
isVisible(): boolean {
@@ -84,37 +86,21 @@ abstract class SidebarBase {
8486
this.map.uiManager.setDocTypePref('Show' + upperCaseType, false);
8587
}
8688

87-
onJSUpdate(e: FireEvent) {
88-
var data = e.data;
89-
90-
if (data.jsontype !== this.type) return;
91-
92-
if (!this.container) return;
93-
94-
if (!this.builder) return;
95-
89+
protected onJSUpdate(e: FireEvent) {
9690
// reduce unwanted warnings in console
97-
if (data.control.id === 'addonimage') {
98-
window.app.console.log('Ignored update for control: ' + data.control.id);
91+
if (e?.data?.control.id === 'addonimage') {
92+
window.app.console.log(
93+
'Ignored update for control: ' + e.data.control.id,
94+
);
9995
return;
10096
}
10197

102-
this.builder.updateWidget(this.container, data.control);
98+
super.onJSUpdate(e);
10399
}
104100

105-
onJSAction(e: FireEvent) {
106-
var data = e.data;
107-
108-
if (data.jsontype !== this.type) return;
109-
110-
if (!this.builder) return;
111-
112-
if (!this.container) return;
113-
114-
var innerData = data.data;
115-
if (!innerData) return;
116-
117-
var controlId = innerData.control_id;
101+
protected onJSAction(e: FireEvent) {
102+
const innerData = e?.data?.data;
103+
const controlId = innerData?.control_id;
118104

119105
// Panels share the same name for main containers, do not execute actions for them
120106
// if panel has to be shown or hidden, full update will appear
@@ -133,8 +119,9 @@ abstract class SidebarBase {
133119
return;
134120
}
135121

136-
this.builder.executeAction(this.container, innerData);
122+
super.onJSAction(e);
137123
}
124+
138125
markNavigatorTreeView(data: WidgetJSON): boolean {
139126
if (!data) return false;
140127

0 commit comments

Comments
 (0)