Drag in from div with dataprocessor fails after first try

Hi

I have divs that I use to drag onto a tree to create new nodes. I am using the dataprocessor to update the tree in our database, but something strange is happening to the div id after the first time the div is dropped.

I’ve changed the divs id and newchild id so they are different, to try and resolve any issues with referencing, but it hasn’t sorted the problem.

<div id="franchise" ><div style="cursor:pointer;"><img src="/dhtmlx/codebase/imgs/custom/treefranchise.png" width="18px" height="18px" />Franchise</div></div>
tree.makeDragable("franchise", function(drop_obj, source_id, target_on, target_before) {
	drop_obj.insertNewChild(target_on, "newnode_franchise", "NEW franchise",0,"treefranchise.png","treefranchiseOpen.png","treefranchiseClosed.png");
});

Scenario

  1. drag div into tree

  2. new node is added and is in bold

  3. alert from debug showing url and response of:- <?xml version="1.0" encoding="iso-8859-1"?>Node creation successful

  4. new node is un-bolded

  5. drag div into tree

  6. new node is added and is in bold

  7. drag div into tree

  8. new node is added and is in bold
    9 alert from debug showing url with wierd sid and response of :- <?xml version="1.0" encoding="iso-8859-1"?>Node type franchise_129777389441 not allowed

[code]

Tree
Franchise
Group
Location
Department
				<div id="rubbish" ><div style="cursor:arrow;"><img src="/dhtmlx/codebase/imgs/custom/bin.gif" width="18px" height="18px" /></div></div>

			</td>
		</tr>
	</table>
	<script language="javascript" type="text/javascript">

function _rclick(id) {
document.getElementById(“response”).innerHTML = ‘Right click:’ + id;
return false;
}
function insert_error(node) {
var div = document.createElement(“div”);
tree.deleteItem(node.getAttribute(“sid”), true);
div.innerHTML=node.firstChild.data;
document.getElementById(‘response’).appendChild(div);

			return true;
		}
		function delete_error(node) {
			tree.saveOpenStates();
			tree.deleteChildItems(0);
			tree.loadXML("tree_feed.php?id=0");
			var div = document.createElement("div");
			div.innerHTML=node.firstChild.data;
			document.getElementById('response').appendChild(div);
			
			return true;
		}
		function update_error(node) {
			tree.saveOpenStates();
			tree.deleteChildItems(0);
			tree.loadXML("tree_feed.php?id=0");
			var div = document.createElement("div");
			div.innerHTML=node.firstChild.data;
			document.getElementById('response').appendChild(div);
			
			return true;
		}
		function myErrorHandler(type, desc, erData){
			refreshNode(0);
		}
		
		dhtmlxError.catchError("ALL",myErrorHandler);
		
		tree=new dhtmlXTreeObject("treeboxbox_tree", "100%", "100%", 0);
		tree.setSkin('dhx_skyblue');

tree.setOnRightClickHandler(_rclick);
tree.setImagePath(“/dhtmlx/codebase/imgs/custom/”);
tree.enableDragAndDrop(true);
tree.attachEvent(“onXLE”, function() {
tree.loadOpenStates();
});
tree.attachEvent(“onBeforeDrag”, function(sID){
var nodrag=tree.getUserData(sID,‘nodrag’);
if(nodrag==‘true’) return false;
return true;
});
var sinput=document.getElementById(‘rubbish’);
tree.dragger.addDragLanding(sinput, {
_drag : function(sourceHtmlObject, dhtmlObject, targetHtmlObject){
tree.deleteItem(sourceHtmlObject.parentObject.id, true);
}
});
tree.makeDragable(“franchise”, function(drop_obj, source_id, target_on, target_before) {
drop_obj.insertNewChild(target_on, “newnode_franchise”, “NEW franchise”,0,“treefranchise.png”,“treefranchiseOpen.png”,“treefranchiseClosed.png”);
});
tree.makeDragable(“group”, function(drop_obj, source_id, target_on, target_before) {
drop_obj.insertNewChild(target_on, “newnode_group”, “NEW group”,0,“treegroup.png”,“treegroupOpen.png”,“treegroupClosed.png”);
});
tree.makeDragable(“location”, function(drop_obj, source_id, target_on, target_before) {
drop_obj.insertNewChild(target_on, “newnode_location”, “NEW location”,0,“treelocation.png”,“treelocationOpen.png”,“treelocationClosed.png”);
});
tree.makeDragable(“department”, function(drop_obj, source_id, target_on, target_before) {
drop_obj.insertNewChild(target_on, “newnode_department”, “NEW department”,0,“treedepartment.png”,“treedepartmentOpen.png”,“treedepartmentClosed.png”);
});
tree.loadXML(“tree_feed.php?id=0”);
myDataProcessor=new dataProcessor(“update.php?uid=”+(new Date()).valueOf());
myDataProcessor.defineAction(“my_insert_error”, insert_error);
myDataProcessor.defineAction(“my_delete_error”, delete_error);
myDataProcessor.defineAction(“my_update_error”, update_error);
myDataProcessor.init(tree);

