@@ -45,6 +45,13 @@ define([
4545 //========================================================================
4646 // [CLASS] MultiSelector
4747 //========================================================================
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+ */
4855 class MultiSelector extends Component {
4956
5057 /**
@@ -62,19 +69,31 @@ define([
6269 // configuration
6370 this . config = this . state ;
6471
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 ;
6678 this . mode = mode ; // variable / columns / index / ndarray0 / ndarray1 / methods / data(given data)
6779 this . parent = parent ;
6880 this . selectedList = selectedList ;
6981 this . includeList = includeList ;
7082 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=[])
7287
7388 this . dataList = dataList ; // [ { value, code, type }, ... ]
7489 this . pointer = { start : - 1 , end : - 1 } ;
7590
7691 var that = this ;
7792
93+ if ( parent === '' ) {
94+ this . _executeCallback ( [ ] ) ;
95+ return ;
96+ }
7897 switch ( mode ) {
7998 case 'columns' :
8099 this . _getColumnList ( parent , function ( dataList ) {
@@ -238,6 +257,7 @@ define([
238257 $ ( this . frameSelector ) . html ( this . render ( ) ) ;
239258 this . bindEvent ( ) ;
240259 this . bindDraggable ( ) ;
260+ this . _bindItemClickEvent ( ) ;
241261 }
242262
243263 getDataList ( ) {
@@ -260,7 +280,9 @@ define([
260280 var that = this ;
261281
262282 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+ }
264286 tag . appendFormatLine ( '<div class="{0} {1}">' , APP_SELECT_CONTAINER , this . uuid ) ;
265287 // select - left
266288 tag . appendFormatLine ( '<div class="{0}">' , APP_SELECT_LEFT ) ;
@@ -275,6 +297,7 @@ define([
275297 $ ( this . wrapSelector ( ) ) . val ( value ) ;
276298 $ ( this . wrapSelector ( ) ) . trigger ( 'change' ) ;
277299 } ) ;
300+ vpSearchSuggest . setAutoFocus ( false ) ;
278301 vpSearchSuggest . setNormalFilter ( true ) ;
279302 tag . appendLine ( vpSearchSuggest . toTagString ( ) ) ;
280303 tag . appendFormatLine ( '<i class="fa fa-search search-icon"></i>' )
@@ -378,6 +401,7 @@ define([
378401
379402 // draggable
380403 that . bindDraggable ( ) ;
404+ that . _bindItemClickEvent ( ) ;
381405 } ) ;
382406
383407 // item indexing - add all
@@ -388,6 +412,8 @@ define([
388412 $ ( that . wrapSelector ( '.' + APP_SELECT_ITEM ) ) . addClass ( 'added' ) ;
389413 $ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + '.selected' ) ) . removeClass ( 'selected' ) ;
390414 that . pointer = { start : - 1 , end : - 1 } ;
415+
416+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
391417 } ) ;
392418
393419 // item indexing - add
@@ -400,6 +426,8 @@ define([
400426 $ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + selector ) ) . addClass ( 'added' ) ;
401427 $ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + selector ) ) . removeClass ( 'selected' ) ;
402428 that . pointer = { start : - 1 , end : - 1 } ;
429+
430+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
403431 } ) ;
404432
405433 // item indexing - del
@@ -420,6 +448,8 @@ define([
420448 selectedTag . removeClass ( 'added' ) ;
421449 selectedTag . removeClass ( 'selected' ) ;
422450 that . pointer = { start : - 1 , end : - 1 } ;
451+
452+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
423453 } ) ;
424454
425455 // item indexing - delete all
@@ -437,12 +467,16 @@ define([
437467 $ ( that . wrapSelector ( '.' + APP_SELECT_ITEM ) ) . removeClass ( 'added' ) ;
438468 $ ( that . wrapSelector ( '.' + APP_SELECT_ITEM + '.selected' ) ) . removeClass ( 'selected' ) ;
439469 that . pointer = { start : - 1 , end : - 1 } ;
470+
471+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
440472 } ) ;
441473
442474 // add new item
443475 $ ( this . wrapSelector ( '.vp-cs-add-item-btn' ) ) . on ( 'click' , function ( event ) {
444476 let newItemName = $ ( that . wrapSelector ( '.vp-cs-add-item-name' ) ) . val ( ) ;
445477 that . _addNewItem ( newItemName ) ;
478+
479+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
446480 } ) ;
447481 // add new item (by pushing enter key)
448482 $ ( this . wrapSelector ( '.vp-cs-add-item-name' ) ) . on ( 'keyup' , function ( event ) {
@@ -452,6 +486,8 @@ define([
452486 if ( keycode == 13 ) { // enter
453487 let newItemName = $ ( this ) . val ( ) ;
454488 that . _addNewItem ( newItemName ) ;
489+
490+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
455491 }
456492 } ) ;
457493
@@ -522,6 +558,8 @@ define([
522558 $ ( this . wrapSelector ( '.vp-cs-del-item' ) ) . on ( 'click' , function ( event ) {
523559 $ ( this ) . closest ( '.' + APP_SELECT_ITEM ) . remove ( ) ;
524560 that . pointer = { start : - 1 , end : - 1 } ;
561+
562+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
525563 } ) ;
526564 }
527565
@@ -629,13 +667,15 @@ define([
629667 if ( $ ( this ) . hasClass ( 'right' ) ) {
630668 // add
631669 $ ( dropGroup ) . addClass ( 'added' ) ;
670+ that . change && that . change ( 'add' , that . getDataList ( ) ) ;
632671 } else {
633672 // del
634673 $ ( dropGroup ) . removeClass ( 'added' ) ;
635674 // sort
636675 $ ( droppedOn ) . find ( '.' + APP_SELECT_ITEM ) . sort ( function ( a , b ) {
637676 return ( $ ( b ) . data ( 'idx' ) ) < ( $ ( a ) . data ( 'idx' ) ) ? 1 : - 1 ;
638677 } ) . appendTo ( $ ( droppedOn ) ) ;
678+ that . change && that . change ( 'remove' , that . getDataList ( ) ) ;
639679 }
640680 // remove selection
641681 $ ( droppableQuery ) . find ( '.selected' ) . removeClass ( 'selected' ) ;
0 commit comments