@@ -45,6 +45,13 @@ define([
45
45
//========================================================================
46
46
// [CLASS] MultiSelector
47
47
//========================================================================
48
+ /**
49
+ * MultiSelector
50
+ * Usage
51
+ * this._columnSelector = new MultiSelector(this.wrapSelector('#multi-selector-id'),
52
+ { mode: 'columns', parent: [data], selectedList: this.state.indexing, allowAdd: true }
53
+ );
54
+ */
48
55
class MultiSelector extends Component {
49
56
50
57
/**
@@ -62,19 +69,31 @@ define([
62
69
// configuration
63
70
this . config = this . state ;
64
71
65
- var { mode, type, parent, dataList= [ ] , selectedList= [ ] , includeList= [ ] , excludeList= [ ] , allowAdd= false } = this . config ;
72
+ var {
73
+ mode, type, parent,
74
+ dataList= [ ] , selectedList= [ ] , includeList= [ ] , excludeList= [ ] ,
75
+ allowAdd= false , showDescription= true ,
76
+ change= null
77
+ } = this . config ;
66
78
this . mode = mode ; // variable / columns / index / ndarray0 / ndarray1 / methods / data(given data)
67
79
this . parent = parent ;
68
80
this . selectedList = selectedList ;
69
81
this . includeList = includeList ;
70
82
this . excludeList = excludeList ;
71
- this . allowAdd = allowAdd ;
83
+ this . allowAdd = allowAdd ; // allow adding new item
84
+ this . showDescription = showDescription ; // show description on the top of the box
85
+
86
+ this . change = change ; // function (type=('add'|'remove'), list=[])
72
87
73
88
this . dataList = dataList ; // [ { value, code, type }, ... ]
74
89
this . pointer = { start : - 1 , end : - 1 } ;
75
90
76
91
var that = this ;
77
92
93
+ if ( parent === '' ) {
94
+ this . _executeCallback ( [ ] ) ;
95
+ return ;
96
+ }
78
97
switch ( mode ) {
79
98
case 'columns' :
80
99
this . _getColumnList ( parent , function ( dataList ) {
@@ -238,6 +257,7 @@ define([
238
257
$ ( this . frameSelector ) . html ( this . render ( ) ) ;
239
258
this . bindEvent ( ) ;
240
259
this . bindDraggable ( ) ;
260
+ this . _bindItemClickEvent ( ) ;
241
261
}
242
262
243
263
getDataList ( ) {
@@ -260,7 +280,9 @@ define([
260
280
var that = this ;
261
281
262
282
var tag = new com_String ( ) ;
263
- tag . appendLine ( '<label>Drag-and-drop columns to right to select.</label>' ) ;
283
+ if ( this . showDescription === true ) {
284
+ tag . appendLine ( '<label>Drag-and-drop columns to right to select.</label>' ) ;
285
+ }
264
286
tag . appendFormatLine ( '<div class="{0} {1}">' , APP_SELECT_CONTAINER , this . uuid ) ;
265
287
// select - left
266
288
tag . appendFormatLine ( '<div class="{0}">' , APP_SELECT_LEFT ) ;
@@ -275,6 +297,7 @@ define([
275
297
$ ( this . wrapSelector ( ) ) . val ( value ) ;
276
298
$ ( this . wrapSelector ( ) ) . trigger ( 'change' ) ;
277
299
} ) ;
300
+ vpSearchSuggest . setAutoFocus ( false ) ;
278
301
vpSearchSuggest . setNormalFilter ( true ) ;
279
302
tag . appendLine ( vpSearchSuggest . toTagString ( ) ) ;
280
303
tag . appendFormatLine ( '<i class="fa fa-search search-icon"></i>' )
@@ -378,6 +401,7 @@ define([
378
401
379
402
// draggable
380
403
that . bindDraggable ( ) ;
404
+ that . _bindItemClickEvent ( ) ;
381
405
} ) ;
382
406
383
407
// item indexing - add all
@@ -388,6 +412,8 @@ define([
388
412
$ ( that . wrapSelector ( '.' + APP_SELECT_ITEM ) ) . addClass ( 'added' ) ;
389
413
$ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + '.selected' ) ) . removeClass ( 'selected' ) ;
390
414
that . pointer = { start : - 1 , end : - 1 } ;
415
+
416
+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
391
417
} ) ;
392
418
393
419
// item indexing - add
@@ -400,6 +426,8 @@ define([
400
426
$ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + selector ) ) . addClass ( 'added' ) ;
401
427
$ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + selector ) ) . removeClass ( 'selected' ) ;
402
428
that . pointer = { start : - 1 , end : - 1 } ;
429
+
430
+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
403
431
} ) ;
404
432
405
433
// item indexing - del
@@ -420,6 +448,8 @@ define([
420
448
selectedTag . removeClass ( 'added' ) ;
421
449
selectedTag . removeClass ( 'selected' ) ;
422
450
that . pointer = { start : - 1 , end : - 1 } ;
451
+
452
+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
423
453
} ) ;
424
454
425
455
// item indexing - delete all
@@ -437,12 +467,16 @@ define([
437
467
$ ( that . wrapSelector ( '.' + APP_SELECT_ITEM ) ) . removeClass ( 'added' ) ;
438
468
$ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + '.selected' ) ) . removeClass ( 'selected' ) ;
439
469
that . pointer = { start : - 1 , end : - 1 } ;
470
+
471
+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
440
472
} ) ;
441
473
442
474
// add new item
443
475
$ ( this . wrapSelector ( '.vp-cs-add-item-btn' ) ) . on ( 'click' , function ( event ) {
444
476
let newItemName = $ ( that . wrapSelector ( '.vp-cs-add-item-name' ) ) . val ( ) ;
445
477
that . _addNewItem ( newItemName ) ;
478
+
479
+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
446
480
} ) ;
447
481
// add new item (by pushing enter key)
448
482
$ ( this . wrapSelector ( '.vp-cs-add-item-name' ) ) . on ( 'keyup' , function ( event ) {
@@ -452,6 +486,8 @@ define([
452
486
if ( keycode == 13 ) { // enter
453
487
let newItemName = $ ( this ) . val ( ) ;
454
488
that . _addNewItem ( newItemName ) ;
489
+
490
+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
455
491
}
456
492
} ) ;
457
493
@@ -522,6 +558,8 @@ define([
522
558
$ ( this . wrapSelector ( '.vp-cs-del-item' ) ) . on ( 'click' , function ( event ) {
523
559
$ ( this ) . closest ( '.' + APP_SELECT_ITEM ) . remove ( ) ;
524
560
that . pointer = { start : - 1 , end : - 1 } ;
561
+
562
+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
525
563
} ) ;
526
564
}
527
565
@@ -629,13 +667,15 @@ define([
629
667
if ( $ ( this ) . hasClass ( 'right' ) ) {
630
668
// add
631
669
$ ( dropGroup ) . addClass ( 'added' ) ;
670
+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
632
671
} else {
633
672
// del
634
673
$ ( dropGroup ) . removeClass ( 'added' ) ;
635
674
// sort
636
675
$ ( droppedOn ) . find ( '.' + APP_SELECT_ITEM ) . sort ( function ( a , b ) {
637
676
return ( $ ( b ) . data ( 'idx' ) ) < ( $ ( a ) . data ( 'idx' ) ) ? 1 : - 1 ;
638
677
} ) . appendTo ( $ ( droppedOn ) ) ;
678
+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
639
679
}
640
680
// remove selection
641
681
$ ( droppableQuery ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
0 commit comments