1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| TreePanelCompte=Ext.extend(Ext.tree.TreePanel,{
id:'gridErreur',
constructor:function(config){
var loader=CompteLoader ({
dataUrl:config.url
});
console.log(loader);
var root= new Ext.tree.AsyncTreeNode({
text:'Coffres',
expanded :true
});
this.treeLoader = CompteLoader({
dataUrl:config.url
});
var configTree=[{
root : root,
// loader: loader,
loader:this.treeLoader,
height:600
}];
archivage.console.TreePanelCompte.superclass.constructor.apply(this,configTree);
}
});
XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
/**
* @property XML_NODE_ELEMENT
* XML element node (value 1, read-only)
* @type Number
*/
XML_NODE_ELEMENT : 1,
/**
* @property XML_NODE_TEXT
* XML text node (value 3, read-only)
* @type Number
*/
XML_NODE_TEXT : 3,
// private override
processResponse : function(response, node, callback){
var xmlData = response.responseXML;
var root = xmlData.documentElement || xmlData;
try{
node.beginUpdate();
node.appendChild(this.parseXml(root));
node.endUpdate();
if(typeof callback == "function"){
callback(this, node);
}
}catch(e){
this.handleFailure(response);
}
},
// private
parseXml : function(node) {
var nodes = [];
Ext.each(node.childNodes, function(n){
if(n.nodeType == this.XML_NODE_ELEMENT){
if(n.childNodes.length > 0){
var child = this.parseXml(n);
if(typeof child == 'string'){
// console.log(child);
var treeNode = this.createNode2(n,child);
treeNode.attributes.innerText = child;
console.log(treeNode);
}else{
var treeNode = this.createNode(n);
treeNode.appendChild(child);
}
}
nodes.push(treeNode);
}
else if(n.nodeType == this.XML_NODE_TEXT){
var text = n.nodeValue.trim();
if(text.length > 0){
return nodes = text;
}
}
}, this);
return nodes;
},
// private overrid
createNode : function(node){
var attr = {
tagName: node.tagName
};
//console.log(node.valueOf())
Ext.each(node.attributes, function(a){
//console.log(a);
attr[a.nodeName] = a.nodeValue;
});
this.processAttributes(attr);
return archivage.console.XmlTreeLoader.superclass.createNode.call(this, attr);
},
createNode2 : function(node,child){
var attr = {
tagName: node.tagName
};
//console.log(node.valueOf())
Ext.each(node.attributes, function(a){
//console.log(a);
attr[a.nodeName] = a.nodeValue;
});
this.processAttributes2(attr,child);
return archivage.console.XmlTreeLoader.superclass.createNode.call(this, attr);
}
/*
* Template method intended to be overridden by subclasses that need to provide
* custom attribute processing prior to the creation of each TreeNode. This method
* will be passed a config object containing existing TreeNode attribute name/value
* pairs which can be modified as needed directly (no need to return the object).
*/
//processAttributes: Ext.emptyFn
});
CompteLoader = Ext.extend(XmlTreeLoader, {
processAttributes : function(attr){
if(attr.tagName=='Coffre'){
attr.text=attr.tagName;
attr.loaded=true;
}else if(attr.tagName=='id') {
attr.leaf=true;
attr.load=true;
}else if(attr.tagName=='name') {
attr.leaf=true;
attr.load=true;
}
},
processAttributes2 : function(attr,child){
if(attr.tagName=='Coffre'){
attr.text=attr.tagName;
attr.loaded=true;
}else if(attr.tagName=='id') {
attr.leaf=true;
attr.text="id :"+child;
attr.load=true;
}else if(attr.tagName=='name') {
attr.leaf=true;
attr.text="Nom :"+child;
attr.load=true;
}
}
}); |
Partager