This commit is contained in:
yumoqing 2024-05-22 12:03:44 +08:00
parent c3e8e499ac
commit 72173bef6a

View File

@ -23,7 +23,7 @@ bricks.TreeNode = class extends bricks.VBox {
this.add_widget(n);
n.bind('click', this.tree.node_click_handle.bind(this.tree, this));
this.node_widget = n;
this.create_node_content(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);
@ -35,7 +35,16 @@ bricks.TreeNode = class extends bricks.VBox {
}
}
getValue(){
return this.user_data;
var v = this.user_data;
if (this.container){
var children = [];
for (var i=0; i<this.container.children.length;i++){
var sv = this.container.children[i].getValue();
children.push(sv);
}
v.children = children;
}
return v;
}
get_id(){
return this.user_data[this.tree.idField];
@ -70,7 +79,7 @@ bricks.TreeNode = class extends bricks.VBox {
}
this.container.hide();
}
create_node_content(widget){
async create_node_content(widget){
var img_size = bricks.app.charsize;
if (this.is_leaf){
widget.add_widget(new bricks.BlankIcon({}));
@ -106,29 +115,27 @@ bricks.TreeNode = class extends bricks.VBox {
url:icon
});
widget.add_widget(img);
// console.log('info:textField=', this.tree.textField, 'data=', this.user_data, 'tree=', this.tree, 'tree opts=', this.tree.opts);
if (this.tree.node_view){
this.view_w = await bricks.widgetBuild(this.tree.node_view, widget, this.user_data);
if (this.view_w){
widget.add_widget(this.view_w);
}
} else {
var txt = this.user_data[this.tree.opts.textField];
this.str_w = new bricks.Text({text:txt});
this.input = new bricks.UiStr({name:'text', value:txt});
this.input.bind('blur', this.edit_handle.bind(this));
widget.add_widget(this.str_w);
}
edit(){
this.node_widget.remove_widget(this.str_w);
this.input.setValue(this.str_w.text);
this.node_widget.add_widget(this.input);
}
async edit_handle(){
if (this.input.value==this.str_w.text)
return;
var v = this.input.value;
r = await this.syncdata('edit');
this.user_data[this.tree.opts.textField] = v;
this.str_w = new bricks.Text({text:v});
this.node_widget.remove_widget(this.input);
this.node_widget.add_widget(this.str_w);
async update_content(){
if (this.tree.node_view){
this.node_widget.remove_Widget(this.view_w);
this.view_w = await bricks.widgetBuild(this.tree.node_view, widget, this.user_data);
if (this.view_w){
widget.add_widget(this.view_w);
}
} else {
this.str_w.set_text(this.user_data[this.tree.opts.textField]);
}
async syncdata(mode){
}
}
@ -185,7 +192,16 @@ bricks.Tree = class extends bricks.VScrollPanel {
this.bind('node_selected',this.node_info_log.bind(this));
}
getValue(){
return this.user_data;
var v = this.user_data;
if (this.container){
var children = [];
for (var i=0; i<this.container.children.length;i++){
var sv = this.container.children[i].getValue();
children.push(sv);
}
v.children = children;
}
return v;
}
get_id(){
return this.user_data[this.idField];
@ -229,6 +245,7 @@ bricks.Tree = class extends bricks.VScrollPanel {
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'){
@ -237,6 +254,10 @@ bricks.Tree = class extends bricks.VScrollPanel {
}
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<records.length;i++){
@ -274,6 +295,7 @@ bricks.Tree = class extends bricks.VScrollPanel {
async delete_node_conformed(event){
var d = {};
d[this.idField] = this.selected_node.get_id();
if (this.editable.delete_url){
var jc = new bricks.HttpJson()
var desc = await jc.post(this.editable.delete_url, {params:d});
if (desc.widgettype == 'Message'){
@ -286,6 +308,13 @@ bricks.Tree = class extends bricks.VScrollPanel {
}
var w = await bricks.widgetBuild(desc, this);
w.open();
} else {
var pnode = this.selected_node.parent_node;
if (pnode && pnode.container){
pnode.container.remove_widget(this.selected_node);
}
this.selected_node = null;
}
}
delete_subnode(node, subnode){
var subid = subnode.user_data[this.idField];
@ -326,20 +355,24 @@ bricks.Tree = class extends bricks.VScrollPanel {
var d = event.params;
var node = this.selected_node;
d[this.idField] = node.get_id();
if(this.editable.update_url){
var jc = new bricks.HttpJson()
var desc = await jc.post(this.editable.update_url, {params:d});
if (desc.widgettype == 'Message'){
this.update_node_data(node, d);
await this.update_node_data(node, d);
}
var w = await bricks.widgetBuild(desc, this);
w.open();
} else {
await this.update_node_data(node, d);
}
}
update_node_data(node, data){
async update_node_data(node, data){
for (var name in Object.keys(data)){
node.user_data[name] = data[name];
}
node.str_w.set_text(data[this.textField]);
await node.update_content();
}
async get_children_data(node){