@@ -41,6 +41,8 @@ define([
4141 }
4242
4343 this . reload ( ) ;
44+ this . bindAutocomplete ( ) ;
45+ this . bindEvent ( ) ;
4446 }
4547
4648 render ( ) {
@@ -54,9 +56,21 @@ define([
5456 // check disabled
5557 if ( ! $ ( this ) . parent ( ) . find ( 'input' ) . is ( ':disabled' ) ) {
5658 // toggle filter box
57- $ ( that . wrapSelector ( '.vp-vs-filter-box' ) ) . toggle ( ) ;
59+ $ ( that . wrapSelector ( '.vp-vs-filter-box' ) ) . toggleClass ( 'vp-inline-block' ) ;
5860 }
5961 } ) ;
62+
63+ $ ( this . _parentTag ) . on ( 'change' , this . wrapSelector ( '.vp-vs-filter-select-all' ) , function ( ) {
64+ // check all
65+ $ ( that . wrapSelector ( '.vp-vs-filter-type' ) ) . prop ( 'checked' , true ) ;
66+ // reload
67+ that . reload ( ) ;
68+ } ) ;
69+
70+ $ ( this . _parentTag ) . on ( 'change' , this . wrapSelector ( '.vp-vs-filter-type' ) , function ( ) {
71+ // TODO:
72+
73+ } ) ;
6074 }
6175
6276 /**
@@ -145,14 +159,31 @@ define([
145159 dtype : obj . varType
146160 } ;
147161 } ) ;
148- console . log ( varList ) ;
149162
150163 // save variable list as state
151164 that . state . varList = varList ;
152165 that . _suggestList = varList ;
153166
154167 let idx = 0 ; // use to Add variable
155- that . bindAutocomplete ( ) ;
168+ $ ( com_util . formatString ( ".{0} input" , that . uuid ) ) . autocomplete ( 'option' , 'source' , function ( req , res ) {
169+ var srcList = typeof that . _suggestList == "function" ? that . _suggestList ( ) : that . _suggestList ;
170+ var returlList = new Array ( ) ;
171+ if ( that . _normalFilter ) {
172+ for ( var idx = 0 ; idx < srcList . length ; idx ++ ) {
173+ // srcList as object array
174+ if ( typeof srcList [ idx ] == "object" ) {
175+ // { label: string, value: string } format
176+ if ( srcList [ idx ] . label . toString ( ) . toLowerCase ( ) . includes ( req . term . trim ( ) . toLowerCase ( ) ) ) {
177+ returlList . push ( srcList [ idx ] ) ;
178+ }
179+ } else if ( srcList [ idx ] . toString ( ) . toLowerCase ( ) . includes ( req . term . trim ( ) . toLowerCase ( ) ) )
180+ returlList . push ( srcList [ idx ] ) ;
181+ }
182+ } else {
183+ returlList = srcList ;
184+ }
185+ res ( returlList ) ;
186+ } ) ;
156187
157188 } catch ( ex ) {
158189 // console.log(ex);
@@ -169,6 +200,10 @@ define([
169200
170201 $ ( com_util . formatString ( ".{0} .{1}" , that . uuid , 'vp-vs-uninit' ) ) . removeClass ( 'vp-vs-uninit' ) . addClass ( 'vp-vs-init' ) ;
171202
203+ // if ($(com_util.formatString(".{0} input", that.uuid)).data('ui-autocomplete') != undefined) {
204+ // $(com_util.formatString(".{0} input", that.uuid)).autocomplete('destroy');
205+ // $(com_util.formatString(".{0} input", that.uuid)).removeData('autocomplete');
206+ // }
172207 $ ( com_util . formatString ( ".{0} input" , that . uuid ) ) . autocomplete ( {
173208 autoFocus : true ,
174209 minLength : minLength ,
@@ -206,7 +241,6 @@ define([
206241 return true ;
207242 }
208243 } ) . autocomplete ( 'instance' ) . _renderItem = function ( ul , item ) {
209- console . log ( ul , item ) ;
210244 return $ ( '<li>' ) . append ( `<div class="vp-vs-item">${ item . label } <label class="vp-gray-text"> | ${ item . dtype } </label></div>` ) . appendTo ( ul ) ;
211245 } ;
212246
@@ -219,8 +253,6 @@ define([
219253 $ ( com_util . formatString ( ".{0} input" , that . uuid ) ) . autocomplete ( 'search' , $ ( com_util . formatString ( ".{0} input" , that . uuid ) ) . val ( ) ) ;
220254 } ) ;
221255 } ) ;
222-
223- this . bindEvent ( ) ;
224256 }
225257
226258 /**
@@ -241,7 +273,15 @@ define([
241273 sbTagString . appendFormatLine ( '<span class="{0}"><img src="{1}"/></span>' , 'vp-vs-filter vp-close-on-blur-btn' , '/nbextensions/visualpython/img/filter.svg' ) ;
242274 // filter box
243275 sbTagString . appendFormatLine ( '<div class="{0} vp-close-on-blur">' , 'vp-vs-filter-box' ) ;
244-
276+ sbTagString . appendLine ( '<div class="vp-grid-box">' ) ;
277+ sbTagString . appendFormatLine ( '<input type="checkbox" id="{0}" class="{1}" checked><label for="{2}">{3}</label>' ,
278+ this . uuid + '_vsSelectAll' , 'vp-vs-filter-select-all' , this . uuid + '_vsSelectAll' , 'Select All' ) ;
279+ this . _dataTypes && this . _dataTypes . forEach ( dt => {
280+ let tmpId = that . uuid + '_' + dt ;
281+ sbTagString . appendFormatLine ( '<input type="checkbox" id="{0}" class="{1}" data-dtype="{2}" checked><label for="{3}">{4}</label>' ,
282+ tmpId , 'vp-vs-filter-type' , dt , tmpId , dt ) ;
283+ } ) ;
284+ sbTagString . appendLine ( '</div>' ) ; // end of vp-grid-box
245285 sbTagString . appendLine ( '</div>' ) ; // end of vp-vs-filter-box
246286 sbTagString . appendLine ( '</div>' ) ;
247287
0 commit comments