var bricks = window.bricks || {}; bricks.TreeNode = class extends bricks.VBox { constructor(tree, pnode, data){ var opts = { width:'100%', height:'auto', } super(opts); this.tree = tree; this.parent_node = pnode; this.children_loaded = false; this.user_data = data; this.is_leaf = this.user_data.is_leaf; this.params = bricks.extend(this.tree.params, {id:this.user_data[this.tree.opts.idField]}); if (this.tree.multitype_tree){ this.params['type'] = this.user_data[this.tree.opts.typeField]; } var n = new bricks.HBox({ height:this.tree.row_height, width:'100%' }) n.dom_element.style.margin = bricks.app.charsize * 0.2; this.add_widget(n); n.bind('click', this.tree.node_click_handle.bind(this.tree, this)); this.node_widget = n; schedule_once(this.create_node_content.bind(this,n), 0.01); if (! this.user_data.is_leaf) { this.container = new bricks.VBox({height:'auto'}); this.add_widget(this.container); this.container.dom_element.style.marginLeft = bricks.app.charsize + 'px'; if (this.user_data.children){ this.tree.create_node_children(this, this.user_data.children); } this.container.hide(); } } getValue(){ var v = this.user_data; if (this.container){ var children = []; for (var i=0; i 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.IconTextBar(toolbar); this.add_widget(this.toolbar_w); this.toolbar_w.bind('command', this.toolbar_command.bind(this)) } toolbar_command(event){ var opts = event.params; switch (opts.name){ case 'add': this.add_new_node(); breaks; case 'delete': this.delete_node(); break; case 'update': this.update_node(); break; default: console.log('opts=', opts); var d = null; if (opts.checked_data){ d = { checked_data:JSON.stringify(this.checked_data) } } else if (opts.selected_node){ d = { selected_data:JSON.stringify(this.selected_node.user_data) } } this.dispatch(opts.name, d); break; } } 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){ node = this.selected_node; d[this.parentField] = node.get_id(); } if (this.editable.add_url){ var jc = new bricks.HttpJson() var desc = await jc.post(this.editable.add_url, {params:d}); if (desc.widgettype == 'Message'){ var data = desc.options.user_data; this.append_new_subnode(node, data); } var w = await bricks.widgetBuild(desc, this); w.open(); } else { d[this.idField] = bricks.uuid(); this.append_new_subnode(node, d); } } async create_tree_nodes(node, records){ for (var i=0;i d.id == node.user_data.id); } node.user_data[this.checkField] = stat; if (stat){ console.log('value=', cb.getValue(), 'node=', node); } this.dispatch('check_changed', node.user_data); } } bricks.Factory.register('Tree', bricks.Tree); bricks.Factory.register('EditableTree', bricks.EditableTree);