PDA

View Full Version : So simple, but i simple dont get it. How to refresh tree?



Kadifo
22 Jul 2010, 7:36 AM
Hello everyone,

I simply don't get this framework and probably never going to do. I've have several years of experience with javascript, but don't get this. I've been with this problem for about 4 hours and googled it and simply can't find anything. Someone please save my life before my head explodes!

Im having a SortTree that one of my friends made once.

Looks like this:



var SortTree = Ext.extend(Ext.tree.TreePanel, {
el:'tree',
useArrows:true,
autoScroll:true,
animate:true,
height:2000,
enableDD:true,
containerScroll: true,
loader: new Ext.tree.TreeLoader({
dataUrl: 'includes/shop_categories_sort.php'
, preloadChildren: false
, requestMethod: 'GET'
, baseParams: {
task: 'read'
}
}),
root: {
nodeType: 'async',
text: 'Shop kategorier',
draggable:false,
id:'source'
},
listeners: {
nodedragover: function(e) {
//console.log(e.data.node.hasChildNodes());
if(e.target.getDepth() == 1){
e.target.leaf = false;
}
if(e.data.node.hasChildNodes()){
e.target.leaf = true;
}
},
nodedrop: function(e){
return this.saveTree(e);
},
dblclick: function(node, e) {
if(node.getDepth() != 0) {
document.getElementById('theiFrame').src='shop_cat_edit.php?id='+node.id
//return document.location = 'pages_edit.php?id='+node.id;
}
}
},
saveTree: function(e){
function simplifyNodes(node) {
var resultNode = {};
var kids = node.childNodes;
var len = kids.length;
for (var i = 0; i < len; i++) {
resultNode[kids[i].id] = simplifyNodes(kids[i]);
}
return resultNode;
}
var encNodes = Ext.encode(simplifyNodes(e.tree.root));

Ext.Ajax.request({
waitMsg: 'Gemmer ...'
, url: 'includes/shop_categories_sort.php'
, params: {
result: encNodes
, task: 'save'
}
, callback: function (options, success, response) {
if (!success) {
Ext.Msg.alert('Der er sket en fejl, prÝv igen.');
}
}
, failure:function(response,options){
Ext.Msg.alert('Fejl','Oops...');
}
, success:function(response,options){

}
, method: 'GET'
, scope: this
});
}
});
Ext.onReady(function(){
var buildTree = new SortTree();
buildTree.render();
buildTree.getRootNode().expand();
});


I have the data which loads inside an iFrame, and when the function "test()" is called within the I got this in my file:


function test() {
var buildTree = new SortTree();
buildTree.render();
}

This just renders another SortTree under the existing one?

How can I make it reload the existing one with the new db update from 'includes/shop_categories_sort.php'?
Please help!!

Nightwish
22 Jul 2010, 9:19 AM
You are creating a new tree. Give the existing tree an ID ("categoryTree" in my example) and use it instead. Try this:



function test()
{
var tree = Ext.getCmp('categoryTree');
tree.getLoader().load(tree.getRootNode());
}


Also make sure that the TreeLoader is initialized with clearOnLoad: true;

Kadifo
22 Jul 2010, 11:18 PM
My hero! If I had the power I would give you the key to the city my friend! :)

Big time thanks!