Skip to content

Commit 535ff59

Browse files
author
minjk-bl
committed
Elif - popup same as if
1 parent afcab16 commit 535ff59

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

data/libraries.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
"type" : "function",
385385
"level": 1,
386386
"name" : "elif",
387-
"tag" : "ELSE,LOGIC",
387+
"tag" : "ELIF,LOGIC",
388388
"path" : "visualpython - logic - control - elif",
389389
"desc" : "elif",
390390
"file" : "m_logic/Elif",

js/m_logic/Elif.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
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
//============================================================================
1515
define([
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() {
2727
super._init();
2828
/** Write codes executed before rendering */
@@ -31,7 +31,7 @@ define([
3131
this.config.saveOnly = true;
3232

3333
this.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() {
4545
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);
4753
});
4854
$(this.wrapSelector('#vp_addUserInput')).on('click', function() {
4955
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);
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([
94109
var page = new com_String();
95110
page.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">');
98114
this.state.v1.forEach((v, idx) => {
99115
if (v.type == 'condition') {
100116
page.appendLine(this.templateForList(idx + 1, v.value));
@@ -118,8 +134,20 @@ define([
118134
page.appendFormatLine('<th>{0}</th>', idx);
119135
page.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());
123151
page.appendFormatLine('<td><input type="text" class="vp-input w100 {0}" value="{1}" placeholder="{2}"/></td>'
124152
, 'v1-i3', v.i3, 'Variable');
125153
page.appendFormatLine('<td><select class="vp-select w100 {0}">', 'v1-i4');
@@ -153,6 +181,13 @@ define([
153181
return 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+
156191
generateCode() {
157192
this.saveState();
158193

@@ -179,5 +214,5 @@ define([
179214

180215
}
181216

182-
return If;
217+
return Elif;
183218
});

0 commit comments

Comments
 (0)