diff --git a/bricks/imgs/close-folder.svg b/bricks/imgs/close-folder.svg
new file mode 100644
index 0000000..6a0ea1b
--- /dev/null
+++ b/bricks/imgs/close-folder.svg
@@ -0,0 +1 @@
+
diff --git a/bricks/svg.js b/bricks/svg.js
index 2447420..ecdf4d2 100644
--- a/bricks/svg.js
+++ b/bricks/svg.js
@@ -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 {
- 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);
diff --git a/bricks/tree.js b/bricks/tree.js
index 7a97ecc..5046e50 100644
--- a/bricks/tree.js
+++ b/bricks/tree.js
@@ -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();