@@ -202,9 +202,6 @@ class ComponentCascadeDot {
202
202
constructor ( name , selected , select , options ) {
203
203
this . name = name ;
204
204
this . DOM = document . getElementById ( name ) ;
205
- this . OPTIONS = Object . assign ( {
206
- select_dimensional : [ ]
207
- } , options ) ;
208
205
if ( ! Array . isArray ( selected ) ) {
209
206
console . error ( 'CascadeDot param selected is not array!' ) ;
210
207
return ;
@@ -237,30 +234,31 @@ class ComponentCascadeDot {
237
234
let data = this . dimensional_data [ stack ] ;
238
235
let stackDom = document . createElement ( 'div' ) ;
239
236
stackDom . className = 'dot-cascade-stack dlp-scroll' ;
240
- var allowSelect = true ;
241
- if ( this . OPTIONS . select_dimensional . length > 0 && ( this . OPTIONS . select_dimensional . indexOf ( stack ) == - 1 ) ) {
242
- allowSelect = false ;
243
- }
244
237
data . forEach ( ( v ) => {
245
238
let div = document . createElement ( 'div' ) ;
246
239
div . className = 'dlp dlp-text dlp-label' ;
240
+ div . textContent = v . val ;
247
241
div . setAttribute ( 'data-id' , v . key ) ;
248
- div . setAttribute ( 'allow-select' , allowSelect ) ;
249
242
div . setAttribute ( 'checked' , 'false' ) ;
250
- div . textContent = v . val ;
243
+ div . setAttribute ( 'data-parent-nodes-id' , JSON . stringify ( v . parentNodes ) ) ;
244
+ let allow_select = false ;
251
245
if ( v . hasOwnProperty ( 'nodes' ) ) {
252
246
let nodes = v . nodes . map ( ( n ) => n . key ) ;
253
247
div . setAttribute ( 'data-nodes-id' , JSON . stringify ( nodes ) ) ;
248
+ } else {
249
+ allow_select = true ;
254
250
}
255
- div . setAttribute ( 'data-parent-nodes-id' , JSON . stringify ( v . parentNodes ) ) ;
256
251
div . addEventListener ( 'click' , this . select . bind ( this , div , stack ) ) ;
257
252
stackDom . append ( div ) ;
258
253
/*selected append*/
259
254
let index = this . selected_data . indexOf ( parseInt ( v . key ) ) ;
260
- if ( ( index !== - 1 ) && allowSelect == false ) {
261
- this . selected_data . splice ( index , 1 ) ;
255
+ if ( allow_select == false && index !== - 1 ) {
256
+ this . selected_data . splice ( index , 1 ) ;
262
257
this . select_data = this . selected_data . slice ( 0 ) ;
263
- } else if ( ( index !== - 1 ) && allowSelect == true ) {
258
+ return ;
259
+ }
260
+ if ( index !== - 1 ) {
261
+ div . setAttribute ( 'checked' , 'true' ) ;
264
262
this . selectToSelected ( div , stack ) ;
265
263
div . insertAdjacentHTML ( 'beforeend' , `<i>${ _componentSvg . check } </i>` ) ;
266
264
/*parent nodes*/
@@ -307,29 +305,41 @@ class ComponentCascadeDot {
307
305
}
308
306
309
307
select ( element , stack ) {
310
- /*nodes*/
311
- let nodes = JSON . parse ( element . getAttribute ( 'data-nodes-id' ) ) ;
312
- this . selectToChildren ( stack + 1 , nodes ) ;
313
- /*current stack*/
314
308
let checked = element . getAttribute ( 'checked' ) ;
315
- if ( checked == ' false' ) {
316
- this . selectActive ( stack , element ) ;
317
- } else {
318
- this . selectInactive ( stack , element ) ;
309
+ let end_node = false ;
310
+ let nodes = JSON . parse ( element . getAttribute ( 'data-nodes-id' ) ) ;
311
+ if ( ! Array . isArray ( nodes ) || ( nodes . length == 0 ) ) {
312
+ end_node = true ;
319
313
}
320
- /*parent nodes*/
321
314
let parent_nodes = JSON . parse ( element . getAttribute ( 'data-parent-nodes-id' ) ) ;
315
+ if ( checked == 'false' ) {
316
+ /*nodes*/
317
+ this . selectToChildren ( stack + 1 , nodes , end_node ) ;
318
+ /*current stack*/
319
+ this . selectActive ( stack , element , end_node ) ;
320
+ /*parent nodes*/
321
+ if ( Array . isArray ( parent_nodes ) ) {
322
+ for ( let stack in parent_nodes ) {
323
+ this . selectToParent ( checked , parent_nodes [ stack ] , parseInt ( stack ) , parent_nodes [ stack - 1 ] , parent_nodes [ stack + 1 ] ) ;
324
+ }
325
+ }
326
+ return ;
327
+ }
328
+ /*current stack*/
329
+ this . selectInactive ( stack , element ) ;
330
+ /*parent nodes*/
322
331
if ( Array . isArray ( parent_nodes ) ) {
323
332
for ( let stack in parent_nodes ) {
324
333
this . selectToParent ( checked , parent_nodes [ stack ] , parseInt ( stack ) , parent_nodes [ stack - 1 ] , parent_nodes [ stack + 1 ] ) ;
325
334
}
326
335
}
327
336
}
328
337
329
- selectActive ( stack , element ) {
338
+ selectActive ( stack , element , end_node ) {
330
339
if ( element . getAttribute ( 'allow-select' ) == 'false' ) return ;
331
340
if ( element . getAttribute ( 'checked' ) == 'true' ) return ;
332
- this . selectToSelected ( element , stack ) ;
341
+ element . setAttribute ( 'checked' , 'true' ) ;
342
+ ! end_node && this . selectToSelected ( element , stack ) ;
333
343
this . tagCal ( parseInt ( element . getAttribute ( 'data-id' ) ) , this . MODE . insert ) ;
334
344
let currentStackDocuments = this . STACKS [ stack ] . childNodes ;
335
345
let parentNode = JSON . parse ( element . getAttribute ( 'data-parent-nodes-id' ) ) . pop ( ) ;
@@ -340,8 +350,10 @@ class ComponentCascadeDot {
340
350
currentStackDocuments [ index ] . classList . add ( 'dlp-label-silence' ) ;
341
351
}
342
352
} ) ;
343
- element . querySelector ( 'i' ) && element . removeChild ( element . querySelector ( 'i' ) ) ;
344
- element . insertAdjacentHTML ( 'beforeend' , `<i>${ _componentSvg . check } </i>` ) ;
353
+ element . querySelector ( 'i' ) != null && element . removeChild ( element . querySelector ( 'i' ) ) ;
354
+ if ( end_node ) {
355
+ element . insertAdjacentHTML ( 'beforeend' , `<i>${ _componentSvg . check } </i>` ) ;
356
+ }
345
357
}
346
358
347
359
selectInactive ( stack , element ) {
@@ -362,7 +374,6 @@ class ComponentCascadeDot {
362
374
}
363
375
364
376
selectToSelected ( element , stack ) {
365
- element . setAttribute ( 'checked' , 'true' ) ;
366
377
let div = document . createElement ( 'div' ) ;
367
378
div . className = 'dlp dlp-text dlp-label' ;
368
379
let id = element . getAttribute ( 'data-id' ) ;
@@ -404,27 +415,15 @@ class ComponentCascadeDot {
404
415
} ) ;
405
416
}
406
417
407
- selectToChildren ( stack , nodes ) {
418
+ selectToChildren ( stack , nodes , end_node ) {
408
419
if ( stack > ( this . dimensional_data . length - 1 ) ) return ;
409
420
let currentStackDocuments = this . STACKS [ stack ] . childNodes ;
410
421
let children = [ ] ;
411
- if ( ! Array . isArray ( nodes ) || ( nodes . length == 0 ) ) {
412
- currentStackDocuments . forEach ( ( D ) => {
413
- D . classList . add ( 'dlp-label-silence' ) ;
414
- let child = JSON . parse ( D . getAttribute ( 'data-nodes-id' ) ) ;
415
- if ( Array . isArray ( child ) ) {
416
- child . forEach ( ( c ) => {
417
- if ( children . indexOf ( child ) == - 1 ) {
418
- children . push ( c ) ;
419
- }
420
- } ) ;
421
- }
422
- } ) ;
423
- this . selectToChildren ( stack + 1 , nodes ) ;
424
- return ;
425
- }
426
-
427
422
currentStackDocuments . forEach ( ( D ) => {
423
+ if ( end_node ) {
424
+ D . classList . add ( 'dlp-label-silence' ) ;
425
+ return ;
426
+ }
428
427
if ( nodes . indexOf ( parseInt ( D . getAttribute ( 'data-id' ) ) ) != - 1 ) {
429
428
D . classList . remove ( 'dlp-label-silence' ) ;
430
429
let child = JSON . parse ( D . getAttribute ( 'data-nodes-id' ) ) ;
0 commit comments