1

I have this rather long pre-AMD code that creates a dijit.tree from a dojo.data.ItemFileWriteStore. It works fine in general but I've tried to implement copying of tree nodes by DnD and I'm not sure about the procedure.

Currently, if I copy a tree item to a different position by holding Ctrl while dragging, the resulting item seems to be a 100% identical one. Meaning: if I then click either of them and invoke its deletion, both get removed from the tree. Here's the delete code invoked by a click event handler:

var item = tree.selectedItem;
var yes = confirm('you sure?');
if (yes) {
    var xhrArgs = {
        url:"path/to/xhr.php",
        handleAs:"text",
        preventCache:true,
        content:{
            action:"delete",
            obj:item.name[0],
            pages_id:item.pages_id[0]
        },
        load:function (content, request) {
            if (request.xhr.status == 200)
                store.deleteItem(item);
        }
    };
    dojo.xhrPost(xhrArgs);
}

Is there anything special I have to do when the tree model's pasteItem (dijit.tree.ForestStoreModel) XHR callback returns? Right now I'm doing nothing with the tree because I expected the tree to not put itself into a non-valid state (duplicate nodes).

dojo.connect(treeModel, 'pasteItem', function(draggedItem, oldParentItem, newParentItem, is_copy, insertIndex) {
    var pageID=draggedItem.pages_id, newParentID=newParentItem.pages_id, 
        pages= dojo.filter(newParentItem.children, function (item) {
            return (item.name != 'element');
        }), content={
            action: "move",
            parent: newParentID,
            pages_id: pageID
        };
    content.obj = 'element';
    content.elements_id = draggedItem.elements_id;
    content.is_copy=is_copy;
    content.pos= insertIndex;

    var xhrArgs = {
        url:"path/to/xhr.php",
        handleAs:"json",
        content:content,
        load: function(result, request){
            draggedItem.pages_id = newParentID;
            // do I need to do something else here?
        },
        error:function (ret) { console.error(ret); }
    };
    dojo.xhrPost(xhrArgs);
});
DanMan
  • 11,323
  • 4
  • 40
  • 61

0 Answers0