/* * Project Name : Visual Python * Description : GUI-based Python code generator * File Name : Def.js * Author : Black Logic * Note : Logic > def * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 * Change Date : */ //============================================================================ // [CLASS] Def //============================================================================ 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' ], function(com_Const, com_String, com_util, PopupComponent) { /** * Def */ class Def extends PopupComponent { _init() { super._init(); /** Write codes executed before rendering */ this.config.dataview = false; this.config.saveOnly = true; this.state = { v1: '', v2: [], ...this.state } } _bindEvent() { super._bindEvent(); /** Implement binding events */ let that = this; $(this.wrapSelector('#vp_addParam')).on('click', function() { that.state.v2.push({ param: '', value: ''}); $(that.wrapSelector('.v2 tbody')).append(that.templateForList(that.state.v2.length, '', '')); }); // Delete param $(document).on('click', this.wrapSelector('.v2-del'), function() { let pos = $(this).closest('.v2-tr').index(); $(that.wrapSelector('.v2-tr:nth('+pos+')')).remove(); that.state.v2.splice(pos, 1); // re-numbering $(that.wrapSelector('.v2-tr')).each((idx, tag) => { $(tag).find('th').text(idx + 1); }); }); } _unbindEvent() { super._unbindEvent(); $(document).off('click', this.wrapSelector('.v2-del')); } saveState() { let that = this; let v2 = []; $(this.wrapSelector('.v2-tr')).each((idx, tag) => { let v2_ele = {}; v2_ele['param'] = $(tag).find('.v2-param').val(); v2_ele['value'] = $(tag).find('.v2-value').val(); v2.push(v2_ele); }); this.state.v2 = v2; } loadState() { super.loadState(); let { v1, v2 } = this.state; } templateForBody() { /** Implement generating template */ var page = new com_String(); page.appendLine('
| Parameter | Default Value |