@@ -21,34 +21,30 @@ enum SidebarType {
21
21
Navigator = 'navigator' ,
22
22
QuickFind = 'quickfind' ,
23
23
}
24
- abstract class SidebarBase {
24
+ abstract class SidebarBase extends JSDialogComponent {
25
25
type : SidebarType ;
26
26
27
- map : any ;
28
-
29
- container : HTMLDivElement ;
30
27
documentContainer : HTMLDivElement ;
31
28
wrapper : HTMLElement ;
32
- builder : JSBuilder ;
33
29
34
30
constructor ( map : any , type : SidebarType ) {
31
+ super ( map , 'Sidebar' , type ) ;
35
32
this . type = type ;
36
33
this . onAdd ( map ) ;
37
34
}
38
35
39
- onAdd ( map : any ) {
40
- this . map = map ;
41
-
42
- app . events . on ( 'resize' , this . onResize . bind ( this ) ) ;
43
-
36
+ protected createBuilder ( ) {
44
37
this . builder = new window . L . control . jsDialogBuilder ( {
45
38
mobileWizard : this ,
46
- map : map ,
39
+ map : this . map ,
47
40
cssClass : `jsdialog sidebar` , // use sidebar css for now, maybe have seperate css for navigator later
48
41
useScrollAnimation : false , // icon views cause jump on sidebar open
49
42
suffix : 'sidebar' ,
50
43
callback : this . callback . bind ( this ) ,
51
44
} ) ;
45
+ }
46
+
47
+ protected setupContainer ( parentContainer ?: HTMLElement ) {
52
48
if ( ! this . container ) {
53
49
this . container = window . L . DomUtil . createWithId (
54
50
'div' ,
@@ -58,14 +54,20 @@ abstract class SidebarBase {
58
54
}
59
55
this . wrapper = document . getElementById ( `${ this . type } -dock-wrapper` ) ;
60
56
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 ) ) ;
61
65
62
- this . map . on ( 'jsdialogupdate' , this . onJSUpdate , this ) ;
63
- this . map . on ( 'jsdialogaction' , this . onJSAction , this ) ;
66
+ this . registerMessageHandlers ( ) ;
64
67
}
65
68
66
69
onRemove ( ) {
67
- this . map . off ( 'jsdialogupdate' , this . onJSUpdate , this ) ;
68
- this . map . off ( 'jsdialogaction' , this . onJSAction , this ) ;
70
+ this . unregisterMessageHandlers ( ) ;
69
71
}
70
72
71
73
isVisible ( ) : boolean {
@@ -84,37 +86,21 @@ abstract class SidebarBase {
84
86
this . map . uiManager . setDocTypePref ( 'Show' + upperCaseType , false ) ;
85
87
}
86
88
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 ) {
96
90
// 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
+ ) ;
99
95
return ;
100
96
}
101
97
102
- this . builder . updateWidget ( this . container , data . control ) ;
98
+ super . onJSUpdate ( e ) ;
103
99
}
104
100
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 ;
118
104
119
105
// Panels share the same name for main containers, do not execute actions for them
120
106
// if panel has to be shown or hidden, full update will appear
@@ -133,8 +119,9 @@ abstract class SidebarBase {
133
119
return ;
134
120
}
135
121
136
- this . builder . executeAction ( this . container , innerData ) ;
122
+ super . onJSAction ( e ) ;
137
123
}
124
+
138
125
markNavigatorTreeView ( data : WidgetJSON ) : boolean {
139
126
if ( ! data ) return false ;
140
127
0 commit comments