@@ -23,47 +23,112 @@ define([
23
23
class DataSelector extends Component {
24
24
25
25
/**
26
- *
27
- * @param {string } frameSelector query for parent component
28
- * @param {Object } config parent:[], selectedList=[], includeList=[]
26
+ * Constructor
27
+ * @param {Object } state { type, ... }
29
28
*/
30
- constructor ( frameSelector , config ) {
31
- super ( frameSelector , config , { } ) ;
29
+ constructor ( state ) {
30
+ super ( $ ( '#site' ) , state ) ;
32
31
}
33
32
34
33
_init ( ) {
35
- this . frameSelector = this . $target ;
34
+ super . _init ( ) ;
36
35
37
- // configuration
38
- this . config = this . state ;
36
+ this . state = {
37
+ type : 'data' , // selector type : data / column
38
+ target : null , // target jquery object
39
+ finish : null , // callback after selection
40
+ data : '' ,
41
+ dataType : '' ,
42
+ ...this . state
43
+ }
39
44
40
- var { mode, type, parent, selectedList= [ ] , includeList= [ ] , excludeList= [ ] } = this . config ;
41
- this . mode = mode ;
42
- this . parent = parent ;
43
- this . selectedList = selectedList ;
44
- this . includeList = includeList ;
45
- this . excludeList = excludeList ;
45
+ }
46
+
47
+ _bindEvent ( ) {
48
+ let that = this ;
49
+
50
+ // Click X to close
51
+ $ ( that . wrapSelector ( '.vp-inner-popup-close' ) ) . on ( 'click' , function ( ) {
52
+ that . close ( ) ;
53
+ } ) ;
54
+
55
+ // Click ok
56
+ $ ( that . wrapSelector ( '#vp_dsOk' ) ) . on ( 'click' , function ( ) {
57
+ // TODO: set target value
58
+ let newValue = that . state . data ;
59
+
60
+ $ ( that . state . target ) . val ( newValue ) ;
61
+ $ ( that . state . target ) . data ( 'type' , that . state . dataType ) ;
62
+ that . state . finish ( newValue ) ;
63
+ that . close ( ) ;
64
+ } ) ;
65
+
66
+ }
67
+
68
+ /**
69
+ * Bind event for items created dynamically
70
+ */
71
+ _bindEventForItem ( ) {
72
+ let that = this ;
46
73
74
+ // Click variable item
75
+ $ ( that . wrapSelector ( '.vp-ds-var-item' ) ) . off ( 'click' ) ;
76
+ $ ( that . wrapSelector ( '.vp-ds-var-item' ) ) . on ( 'click' , function ( ) {
77
+ $ ( that . wrapSelector ( '.vp-ds-var-item' ) ) . removeClass ( 'selected' ) ;
78
+ $ ( this ) . addClass ( 'selected' ) ;
47
79
80
+ let data = $ ( this ) . find ( '.vp-ds-var-data' ) . text ( ) ;
81
+ let dataType = $ ( this ) . find ( '.vp-ds-var-type' ) . text ( ) ;
82
+ that . state . data = data ;
83
+ that . state . dataType = dataType ;
84
+
85
+ // TODO: load preview
86
+ } ) ;
48
87
}
49
88
50
- load ( ) {
51
- $ ( this . frameSelector ) . html ( this . render ( ) ) ;
52
- this . bindEvent ( ) ;
89
+ loadVariables ( ) {
90
+ let that = this ;
91
+ // Searchable variable types
92
+ let types = [
93
+ ...vpConfig . getDataTypes ( ) ,
94
+ // ML Data types
95
+ ...vpConfig . getMLDataTypes ( )
96
+ ] ;
97
+
98
+ vpKernel . getDataList ( types ) . then ( function ( resultObj ) {
99
+ var varList = JSON . parse ( resultObj . result ) ;
100
+
101
+ let varTags = new com_String ( ) ;
102
+ varList && varList . forEach ( ( varObj , idx ) => {
103
+ varTags . appendFormatLine ( '<div class="{0} {1}">' , 'vp-ds-var-item' , 'vp-grid-col-p50' ) ;
104
+ varTags . appendFormatLine ( '<div class="{0}">{1}</div>' , 'vp-ds-var-data' , varObj . varName ) ;
105
+ varTags . appendFormatLine ( '<div class="{0}">{1}</div>' , 'vp-ds-var-type' , varObj . varType ) ;
106
+ varTags . appendLine ( '</div>' ) ;
107
+ } ) ;
108
+
109
+ $ ( that . wrapSelector ( '.vp-ds-variable-box' ) ) . html ( varTags . toString ( ) ) ;
110
+
111
+ that . _bindEventForItem ( ) ;
112
+
113
+ } ) ;
53
114
}
54
115
55
116
template ( ) {
56
117
return dataHTML ;
57
118
}
58
119
59
120
render ( ) {
60
-
61
- }
121
+ super . render ( ) ;
62
122
63
- bindEvent ( ) {
64
- let that = this ;
123
+ this . loadVariables ( ) ;
124
+ }
65
125
126
+ open ( ) {
127
+ $ ( this . wrapSelector ( ) ) . show ( ) ;
128
+ }
66
129
130
+ close ( ) {
131
+ $ ( this . wrapSelector ( ) ) . remove ( ) ;
67
132
}
68
133
}
69
134
0 commit comments