From 2df5098bd7b1f664207726dbc787cb0463140e27 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 20 May 2024 18:16:38 +0800 Subject: [PATCH] bugfix --- bricks/menu.js | 93 +++++++++++++++++++++++++++++++------------- bricks/modal.js | 15 ++++--- bricks/tree.js | 101 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 166 insertions(+), 43 deletions(-) diff --git a/bricks/menu.js b/bricks/menu.js index 3e72a70..739c03a 100755 --- a/bricks/menu.js +++ b/bricks/menu.js @@ -13,50 +13,89 @@ bricks.Menu = class extends bricks.VBox { this.dom_element.style.position = "absolute"; this.dom_element.style.backgroundColor = options.bgcolor || "white"; this.dom_element.style.zIndex = "1000"; - this.create_children(this.dom_element, this.opts.items); + this.create_children(this, this.opts.items); this.bind('click', this.menu_clicked); } create_submenu_container(){ - let cp = document.createElement('div'); - cp.style.marginLeft = "15px"; - cp.style.display = 'none'; + let cp = new bricks.VBox({}); + cp.set_style('marginLeft', "15px"); + cp.set_style('display', 'none'); return cp; } async menu_clicked(event){ - let mit = event.target; - if (mit.children.length > 0){ - for (var i=0;i tools.push(f)); + if (toolbar.tools){ + toolbar.tools.forEach(f => tools.push(f)); + } if (this.editable){ tools.push({icon:bricks_resource('imgs/add.png'), name:'add'}); tools.push({icon:bricks_resource('imgs/update.png'), name:'update'}); tools.push({icon:bricks_resource('imgs/delete.png'), name:'delete'}); } + if (tools.length == 0){ + return; + } toolbar.tools = tools; this.toolbar_w = new bricks.IconBar(toolbar); this.add_widget(this.toolbar_w); this.toolbar_w.bind('add', this.add_new_node.bind(this)); - this.toolbar_w.bind('delete', this.delete.bind(this)); + this.toolbar_w.bind('delete', this.delete_node.bind(this)); this.toolbar_w.bind('update', this.update_node.bind(this)); } + async add_new_node(){ + var w = new bricks.ModalForm({ + target:this, + "width":"80%", + "height":"80%", + title:'add new node', + fields:this.editable.fields + }); + w.bind('submit', this.new_node_inputed.bind(this)) + } + + async new_node_inputed(event){ + var d = event.params; + var node = this; + if (this.selected_node){ + d[this.parentField] = this.selected+node.get_id(); + node = this.selected_node; + } + var jc = new bricks.HttpJson() + var desc = jc.post(this.editable.add_url, {params:d}); + if (desc.widgettype == 'Message'){ + var data = desc.options.user_data; + this.build_subnode(node, data); + } + var w = await bricks.widgetBuild(desc, this); + } + async create_tree_nodes(node, records){ + for (var i=0;i