PDA

View Full Version : Asynchronous Tree remove node



zlog
22 Feb 2009, 9:35 AM
Hello,

I don't know how to remove a node from my async tree.
After ajax request my node is deleted from database, but it still appear in my view.

My code:


function processUserRemoveResult(btn) {
if (btn == 'yes') {
var node=myTree.getSelectionModel().getSelectedNode();
var pn=node.parentNode;
Ext.Ajax.request({
url:'/chat/usersStructure/removeuser.do',
params: {"name": mySelectedNode.selNode.text, "id": mySelectedNode.selNode.id},
method: 'POST',
success: function (result, request) {
var responseObj = Ext.util.JSON.decode(result.responseText);
Ext.MessageBox.alert(responseObj.type, responseObj.message);
if (responseObj.success) {
Ext.MessageBox.alert("node: "+node.parentNode.text);
//myTree.getLoader().load(myTree.getRootNode());
//node.parentNode.removeChild(node);
node.remove();
node.ui.remove();
pn.endUpdate();
}
},
failure: function(result, request) {
Ext.MessageBox.alert("Warning", "Operation had failed !");
}
});

If someone could help, tnx.

Regards
}
}

zlog
22 Feb 2009, 11:55 PM
nobody? :)

zlog
23 Feb 2009, 1:07 AM
maybe some links or some references, other than API, because I know where is API.

Animal
23 Feb 2009, 1:12 AM
You're going to have to do that horrible thing that nobody wants to do!

Arg! debugging! By steppng through code! Argh! Horror! Nooooooooooooooooooooo! Somebody else do it!!!!!!!!!!!!!!!!!!!!!!

zlog
23 Feb 2009, 3:54 AM
Well I debugged two days on these and tried 3 days to figure out what's wrong. So that's why I wrote on these forum. I told myself that maybe someone used this async tree.

But maybe you are just another user who thinks that debugging 3 months instead of asking someone on a forum that can help you is better, then you're the man.

Animal
23 Feb 2009, 4:11 AM
No.

Did you set a breakpoint at the line



node.remove();


And examine the node variable? Step into the remove() call? See what happened?

We are not magicians. We cannot debug remotely. If I was in your position, I would have to debug, and not rely on someone saving me.

I've been in your position often. In a complex class, a mysterious bug. I just had to plough through the code examinnig what was happening line by line by line by line.

zlog
23 Feb 2009, 4:47 AM
:), ok but it's not easy to debug some none indented code

Animal
23 Feb 2009, 5:31 AM
Indent your code then.

zlog
13 Mar 2009, 2:39 AM
The problem was that I had a listener on that tree like this:

listeners:{
'render':function(tp) {
tp.getSelectionModel().on('selectionchange', function(selModel, node) {
selectedFolder = node.text;

When I comment this line "selectedFolder = node.text;" then it works. If not I get an error "Result of expression 'node' [null] is not an object." in Safari developer 4 Beta.

Tnx Animal, for your help.

Animal
13 Mar 2009, 3:04 AM
It is perfectly valid for that to be null.

If the use deselected a node (Which will happen with a single selection model before a new node is selected), then that will be null.

zlog
13 Mar 2009, 3:16 AM
How to do then the delete action?


folderTree.getSelectionModel().getSelectedNode().remove();
folderTree.getSelectionModel().select(folderTree.getRootNode());

This is not good

Animal
13 Mar 2009, 3:18 AM
What?

What are you talking about?

jsakalos
13 Mar 2009, 3:44 AM
Have you seen this: http://remotetree.extjs.eu? It contains answer to your original question.

zlog
13 Mar 2009, 3:45 AM
Well, I have these listener on my tree:


listeners:{
'render':function(thisComponent) {
thisComponent.getSelectionModel().on('selectionchange', function(selModel, node) {
selectedFolder = node.text;
buttonReplayMessage.disable();
buttonForwardMessage.disable();
contentPanel.setTitle(selectedFolder);
mainTabPanel.setActiveTab(contentPanel);
updatemessages(selectedFolder);
updateFolderButtons();
});
}
}

also on a button from my tree toolbar I have a delete function handler:


function deleteFolderHandler() {
var nodeBeforeDelete = folderTree.getSelectionModel().getSelectedNode();
folderTree.getSelectionModel().unselect(nodeBeforeDelete);
nodeBeforeDelete.remove();
folderTree.getSelectionModel().select(folderTree.getRootNode());
}

The problem is that if I uncomment this line "selectedFolder = node.text;" from my tree listener, there is no update in my tree UI, and my node is not deleted.

I know that I do something wrong but how can I do these correctly. I think that I must change the selection before remove, but after I tried this is the same thing.

Animal
13 Mar 2009, 3:46 AM
node might be null!

jsakalos
13 Mar 2009, 3:46 AM
See my post above.

zlog
13 Mar 2009, 4:10 AM
Jsakalos I had seen your example, but I don't understand what's wrong at my code now. :) even after I had seen your code.

Anyway tnx.

zlog
13 Mar 2009, 4:12 AM
Animal, how's that possible to be null ? It's correct is null but how's that possible I changed selection to my root node before I deleted the old selection.

Animal
13 Mar 2009, 4:12 AM
if (node) {
...
}


?

zlog
13 Mar 2009, 4:22 AM
Yes Animal that check solved my problem :) but i don't know why that node was null if I changed my selection just before remove.

Anyway tnx for your help :)

Animal
13 Mar 2009, 4:39 AM
Changing a selection is two steps. The old selection has to be unselected.

That fires a selectionchange event, informing any listeners that the selected node is now....... nothing!

Then the new node is selected, and another selectionchange event is fired.

zlog
13 Mar 2009, 5:30 AM
Ok, tnx