Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Eric on Apr 24, 2008 09:14
open dhtmlx forum
When dataProcessor fails on server-side

I have a tree that displays a hierarchy from a tree stored in a database. When a tree node is dragged within the tree, it fires a dataProcessor event that updates the db table on the server.

I can't seem to figure out how to handle failures. When the server update fails, I'm returning this:

<data>
<action type="failure" sid="11079" tid="11077" old_parent="5">
</data>

Where sid is the id of the node being moved, tid is the parent we're trying to move it under, and old_parent is the original parent_id from the database BEFORE the update.

When the backend returns a failure, I want to move the node in the HTML tree back to its original position so that the client and server don't get out of sync. My problem is that calling tree.moveItem (as shown below) causes the dataProcessor to fire again.

Is there a way to temporarily disable the dataProcessor object, move the node, then reenable the processor?


Thanks,
Eric

// my tree setup:

// use the dataProcessor to fire move_node when an item is dragged
myDataProcessor = new dataProcessor("move_node.php");
myDataProcessor.init(tree);

myDataProcessor.defineAction("failure", function(tag) {
undoMove(tag);
return true;
});


function undoMove(btag)
{
console.log(btag);

var id_moved = btag.getAttribute("sid");
var new_parent = btag.getAttribute("tid");
var old_parent = btag.getAttribute("old_parent");

// we need to take the node of id 'id_moved' and move it BACK
// from 'new_parent' to 'old_parent'

// THIS DOES NOT WORK!!!! It causes some kind of client-side infinite loop that keeps calling back to the server.
tree.moveItem(id_moved, "item_child", old_parent, null);
}
Answer posted by Support on Apr 24, 2008 10:33
>>Is there a way to temporarily disable the dataProcessor object, move the node, then reenable the processor?

dataproc.autoUpdate=false;   //stop automatic updates
var temp=dataproc.updatedRows; // save existing state

    ... any actions here ...

dataproc.updatedRows=temp; // restore previous state
dataproc.autoUpdate=true;   //restore automatic updates
Answer posted by ImportFanatik on Jul 06, 2009 15:49

I am attempting to build the same function but am stuck at the part where the "tag" is passed to the custom handling function.

myDataProcessor.defineAction("failure", function(tag) {
var id_moved = tag.getAttribute("sid");
alert("sid is:" & id_moved);

return true;
});

 

This displays "sid is 0" no matter what I do.

Any suggestions?

Thanks!

 

Answer posted on Jul 07, 2009 00:29
Please check if "failure" action returns correct responce where sid was actually set:
<data>
� <action type="failure" sid="some" tid="some" />
� </data>