<?xml version="1.0" encoding="iso-8859-1"?>Node creation successful <?xml version="1.0" encoding="iso-8859-1"?>Node type franchise_129777389441 not allowed[/code]

I assume this is a result of dragging something onto the tree, because the id of the new element changes, it also changes the original div, as they have the same id.

A little progress.

I’ve done some debugging and the divs ID does not change. The ID is definately being generated by the tree, IF the id already exists.
So on the first attempt id ‘newnode_franchise’ doesnt exist so id stays the same. The second time the id ‘newnode_franchise’ still doesnt exist, as it has been changed by dataprocessor to ‘35’, but fails to update so remains unchanged (‘newnode_franchise’). The third time the id ‘newnode_franchise’ exists and tree generates its own id ‘newnode_franchise_342553534’. But who knows what happens the second time for it to fail?

I have removed the numbers from the sid when inserting the new node in the database and the backend works fine, giving the correct response, so now if things do go wrong, the user can continue to work. But the failed second attempt still shows as a bold entry with no call to the dataprocessor.

I’ve added the dhtmlxdataprocessor_debug.js and get the following. To avoid confusion, I’ve seperated the three actions with —. (3x drag same div to same top level node in tree)

Log:
row newnode_franchise marked [inserted,valid]
Initiating data sending for newnode_franchise
Sending in one-by-one mode, current ID = newnode_franchise
Server url: update.php?uid=1297865209782 parameters

newnode_franchisetr_id = newnode_franchise
tr_pid = 1
tr_order = 2
tr_text = NEW franchise
!nativeeditor_status = inserted

Server response received details

<?xml version="1.0" encoding="iso-8859-1"?><data><action type="insert" sid="newnode_franchise" tid="1554">Node creation successful</action></data>

Action: insert SID:newnode_franchise TID:1554
row newnode_franchise unmarked [updated,valid]


row newnode_franchise marked [inserted,valid]
Initiating data sending for newnode_franchise

row newnode_franchise_1297865270030 marked [inserted,valid]
Initiating data sending for newnode_franchise_1297865270030
Sending in one-by-one mode, current ID = newnode_franchise_1297865270030
Server url: update.php?uid=1297865209782 parameters

newnode_franchise_1297865270030tr_id = newnode_franchise_1297865270030
tr_pid = 1
tr_order = 4
tr_text = NEW franchise
!nativeeditor_status = inserted

Server response received details

<?xml version="1.0" encoding="iso-8859-1"?><data><action type="insert" sid="newnode_franchise_1297865270030" tid="1555">Node creation successful</action></data>

Action: insert SID:newnode_franchise_1297865270030 TID:1555
row newnode_franchise_1297865270030 unmarked [updated,valid]
Initiating data sending for all rows

Anyone got anything to say about this???

Unfortunately we cannot reproduce this issue locally.

9 alert from debug showing url with wierd sid and response of :- <?xml version="1.0" encoding="iso-8859-1"?>Node type franchise_129777389441 not allowed
You should check your server side code why it returns error response. Client side code is correct and works as expected at local example.