bugfix
This commit is contained in:
parent
57f9c11f75
commit
13f7461dc3
1
bricks/imgs/close-folder.svg
Normal file
1
bricks/imgs/close-folder.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1751017528469" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5616" width="100%" height="100%"><path d="M153.6 307.2h250.88l-51.2-76.8H153.6V307.2z m368.64 0H870.4c56.32 0 102.4 46.08 102.4 102.4v435.2c0 56.32-46.08 102.4-102.4 102.4H153.6c-56.32 0-102.4-46.08-102.4-102.4v-614.4c0-56.32 46.08-102.4 102.4-102.4h199.68c35.84 0 66.56 15.36 87.04 46.08L522.24 307.2zM153.6 409.6v435.2h716.8V409.6H153.6z" fill="${color}" p-id="5617"></path></svg>
|
After Width: | Height: | Size: 498 B |
@ -28,6 +28,10 @@ bricks.Svg = class extends bricks.VBox {
|
||||
}
|
||||
}
|
||||
set_url(url){
|
||||
if (!url){
|
||||
this.dom_element.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
this.url = url;
|
||||
fetch(url)
|
||||
.then(response => response.text())
|
||||
@ -84,18 +88,45 @@ bricks.StatedSvg = class extends bricks.Svg {
|
||||
} */
|
||||
constructor(opts){
|
||||
super(opts);
|
||||
this.curstate = null;
|
||||
if (this.states){
|
||||
if (! this.state){
|
||||
this.state = this.states[0].state;
|
||||
}
|
||||
var url = this.set_state(this.state);
|
||||
this.set_url(url);
|
||||
this.set_state(this.state);
|
||||
}
|
||||
this.bind('click', this.trigger.bind(this));
|
||||
}
|
||||
trigger(event){
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
for (var i=0;i<this.states.length;i++){
|
||||
var g = this.states[i];
|
||||
if (this.curstate = g.state) {
|
||||
var k = 0;
|
||||
if (i < this.states.length - 1){
|
||||
k = i + 1;
|
||||
}
|
||||
this.set_state(this.states[k].state);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
set_state(state){
|
||||
if (state == this.curstate){
|
||||
return;
|
||||
}
|
||||
this.curstate = state;
|
||||
var done = false;
|
||||
this.states.forEach(s => {
|
||||
if (s.state == state) this.set_url(s.url);
|
||||
if (s.state == state){
|
||||
this.set_url(s.url);
|
||||
this.dispatch('state_changed', state);
|
||||
done = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (! done) this.set_url(null);
|
||||
}
|
||||
}
|
||||
bricks.Factory.register('Svg', bricks.Svg);
|
||||
|
@ -10,7 +10,8 @@ bricks.TreeNode = class extends bricks.VBox {
|
||||
this.parent_node = pnode;
|
||||
this.children_loaded = false;
|
||||
this.user_data = data;
|
||||
this.is_leaf = this.user_data.is_leaf;
|
||||
this.is_leaf_field = this.tree.is_leafField || 'is_leaf';
|
||||
this.is_leaf = this.user_data[this.is_leaf_field];
|
||||
this.params = bricks.extend(this.tree.params, {id:this.user_data[this.tree.opts.idField]});
|
||||
if (this.tree.opts.typeField){
|
||||
this.params.type = this.user_data[this.tree.opts.typeField];
|
||||
@ -83,32 +84,39 @@ bricks.TreeNode = class extends bricks.VBox {
|
||||
}
|
||||
this.container.hide();
|
||||
}
|
||||
create_triple(){
|
||||
return new bricks.StatedSvg({
|
||||
state:'close',
|
||||
states:[
|
||||
{
|
||||
state: 'open',
|
||||
url: bricks_resource('imgs/node-expand.svg')
|
||||
},
|
||||
{
|
||||
state: 'close',
|
||||
url: bricks_resource('imgs/node-collapse.svg')
|
||||
}
|
||||
],
|
||||
rate: 1,
|
||||
});
|
||||
}
|
||||
change_node_type(){
|
||||
if (this.is_leaf){
|
||||
this.triple.set_state('close');
|
||||
this.triple.bind('state_changed', this.toggleExpandCollapse.bind(this));
|
||||
return;
|
||||
this.triple.set_url(null);
|
||||
this.triple.unbind('state_changed', this.toggleExpandCollapse.bind(this));
|
||||
} else {
|
||||
this.triple.set_state('close');
|
||||
this.triple.bind('state_changed', this.toggleExpandCollapse.bind(this));
|
||||
}
|
||||
}
|
||||
async create_node_content(widget){
|
||||
var img_size = bricks.app.charsize;
|
||||
if (this.is_leaf){
|
||||
widget.add_widget(new bricks.BlankIcon({}));
|
||||
} else {
|
||||
var srcs = this.tree.opts.node_state_imgs || {};
|
||||
var sources = {};
|
||||
sources['open'] = objget(srcs, 'open', bricks_resource('imgs/node-expand.svg'));
|
||||
sources['close'] = objget(srcs, 'close', bricks_resource('imgs/node-collapse.svg'));
|
||||
this.trigle = new bricks.StatedSvg({
|
||||
state:'close',
|
||||
states:[
|
||||
{
|
||||
state: 'open',
|
||||
url: bricks_resource('imgs/node-expand.svg')
|
||||
},
|
||||
{
|
||||
state: 'close',
|
||||
url: bricks_resource('imgs/node-collapse.svg')
|
||||
}
|
||||
],
|
||||
rate: 1,
|
||||
});
|
||||
this.trigle.bind('state_changed', this.toggleExpandCollapse.bind(this));
|
||||
widget.add_widget(this.trigle);
|
||||
}
|
||||
this.triple = this.create_triple();
|
||||
widget.add_widget(this.triple);
|
||||
this.change_node_type();
|
||||
if (this.tree.checkField){
|
||||
var v = this.user_data[this.tree.checkField];
|
||||
this.check_w = new bricks.UiCheck({name:'check', value:v});
|
||||
@ -160,9 +168,9 @@ bricks.TreeNode = class extends bricks.VBox {
|
||||
}
|
||||
if (! icons){
|
||||
icons = {
|
||||
open: bricks_resource('imgs/open_folders.svg'),
|
||||
close: bricks_resource('imgs/close_folder.svg'),
|
||||
leaf: bricks_resource('imgs/close_folder.svg')
|
||||
open: bricks_resource('imgs/open-folders.svg'),
|
||||
close: bricks_resource('imgs/close-folder.svg'),
|
||||
leaf: bricks_resource('imgs/close-folder.svg')
|
||||
};
|
||||
}
|
||||
this.icons_urls = icons;
|
||||
@ -174,6 +182,7 @@ bricks.Tree = class extends bricks.VScrollPanel {
|
||||
{
|
||||
row_height:
|
||||
idField:
|
||||
is_leafField:
|
||||
textField:
|
||||
type_icons:
|
||||
typeField:
|
||||
@ -317,6 +326,8 @@ bricks.Tree = class extends bricks.VScrollPanel {
|
||||
if (desc.widgettype == 'Message'){
|
||||
var data = desc.options.user_data;
|
||||
this.append_new_subnode(node, data);
|
||||
node.is_leaf = false;
|
||||
if (node != this) node.change_node_type();
|
||||
}
|
||||
var w = await bricks.widgetBuild(desc, this);
|
||||
w.open();
|
||||
|
Loading…
Reference in New Issue
Block a user