11/*
22 * Project Name : Visual Python
33 * Description : GUI-based Python code generator
4- * File Name :If .js
4+ * File Name :Elif .js
55 * Author : Black Logic
6- * Note : Logic >if
6+ * Note : Logic >elif
77 * License : GNU GPLv3 with Visual Python special exception
88 * Date : 2021. 11. 18
99 * Change Date :
1010 */
1111
1212//============================================================================
13- // [CLASS]If
13+ // [CLASS]Elif
1414//============================================================================
1515define ( [
1616'vp_base/js/com/com_String' ,
@@ -20,9 +20,9 @@ define([
2020] , function ( com_String , com_util , PopupComponent , SuggestInput ) {
2121
2222/**
23- *If
23+ *Elif
2424 */
25- class If extends PopupComponent {
25+ class Elif extends PopupComponent {
2626_init ( ) {
2727super . _init ( ) ;
2828/** Write codes executed before rendering */
@@ -31,7 +31,7 @@ define([
3131this . config . saveOnly = true ;
3232
3333this . state = {
34- v1 :[ ] ,
34+ v1 :[ { type : 'condition' , value : { } } ] ,
3535 ...this . state
3636}
3737}
@@ -43,11 +43,23 @@ define([
4343// Add param
4444$ ( this . wrapSelector ( '#vp_addCondition' ) ) . on ( 'click' , function ( ) {
4545that . 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 ) ;
4753} ) ;
4854$ ( this . wrapSelector ( '#vp_addUserInput' ) ) . on ( 'click' , function ( ) {
4955that . 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 ) ;
5163} ) ;
5264
5365// Delete param
@@ -61,6 +73,9 @@ define([
6173$ ( that . wrapSelector ( '.v1-tr' ) ) . each ( ( idx , tag ) => {
6274$ ( tag ) . find ( 'th' ) . text ( idx + 1 ) ;
6375} ) ;
76+
77+ // disable last operator
78+ $ ( that . wrapSelector ( '.v1 tr:last .v1-i4' ) ) . prop ( 'disabled' , true ) ;
6479} ) ;
6580}
6681
@@ -94,7 +109,8 @@ define([
94109var page = new com_String ( ) ;
95110page . appendLine ( '<table class="v1 wp100" style="margin: 10px 0">' ) ;
96111// 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">' ) ;
98114this . state . v1 . forEach ( ( v , idx ) => {
99115if ( v . type == 'condition' ) {
100116page . appendLine ( this . templateForList ( idx + 1 , v . value ) ) ;
@@ -118,8 +134,20 @@ define([
118134page . appendFormatLine ( '<th>{0}</th>' , idx ) ;
119135page . appendFormatLine ( '<td><input type="text" class="vp-input w100 {0}" value="{1}" placeholder="{2}"/></td>'
120136, '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 ( ) ) ;
123151page . appendFormatLine ( '<td><input type="text" class="vp-input w100 {0}" value="{1}" placeholder="{2}"/></td>'
124152, 'v1-i3' , v . i3 , 'Variable' ) ;
125153page . appendFormatLine ( '<td><select class="vp-select w100 {0}">' , 'v1-i4' ) ;
@@ -153,6 +181,13 @@ define([
153181return page . toString ( ) ;
154182}
155183
184+ render ( ) {
185+ super . render ( ) ;
186+
187+ // disable last operator
188+ $ ( this . wrapSelector ( '.v1 tr:last .v1-i4' ) ) . prop ( 'disabled' , true ) ;
189+ }
190+
156191generateCode ( ) {
157192this . saveState ( ) ;
158193
@@ -179,5 +214,5 @@ define([
179214
180215}
181216
182- return If ;
217+ return Elif ;
183218} ) ;