/* * Project Name : Visual Python * Description : GUI-based Python code generator * File Name : While.js * Author : Black Logic * Note : Logic > while * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 * Change Date : */ //============================================================================ // [CLASS] While //============================================================================ define([ 'vp_base/js/com/com_Const', 'vp_base/js/com/com_String', 'vp_base/js/com/com_util', 'vp_base/js/com/component/PopupComponent', 'vp_base/js/com/component/SuggestInput' ], function(com_Const, com_String, com_util, PopupComponent, SuggestInput) { /** * While */ class While extends PopupComponent { _init() { super._init(); /** Write codes executed before rendering */ this.config.dataview = false; this.config.sizeLevel = 1; this.config.saveOnly = true; this.state = { v1: [{ type: 'condition', value: {} }], ...this.state } } _bindEvent() { super._bindEvent(); /** Implement binding events */ let that = this; // Add param $(this.wrapSelector('#vp_addCondition')).on('click', function() { that.state.v1.push({ type: 'condition', value: {} }); $(that.wrapSelector('.v1 tbody')).append(that.templateForList(that.state.v1.length, {})); // enable and disable last one // enable all operator $(that.wrapSelector('.v1 .v1-i4')).prop('disabled', false); // disable last operator $(that.wrapSelector('.v1 tr:last .v1-i4')).prop('disabled', true); }); $(this.wrapSelector('#vp_addUserInput')).on('click', function() { that.state.v1.push({ type: 'input', value: {} }); $(that.wrapSelector('.v1 tbody')).append(that.templateForInput(that.state.v1.length, {})); // enable and disable last one // enable all operator $(that.wrapSelector('.v1 .v1-i4')).prop('disabled', false); // disable last operator $(that.wrapSelector('.v1 tr:last .v1-i4')).prop('disabled', true); }); // Delete param $(document).on('click', this.wrapSelector('.v1-del'), function() { let pos = $(this).closest('.v1-tr').index(); $(that.wrapSelector('.v1-tr:nth('+pos+')')).remove(); that.state.v1.splice(pos, 1); // re-numbering $(that.wrapSelector('.v1-tr')).each((idx, tag) => { $(tag).find('th').text(idx + 1); }); // disable last operator $(that.wrapSelector('.v1 tr:last .v1-i4')).prop('disabled', true); }); } _unbindEvent() { super._unbindEvent(); $(document).off('click', this.wrapSelector('.v1-del')); } saveState() { let that = this; let v1 = []; $(this.wrapSelector('.v1-tr')).each((idx, tag) => { let type = $(tag).data('type'); let v1_ele = {}; if (type == 'condition') { v1_ele['i1'] = $(tag).find('.v1-i1').val(); v1_ele['i2'] = $(tag).find('.v1-i2').val(); v1_ele['i3'] = $(tag).find('.v1-i3').val(); v1_ele['i4'] = $(tag).find('.v1-i4').val(); } else { v1_ele['i1'] = $(tag).find('.v1-i1').val(); v1_ele['i4'] = $(tag).find('.v1-i4').val(); } v1.push({ type: type, value: v1_ele }); }); this.state.v1 = v1; } templateForBody() { /** Implement generating template */ var page = new com_String(); page.appendLine('
| Parameter | Default Value |