PDA

View Full Version : Help In Getting the Nodes Checked in for the tree Panel.



er.viveksharma
1 Apr 2011, 10:53 AM
Hi I am new to EXT Js and trying to introduce an enhancement which needs checkboxes to be there in front of all the text files that I have in the tree. I have successfully been able to add the checkboxes and handle the events on the clicks but still not able to capture all the checked items on the click of the button 'Add Licenses'. I need some urgent help. Below is the code I am trying to work with :

.Components.ComponentFileBrowser = Ext.extend(.Components.BaseView,{
layout:'border',
initComponent:function()
{
this.title="Browse:"+this.name.substring(0,10)+"...";
this.title="<span title='"+"Browse:"+this.name+"'>"+this.title+"</span>";
.Components.AssetHierarchyView.superclass.initComponent.call(this);
this.tree = new Ext.tree.TreePanel({
this:this.tree,
animate:true,
loader: new Ext.tree.TreeLoader({
dataUrl:

}),
enableDD:false,
autoScroll:true,
componentId:this.componentId,
containerScroll: true,
region: 'center',
split: true,
width: '30%',
collapsible: true,
contextMenu: new Ext.menu.Menu({
items: [{
id: 'add-license',
text: 'Add this License'
}],
listeners: {
itemclick: function(item) {
switch (item.id) {
case 'add-license':
var n = item.parentMenu.contextNode;
Ext.Ajax.request({
url : .Config.baseURL+.Config.context +'ComponentServiceServlet?action=addLicense',
params : {componentId:n.getOwnerTree().componentId,licenseFileName:n.id},
method: 'POST',
success: function (result, request) {
var rs=new Ext.form.IPCXmlErrorReader().read(result);
if(rs.success){
Ext.MessageBox.alert('Information', 'Added License Successfully...',function(){});
}else{
Ext.MessageBox.alert('Error Message', rs.records[0].data['msg']);
}
},
failure: function (result, request) {
var rs=new Ext.form.IPCXmlErrorReader().read(result);
Ext.MessageBox.alert('Error Message', rs.records[0].data['msg']);
},
callback:function(){}
});
break;
}
}
}
}),
listeners: {
contextmenu: function(node, e) {
if(node.attributes['iconCls'] == 'file-txt'){
node.select();
var c = node.getOwnerTree().contextMenu;
c.contextNode = node;
c.showAt(e.getXY());
}
},
'checkchange': function(node, checked){
if(checked){
node.getUI().addClass('complete');
}else{
node.getUI().removeClass('complete');
}
}
},
buttons: [{
text: 'Add The Licenses',
handler: function(){

var msg = '', selNodes = this.getChecked();
Ext.each(selNodes, function(node){
if(msg.length > 0){
msg += ', ';
}
msg += node.text;
});
Ext.Msg.show({
title: 'The Licences Added',
msg: msg.length > 0 ? msg : 'None',
icon: Ext.Msg.INFO,
minWidth: 200,
buttons: Ext.Msg.OK
});
}
}]
});
new Ext.tree.TreeSorter(this.tree, {folderSort: true});

this.content = new Ext.Panel({
region: 'east',
split: true,
collapsible: true,
html:' ',
width: '60%',
containerScroll: true,
autoScroll:true
});
var root = new Ext.tree.AsyncTreeNode({
text: this.name,
draggable:false,
id: this.name
});

this.tree.setRootNode(root);

this.tree.getRootNode().expand();
Ext.MessageBox.wait('Please Wait...');
this.tree.on('beforeload',this.changeURL,this);
this.tree.getRootNode().on('load',this.hideMessage,this);
this.add(this.tree,this.content);
},
changeURL : function (node,event){
this.tree.loader.dataUrl = .Config.baseURL+.Config.context +'ComponentServiceServlet?action=getFiles&name='+node.id+'&cid='+this.id;
},
hideMessage:function(){
var cs = this.tree.getRootNode().childNodes;
for(var i = 0, len = cs.length; i < len; i++) {
if(cs[i].leaf === undefined) {
cs[i].expand();
/* cs[i].on('expand', function(){
for(var x = 0; x < this.childNodes.length; x++) {
if(this.childNodes[x].leaf === undefined) {
this.childNodes[x].expand();
}
}
},cs[i]);*/
}
}
Ext.MessageBox.hide();
},
getTextContent : function(name){
textPanel=this.content;
Ext.Ajax.request({
url : .Config.baseURL+name ,
success: function ( result, request ) {
textPanel.el.dom.childNodes[1].childNodes[0].innerHTML='<textarea name="textarea" cols="111" rows="46" readonly="true" WRAP="SOFT">'+result.responseText+'</textarea>';
},
failure: function ( result, request) {

}
});
}

});

Ext.reg('ComponentFileBrowser', .Components.ComponentFileBrowser);