PDA

View Full Version : [tree] check if folder



markkl
11 Feb 2008, 3:14 AM
How do i know when the node is en file or a dir onclick?
And how do i send extra fields in tree , for example i want to send the exention from all the file's.



var Tree = Ext.tree;

var tree = new Tree.TreePanel({
region:'west',
split:true,
collapsible: true,
collapseMode: 'mini',
width:200,
minWidth: 150,
maxWidth: 350,
border: false,
title: 'Bestanden',
margins: '5 0 5 5',
cmargins: '5 5 5 5',
el:'tree-div',
enableRename: true,
autoScroll:true,
animate:false,
enableDD:true,
containerScroll: true,
loader: new Tree.TreeLoader({
dataUrl:'get-nodes.php'
})
});


// set the root node
var root = new Tree.AsyncTreeNode({
text: 'phpBB3',
draggable:false,
id:'source'
});
tree.on('click', function(node,test,type){
extension =node.text.split(".")[node.text.split(".").length-1];
if(extension == "js")
extension = "javascript"
if(extension == "htm")
extension = "html"
tabcontrol.getFileContent(node.text,'phpBB3/'+node.id,extension);
});

evant
11 Feb 2008, 3:20 AM
You could check if the node is a leaf or not



alert(node.isLeaf());


As for passing extra parameters, just put them in the TreeNode config. From here, they can be accessed by an attributes property:



{
id: 'node1',
text: 'Node 1',
foo: 'x',
bar: 'y'
}
alert(node.attributes.foo);

markkl
11 Feb 2008, 3:53 AM
THNX works perfect.
I got one more question:
When i activate a tab i want to trigger a function, but how do i do this?


addTab: function(tabTitle, targetUrl,type,content) {
tabPanel.add({
title: tabTitle,
closable:true,
iconCls: 'tabs',
html: '<textarea id="editor'+index+'" class="codepress '+type+'" style="width:100%;height:99%;">'+content+'</textarea>'
}).show();
CodePress.start('editor'+index);
editors[tabPanel.getActiveTab().id]='editor'+index;
Ext.MessageBox.hide();
if(tabPanel.items.length >=1){
close = 'welkomTab';
tabPanel.remove('welkomTab');
}

tabPanel.on('beforeRemove', function(panel, node){
if(node.id == close){
return true;
}
return true;
Ext.MessageBox.show({
title:'Save Changes?',
msg: 'You are closing a tab that has unsaved changes. <br />Would you like to save your changes?',
buttons: Ext.MessageBox.YESNOCANCEL,
icon: Ext.MessageBox.QUESTION,
fn:function(btn){
if (btn=="yes"){
alert("save file functie hier");
close = node.id;
tabPanel.remove(node.id);
}else if(btn=='no'){
close = node.id;
tabPanel.remove(node.id);
}else if(btn=='cancel'){
closingAll = false;
return false;
}
}
});
return false;

} );

tabPanel.on('remove', function(panel, node){
if( closingAll ){
menufunctions.closeAll();
}
});
tabPanel.on('activate', function(){
alert("THis is not working");
});

}
},