]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/components/DynamicTreeFolder.js
6841b700d748efedaf6dbecd41651b262eddc85c
2 * A "dynamic" implementation of the standard TreeFolder class.
5 qx
.Class
.define("org.argeo.ria.components.DynamicTreeFolder", {
6 extend
: qx
.ui
.tree
.TreeFolder
,
10 * The current state of the folder, usually "empty" => "loading" => "loaded"
18 * String to display as a child node during loading
25 * Function that will load the children of this folder
29 init : function(treeFolder
){treeFolder
.setLoaded();}
32 * Optionnal data describing the "drag" behaviour of the created children.
33 * First level is "file" or "folder", and for each of them, supported keys are "type" and "action".
42 * Creates a new instance of DynamicTreeFolder
43 * @param label {String} Label of the folder
44 * @param loader {Function} Function that will load the children
45 * @param loadingString {String} String to display as a child node during loading
46 * @param dragData {Map} Optionnal data describing the "drag" behaviour of the created children.
48 construct : function(label
, loader
, loadingString
, dragData
){
49 this.base(arguments
, label
);
50 if(loader
) this.setLoader(loader
);
51 if(loadingString
) this.setLoadingString(loadingString
);
52 if(dragData
) this.setDragData(dragData
);
53 this.addListener("changeOpen", function(e
){
54 if(e
.getData() && this.getState() == "loading"){
58 this.setState("loading");
63 * Add an item to the folder
64 * @param varargs {Mixed} One or many children to add
66 add : function(varargs
){
67 this.base(arguments
, varargs
);
68 for (var i
=0, l
=arguments
.length
; i
<l
; i
++)
70 var treeItem
= arguments
[i
];
71 if(treeItem
== this.loadingChild
) continue;
72 this.appendDragData(treeItem
);
77 * If there is dragData set, init the drag behaviour of a child
78 * @param treeItem {qx.ui.tree.AbstractTreeItem} Newly created child
80 appendDragData : function(treeItem
){
81 var dragData
= this.getDragData();
82 var nodeTypeDetected
= false;
83 if(qx
.Class
.isSubClassOf(qx
.Class
.getByName(treeItem
.classname
), qx
.ui
.tree
.TreeFile
) && dragData
["file"]){
84 nodeTypeDetected
= "file";
86 if(qx
.Class
.isSubClassOf(qx
.Class
.getByName(treeItem
.classname
), qx
.ui
.tree
.TreeFolder
) && dragData
["folder"]){
87 nodeTypeDetected
= "folder";
89 if(!nodeTypeDetected
) return;
91 treeItem
.setDraggable(true);
92 treeItem
.addListener("dragstart", function(e
){
93 if(dragData
[nodeTypeDetected
]["type"]){
94 for(var j
=0;j
<dragData
[nodeTypeDetected
]["type"].length
;j
++){
95 e
.addType(dragData
[nodeTypeDetected
]["type"][j
]);
98 if(dragData
[nodeTypeDetected
]["action"]){
99 for(var j
=0;j
<dragData
[nodeTypeDetected
]["action"].length
;j
++){
100 e
.addAction(dragData
[nodeTypeDetected
]["action"][j
]);
108 * Set the state to "loaded"
110 setLoaded : function(){
111 this.setState("loaded");
114 * Called when "state" is set to a new value
115 * @param state {String} the new state
117 _applyState : function(state
){
118 if(state
== "loaded"){
119 if(this.loadingChild
){
120 this.remove(this.loadingChild
);
121 delete this.loadingChild
;
123 }else if(state
== "loading" && !this.loadingChild
){
124 this.addLoadingChild();
128 * Create a temporary child with the loadingString label and add it.
130 addLoadingChild : function(){
131 this.loadingChild
= new qx
.ui
.tree
.TreeFile(this.getLoadingString());
132 this.add(this.loadingChild
);
135 * Call loader function.
138 var loaderFunc
= this.getLoader();
142 * Empty then call loader function.
146 this.setState("loading");