14
14
import * as Utils from '../utils.js' ;
15
15
import crudToolbarHTML from './crudToolbar.html' ;
16
16
17
+ const CLASS_BG = 'editBackground'
18
+ const CLASS_FG = 'editForground' ;
19
+ const CLASS_FG_FULLSCREEN = 'editForgroundBig' ;
20
+
21
+ let ICON_CLASS_FS = 'bi-arrows-fullscreen' ;
22
+ let ICON_CLASS_FS_EXIT = 'bi-fullscreen-exit' ;
23
+
24
+ const ATTR_FULLSCREEN = 'fullscreen' ;
25
+
17
26
export enum CrudOperation {
18
27
CREATE ,
19
28
UPDATE ,
@@ -33,38 +42,14 @@ export class CrudToolbar extends HTMLElement {
33
42
buttonUpdate : null ,
34
43
buttonDelete : null ,
35
44
buttonCancel : null ,
45
+ buttonFullscreen : null ,
36
46
divRoot : null ,
37
47
} ;
38
48
39
- static get observedAttributes ( ) {
40
- return [ `extraeditclass` ] ;
41
- }
42
-
43
- private _extraEditClass : string ;
44
-
45
- get extraeditclass ( ) {
46
- return this . _extraEditClass ;
47
- }
48
-
49
- set extraeditclass ( val : string ) {
50
- if ( val == null ) { // check for null and undefined
51
- this . removeAttribute ( 'extraeditclass' ) ;
52
- }
53
- else {
54
- this . setAttribute ( 'extraeditclass' , val ) ;
55
- }
56
- }
57
-
58
49
get idValue ( ) {
59
50
return this . dom . inputIdValue . value ;
60
51
}
61
52
62
- attributeChangedCallback ( name , oldValue , newValue ) {
63
- if ( name === `extraeditclass` ) {
64
- this . _extraEditClass = newValue ;
65
- }
66
- }
67
-
68
53
set idValue ( newValue ) {
69
54
const domInput : HTMLInputElement = this . shadowRoot . getElementById ( 'inputIdValue' ) as HTMLInputElement ;
70
55
domInput . value = newValue ;
@@ -91,23 +76,32 @@ export class CrudToolbar extends HTMLElement {
91
76
92
77
set createDisabled ( newValue : boolean ) {
93
78
this . isCreateDisabled = newValue ;
94
- this . setButtonState ( 'buttonCreate' , newValue ) ;
79
+ this . lazyInit ( this . dom . buttonCreate ) ;
80
+ this . setButtonState ( this . dom . buttonCreate , newValue ) ;
95
81
}
96
82
97
83
set deleteDisabled ( newValue : boolean ) {
98
84
this . isDeleteDisabled = newValue ;
99
- this . setButtonState ( 'buttonDelete' , newValue ) ;
85
+ this . lazyInit ( this . dom . buttonDelete ) ;
86
+ this . setButtonState ( this . dom . buttonDelete , newValue ) ;
100
87
}
101
88
102
89
set editDisabled ( newValue : boolean ) {
103
90
this . isEditDisabled = newValue ;
104
91
if ( ! this . isEditing ) {
105
- this . setButtonState ( 'buttonEdit' , newValue ) ;
92
+ this . lazyInit ( this . dom . buttonEdit ) ;
93
+ this . setButtonState ( this . dom . buttonEdit , newValue ) ;
106
94
}
107
95
}
108
96
109
- setButtonState ( buttonId , isDisabled ) {
110
- const button = this . shadowRoot . getElementById ( buttonId ) ;
97
+ lazyInit ( element : HTMLElement ) {
98
+ if ( ! element ) {
99
+ Utils . getAllElementsById ( this . dom , this . shadowRoot ) ;
100
+ }
101
+ }
102
+
103
+ setButtonState ( button : HTMLButtonElement , isDisabled : boolean ) {
104
+ // const button = this.shadowRoot.getElementById(buttonId);
111
105
112
106
if ( isDisabled ) {
113
107
button . setAttribute ( 'hidden' , '' ) ;
@@ -136,6 +130,7 @@ export class CrudToolbar extends HTMLElement {
136
130
this . dom . buttonCreate . onclick = this . eventDispatcher ( 'onCreateClick' ) ;
137
131
this . dom . buttonUpdate . onclick = this . eventDispatcher ( 'onUpdateClick' ) ;
138
132
this . dom . buttonDelete . onclick = this . eventDispatcher ( 'onDeleteClick' ) ;
133
+ this . dom . buttonFullscreen . onclick = ( ) => this . toggleFullscreen ( ) ;
139
134
this . dom . inputIdValue . addEventListener ( 'change' , ( event ) => {
140
135
( event . target as HTMLElement ) . classList . remove ( 'is-invalid' ) ;
141
136
this . dispatchEvent ( new CustomEvent ( 'onIdValueChange' , { composed : true } ) ) ;
@@ -153,17 +148,16 @@ export class CrudToolbar extends HTMLElement {
153
148
154
149
toggleEdit ( isCancel ) {
155
150
this . isEditing = ! this . isEditing ;
156
- document . getElementById ( 'modalCrudEdit' ) . classList . toggle ( 'editBackground' ) ;
157
- this . dom . divRoot . classList . toggle ( 'editForground' ) ;
158
- if ( this . _extraEditClass ) {
159
- this . dom . divRoot . classList . toggle ( this . _extraEditClass ) ;
160
- }
161
-
162
- if ( this . isEditing || this . isEditDisabled ) {
163
- this . dom . buttonEdit . setAttribute ( 'hidden' , '' ) ;
164
- } else {
165
- this . dom . buttonEdit . removeAttribute ( 'hidden' ) ;
166
- }
151
+
152
+ // toggle modal mode;
153
+ document . getElementById ( 'modalCrudEdit' ) . classList . toggle ( CLASS_BG ) ;
154
+ document . body . classList . toggle ( 'modal-open' ) ;
155
+ document . body . style . overflow = this . isEditing && this . hasAttribute ( ATTR_FULLSCREEN ) ? 'hidden' : '' ;
156
+ this . dom . divRoot . classList . toggle ( this . hasAttribute ( ATTR_FULLSCREEN ) ? CLASS_FG_FULLSCREEN : CLASS_FG ) ;
157
+
158
+ // toggle button states;
159
+ this . setButtonState ( this . dom . buttonEdit , this . isEditing || this . isEditDisabled ) ;
160
+ this . setButtonState ( this . dom . buttonFullscreen , ! this . isEditing ) ;
167
161
this . dom . buttonCancel . toggleAttribute ( 'hidden' ) ;
168
162
169
163
if ( this . isEditing ) {
@@ -179,8 +173,11 @@ export class CrudToolbar extends HTMLElement {
179
173
if ( this . isEditing || ! this . dom . inputIdValue . value ) {
180
174
this . dom . buttonDelete . setAttribute ( 'hidden' , '' ) ;
181
175
}
176
+
177
+
182
178
const allowIdChange = this . isEditing && ( ! this . dom . inputIdValue . value || this . hasAttribute ( 'allowIdChange' ) ) ;
183
179
this . dom . inputIdValue . disabled = ! allowIdChange ;
180
+
184
181
this . dispatchEvent ( new CustomEvent ( 'onEditToggle' , {
185
182
composed : true ,
186
183
detail : {
@@ -189,6 +186,18 @@ export class CrudToolbar extends HTMLElement {
189
186
} ,
190
187
} ) ) ;
191
188
}
189
+
190
+ toggleFullscreen ( ) {
191
+ this . toggleAttribute ( ATTR_FULLSCREEN ) ;
192
+ this . dom . buttonFullscreen . querySelector ( '.bi' ) . classList . toggle ( ICON_CLASS_FS ) ;
193
+ this . dom . buttonFullscreen . querySelector ( '.bi' ) . classList . toggle ( ICON_CLASS_FS_EXIT ) ;
194
+ document . body . style . overflow = this . isEditing && this . hasAttribute ( ATTR_FULLSCREEN ) ? 'hidden' : '' ;
195
+ if ( this . dom . divRoot . classList . contains ( CLASS_FG ) ) {
196
+ this . dom . divRoot . classList . replace ( CLASS_FG , CLASS_FG_FULLSCREEN ) ;
197
+ } else {
198
+ this . dom . divRoot . classList . replace ( CLASS_FG_FULLSCREEN , CLASS_FG ) ;
199
+ }
200
+ }
192
201
}
193
202
194
203
customElements . define ( 'crud-toolbar' , CrudToolbar ) ;
0 commit comments