1
1
/*
2
2
* Project Name : Visual Python
3
3
* Description : GUI-based Python code generator
4
- * File Name : If .js
4
+ * File Name : Elif .js
5
5
* Author : Black Logic
6
- * Note : Logic > if
6
+ * Note : Logic > elif
7
7
* License : GNU GPLv3 with Visual Python special exception
8
8
* Date : 2021. 11. 18
9
9
* Change Date :
10
10
*/
11
11
12
12
//============================================================================
13
- // [CLASS] If
13
+ // [CLASS] Elif
14
14
//============================================================================
15
15
define ( [
16
16
'vp_base/js/com/com_String' ,
@@ -20,9 +20,9 @@ define([
20
20
] , function ( com_String , com_util , PopupComponent , SuggestInput ) {
21
21
22
22
/**
23
- * If
23
+ * Elif
24
24
*/
25
- class If extends PopupComponent {
25
+ class Elif extends PopupComponent {
26
26
_init ( ) {
27
27
super . _init ( ) ;
28
28
/** Write codes executed before rendering */
@@ -31,7 +31,7 @@ define([
31
31
this . config . saveOnly = true ;
32
32
33
33
this . state = {
34
- v1 : [ ] ,
34
+ v1 : [ { type : 'condition' , value : { } } ] ,
35
35
...this . state
36
36
}
37
37
}
@@ -43,11 +43,23 @@ define([
43
43
// Add param
44
44
$ ( this . wrapSelector ( '#vp_addCondition' ) ) . on ( 'click' , function ( ) {
45
45
that . state . v1 . push ( { type : 'condition' , value : { } } ) ;
46
- $ ( that . wrapSelector ( '.v1 tbody' ) ) . append ( that . templateForList ( that . state . v1 . length , { } ) ) ;
46
+ $ ( that . wrapSelector ( '.v1-table' ) ) . append ( that . templateForList ( that . state . v1 . length , { } ) ) ;
47
+
48
+ // enable and disable last one
49
+ // enable all operator
50
+ $ ( that . wrapSelector ( '.v1 .v1-i4' ) ) . prop ( 'disabled' , false ) ;
51
+ // disable last operator
52
+ $ ( that . wrapSelector ( '.v1 tr:last .v1-i4' ) ) . prop ( 'disabled' , true ) ;
47
53
} ) ;
48
54
$ ( this . wrapSelector ( '#vp_addUserInput' ) ) . on ( 'click' , function ( ) {
49
55
that . state . v1 . push ( { type : 'input' , value : { } } ) ;
50
- $ ( that . wrapSelector ( '.v1 tbody' ) ) . append ( that . templateForInput ( that . state . v1 . length , { } ) ) ;
56
+ $ ( that . wrapSelector ( '.v1-table' ) ) . append ( that . templateForInput ( that . state . v1 . length , { } ) ) ;
57
+
58
+ // enable and disable last one
59
+ // enable all operator
60
+ $ ( that . wrapSelector ( '.v1 .v1-i4' ) ) . prop ( 'disabled' , false ) ;
61
+ // disable last operator
62
+ $ ( that . wrapSelector ( '.v1 tr:last .v1-i4' ) ) . prop ( 'disabled' , true ) ;
51
63
} ) ;
52
64
53
65
// Delete param
@@ -61,6 +73,9 @@ define([
61
73
$ ( that . wrapSelector ( '.v1-tr' ) ) . each ( ( idx , tag ) => {
62
74
$ ( tag ) . find ( 'th' ) . text ( idx + 1 ) ;
63
75
} ) ;
76
+
77
+ // disable last operator
78
+ $ ( that . wrapSelector ( '.v1 tr:last .v1-i4' ) ) . prop ( 'disabled' , true ) ;
64
79
} ) ;
65
80
}
66
81
@@ -94,7 +109,8 @@ define([
94
109
var page = new com_String ( ) ;
95
110
page . appendLine ( '<table class="v1 wp100" style="margin: 10px 0">' ) ;
96
111
// page.appendLine('<thead><tr><td></td><td>Parameter</td><td></td><td>Default Value</td></tr></thead>');
97
- page . appendLine ( '<tbody><colgroup><col width="20px"><col width="100px"><col width="100px"><col width="100px"><col width="100px"><col width="30px"></colgroup>' ) ;
112
+ page . appendLine ( '<colgroup><col width="20px"><col width="100px"><col width="100px"><col width="100px"><col width="100px"><col width="30px"></colgroup>' ) ;
113
+ page . appendLine ( '<tbody class="v1-table">' ) ;
98
114
this . state . v1 . forEach ( ( v , idx ) => {
99
115
if ( v . type == 'condition' ) {
100
116
page . appendLine ( this . templateForList ( idx + 1 , v . value ) ) ;
@@ -118,8 +134,20 @@ define([
118
134
page . appendFormatLine ( '<th>{0}</th>' , idx ) ;
119
135
page . appendFormatLine ( '<td><input type="text" class="vp-input w100 {0}" value="{1}" placeholder="{2}"/></td>'
120
136
, 'v1-i1' , v . i1 , 'Variable' ) ;
121
- page . appendFormatLine ( '<td><input type="text" class="vp-input w100 {0}" value="{1}" placeholder="{2}"/></td>'
122
- , 'v1-i2' , v . i2 , 'Operator' ) ;
137
+ // suggestInput for operator
138
+ let operList = [ '' , '==' , '!=' , 'in' , 'not in' , '<' , '<=' , '>' , '>=' ] ;
139
+ var suggestInput = new SuggestInput ( ) ;
140
+ suggestInput . addClass ( 'vp-input w100 v1-i2' ) ;
141
+ suggestInput . setSuggestList ( function ( ) { return operList ; } ) ;
142
+ suggestInput . setPlaceholder ( 'Operator' ) ;
143
+ suggestInput . setNormalFilter ( false ) ;
144
+ suggestInput . setValue ( v . i2 ) ;
145
+ suggestInput . setSelectEvent ( function ( selectedValue ) {
146
+ // trigger change
147
+ $ ( this . wrapSelector ( ) ) . val ( selectedValue ) ;
148
+ $ ( this . wrapSelector ( ) ) . trigger ( 'change' ) ;
149
+ } ) ;
150
+ page . appendFormatLine ( '<td>{0}</td>' , suggestInput . toTagString ( ) ) ;
123
151
page . appendFormatLine ( '<td><input type="text" class="vp-input w100 {0}" value="{1}" placeholder="{2}"/></td>'
124
152
, 'v1-i3' , v . i3 , 'Variable' ) ;
125
153
page . appendFormatLine ( '<td><select class="vp-select w100 {0}">' , 'v1-i4' ) ;
@@ -153,6 +181,13 @@ define([
153
181
return page . toString ( ) ;
154
182
}
155
183
184
+ render ( ) {
185
+ super . render ( ) ;
186
+
187
+ // disable last operator
188
+ $ ( this . wrapSelector ( '.v1 tr:last .v1-i4' ) ) . prop ( 'disabled' , true ) ;
189
+ }
190
+
156
191
generateCode ( ) {
157
192
this . saveState ( ) ;
158
193
@@ -179,5 +214,5 @@ define([
179
214
180
215
}
181
216
182
- return If ;
217
+ return Elif ;
183
218
} ) ;
0 commit comments