Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Alexander on Jun 16, 2009 08:45
open dhtmlx forum
dhtmlxTree; dhtmlxDataProcessor - cannot cancel node update

Hello,

I use dnd moving nodes to change their order and so on (without mercy). If I got error on server side i get next xml:
<data>
<action sid='136' pid='485' type='errorUpdate'>Can't move category.</action>
</data>
On client side I made the handler where I want to replace this item back
function updateErrorHandler(tag) {
    var sid = tag.getAttribute("sid");
    var pid = tag.getAttribute("pid");

// I tried with deletion of the moved item and without, but it doesn't work
//    tree.deleteItem(sid, false);
//    tree.deleteItem(sid, false);
    myDataProcessor.setUpdated(sid, false);

// next i try to return previous state
                    
//    tree.refreshItems(sid, "admin_menuXML.php"); // i tried such way, no correct result
//    tree.smartRefreshItem(sid, "admin_menuXML.php"); // i tried such way, no correct result                    
    tree.smartRefreshBranch(sid, "admin_menuXML.php"); // no correct result
//    tree.smartRefreshBranch(pid, "admin_menuXML.php"); // no correct result
                    
return false;
}

I cannot restore previous state of the items if server error occurred. Please advise the right way.

Thanks.
Regards,
Alex.
Answer posted by Alex (support) on Jun 17, 2009 02:24

Hello,

the tree.smartRefreshBranch(sid, "admin_menuXML.php"); method refreshes branch where sid is parent. So, that is not what you need if you want to refresh the whole tree.�

Possibly the following can be used: tree.smartRefreshBranch(0, "admin_menuXML.php?id="+0);

Or you can get the parent id and item position before item is moved:

var parent = 0;
var index = 0;
tree.attachEvent("onBeforeDrag",function(sourceId){
�parent = tree.getParentId(sourceId);
�index = tree.getIndexById(sourceId);
�return true;
})�
And if the error response is got, you can restore the item position using moveItem method (deleteItem and insertNewNext methods).

Answer posted by Alexander on Jun 18, 2009 01:30
I have written next function:

               function updateErrorHandler(tag) {
                    var sid = tag.getAttribute("sid");
                                                         
                    var chCount = tree.hasChildren(parentBeforeMove);
                    var target, mode;
                    if (chCount == 0) {
                        target = parentBeforeMove;
                        mode = 'item_child';
                    } else {
                        if (indexBeforeDelete > 0) {
                            target = indexBeforeMove-1;
                            mode = 'item_sibling_next';
                        } else {
                            target = indexBeforeMove;
                            mode = 'item_sibling';
                        }
                        target = tree.getChildItemIdByIndex(parentBeforeMove, target);
                    }
                    tree.moveItem(sid, mode, target);
                   
                    return false;
                }

Where indexBeforeMove and parentBeforeMove saved like you showed before.
This function works right, but tree.moveItem(sid, mode, target) generates dhtmlxdataprocessor request and server returns error again and dhtmlxdataprocessor requests to server again and again, please advise how is possible to don't send server request via my tree.moveItem(sid, mode, target)? I use dhtmlxtree 1.6

Thanks.
Answer posted by Alex (support) on Jun 18, 2009 04:34

Hello,�

sorry for the missleading information. Yes, moveItem also calls onDrag and onDrop events - and server-side update.

You can try to do the following to avoid server-sdie request on moveItem call:

- try to set some variable where the id of moved item is placed, for example - moved_id:

�moved_id=sid;
�tree.moveItem(sid, mode, target); �

- set onDrag event that will disable automatic update
tree.attachEvent("onDrag",function(sid,tid){
� if(sid==moved_id)
� DataProcessor.setUpdateMode("off");
� return true
�})

�- then you need to modify the code of dhtmlxdataprocessor.js, here please locate following code:

this.obj.attachEvent("onDrop",function(id,id_2,id_3,tree_1,tree_2){
� if (tree_1==tree_2)
� self.setUpdated(id,true);
});

and replace it with (add the highlighted part):

this.obj.attachEvent("onDrop",function(id,id_2,id_3,tree_1,tree_2){
if(typeof(moved_id)!="undefined"&&id==moved_id){
� self.setUpdated(moved_id,false);
� moved_id=0;
� self.setUpdateMode("cell");
� return
� }�

� if (tree_1==tree_2)
� self.setUpdated(id,true);
});



Answer posted by Alexander on Jun 18, 2009 09:25
Hello,

ok, I understood the trick you've offered, but the version of my dhtmlxdataprocessor.js is 1.0 so it hasn't such code. I've added it to my own onDrop event handler but had no effect. Is it possible to resolve this problem the other way?

Thank you.
Alexander.

Answer posted by Alexander on Jun 18, 2009 09:47
Oh, sorry, I found it, it's a bit different from yours - this.obj.setDropHandler(...

It seems that the problem resolved :) But I've noticed that moveItem inserts item not in right place now, I'll try to figure it out.

Thank you very much!