/* * Project Name : Visual Python * Description : GUI-based Python code generator * File Name : For.js * Author : Black Logic * Note : Logic > for * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 * Change Date : */ //============================================================================ // [CLASS] For //============================================================================ define([ __VP_CSS_LOADER__('vp_base/css/m_logic/for'), // INTEGRATION: unified version of css loader 'vp_base/js/com/com_String', 'vp_base/js/com/com_util', 'vp_base/js/com/component/PopupComponent', 'vp_base/js/com/component/VarSelector' ], function(forCss, com_String, com_util, PopupComponent, VarSelector) { /** * For */ class For extends PopupComponent { _init() { super._init(); /** Write codes executed before rendering */ this.config.dataview = false; this.config.saveOnly = true; this.config.sizeLevel = 1; this.state = { v1: 'idx', // index v2: 'item', // item v3: 'range', // Type : range/variable/typing v4: '', // Range - start v5: '', // - stop v6: '', // - step v7: '', // Variable v8: '', // Typing useEnumerate: true, ...this.state } this._addCodemirror('code', this.wrapSelector('#code')); } _bindEvent() { super._bindEvent(); /** Implement binding events */ let that = this; $(this.wrapSelector('#v3')).on('change', function() { let type = $(this).val(); // show input if (type == 'range') { $(that.wrapSelector('#v2')).hide(); $(that.wrapSelector('.vp-enumerate-box')).hide(); } else { $(that.wrapSelector('#v2')).show(); $(that.wrapSelector('.vp-enumerate-box')).show(); } // show sub box $('.vp-for-sub-box').hide(); $('.vp-sub-'+type).show(); }); $(this.wrapSelector('#v7')).on('var_changed', function(evt) { let value = evt.value; that.state.v7 = value; }); $(this.wrapSelector('#useEnumerate')).on('change', function() { let checked = $(this).prop('checked'); that.state.useEnumerate = checked; if (checked) { $(that.wrapSelector('#v1')).show(); } else { $(that.wrapSelector('#v1')).hide(); } }); } templateForBody() { /** Implement generating template */ var page = new com_String(); page.appendLine('