Swapping in treeview gives error

1 posts, 0 answers
  1. Heamraj
    Heamraj avatar
    1 posts
    Member since:
    Feb 2009

    Posted 18 Feb 2009 Link to this post

    I am dragging items between the nodes. I am getting the error if i swap two nodes on the same level. could any one help me. The sample code is here. I have tested with 3 levels of nodes

     

     
        <script language="javascript" type="text/javascript">  
     
                    function onNodeDropping(sender, args)  
                    {             
                        var dest = args.get_destNode();  
                        if (dest)  
                        {   
                                clientSideEdit(sender, args);  
                                args.set_cancel(true);  
                                return;  
                          
                            //dropOnTree(args);  
                        }  
                        else  
                        {   
                            dropOnHtmlElement(args);  
                        }  
                    }  
                      
          
                    function clientSideEdit(sender, args)  
                    {  
                        if(isValidDrop(sender,args)==false)  
                        {  
                            args.set_cancel(true);  
                              
                            return;  
                        }     
    var destinationNode = args.get_destNode();                      
        if(destinationNode)     
        {                    
            var firstTreeView = $find('trvOne');     
            var secondTreeView = $find('trvOne');     
             
            firstTreeView.trackChanges();     
           // secondTreeView.trackChanges();     
            var sourceNodes = args.get_sourceNodes();     
              
                var sourceNode = sourceNodes[0];     
                sourceNode.get_parent().get_nodes().remove(sourceNode);                          
                     
                //if(args.get_dropPosition() == "over") destinationNode.get_nodes().add(sourceNode);                                                           
                //if(args.get_dropPosition() == "above")  insertBefore(destinationNode, sourceNode);     
                //if(args.get_dropPosition() == "below")  insertAfter(destinationNode, sourceNode);     
                insertBefore(destinationNode, sourceNode);    
                //sourceNode.clone();  
     
            destinationNode.set_expanded(true);     
     
            firstTreeView.commitChanges();     
            //secondTreeView.commitChanges();     
        }     
     
                    }  
                      
                    function insertBefore(destinationNode, sourceNode)  
                    {  
                        var destinationParent = destinationNode.get_parent();  
                        var index = destinationParent.get_nodes().indexOf(destinationNode);  
                        destinationParent.get_nodes().insert(index, sourceNode);  
                    }  
                      
                    function insertAfter(destinationNode, sourceNode)  
                    {  
                        var destinationParent = destinationNode.get_parent();  
                        var index = destinationParent.get_nodes().indexOf(destinationNode);  
                        destinationParent.get_nodes().insert(index+1, sourceNode);  
                    }                 
     
                      
                    function isValidDrop(sender, args)  
                    {  
                      
                        var tree = $find('trvOne');  
                        var sourceNode = args.get_sourceNode();  
                        var destinationNode = args.get_destNode();        
                          
                        var sourceNodeLevel;  
                        var destinationNodeLevel;  
                        sourceNodeLevel=getNodeLevel(sourceNode);  
                        destinationNodeLevel=getNodeLevel(destinationNode);  
                          
                        if(sourceNodeLevel==destinationNodeLevel)  
                            return true;  
                        else      
                            return false;  
                        /*                
                        if(!sourceNode.get_parent())  
                        {  
                            args.set_cancel(true);  
                            tree._clearDrag();  
                            return false;  
                        }  
                        if(sourceNode.get_parent() && !(sourceNode.get_parent().get_parent()))  
                        {  
                            args.set_cancel(true);  
                            tree._clearDrag();  
                            return false;  
                        }  
                        if(sourceNode.get_parent() && sourceNode.get_parent().get_parent() && !(sourceNode.get_parent().get_parent().get_parent()))  
                        {  
                            args.set_cancel(true);  
                            tree._clearDrag();  
                            return false;  
                        }  
                        */  
                          
                    }  
                      
                      
                    function getNodeLevel(node)  
                    {  
                        var FirstParent;  
                        var SecondParent;  
                        var ThirdParent;  
                          
                        var Level;  
                          
                        FirstParent=node.get_parent();  
                        if(FirstParent)  
                            SecondParent=FirstParent.get_parent();  
                        if(SecondParent)  
                            ThirdParent=SecondParent.get_parent();  
                          
                        if(ThirdParent)  
                            Level=3;  
                        else if(SecondParent)  
                            Level=2;  
                        else if(FirstParent)  
                            Level=1;  
     
                                      
                        return Level;  
                          
                    }  
                      
                    function dropOnHtmlElement(args)  
                    {                     
                        var target = args.get_htmlElement();  
                          
                        if (target.tagName == "SELECT" && target.id=='lstShortCut')  
                        {  
                      
                            if(getNodeLevel(args.get_sourceNode())!=3)  
                            {  
                                args.set_cancel(true);  
                                return;  
                            }  
                                  
                            target.style.cursor = "default";  
                            //target.value = args.get_sourceNode().get_text();        
                              
                            var sourceNodeValue=args.get_sourceNode().get_value();  
                            for(var i=0;i<target.options.length;i++)  
                            {  
                                if(target.options[i].value==sourceNodeValue)  
                                {  
                                    args.set_cancel(true);  
                                    return true;  
                                }  
                            }                         
                              
                            var newnewOpt = new Option( args.get_sourceNode().get_text(), args.get_sourceNode().get_value(), true, false);  
                            target.options[target.options.length] = newOpt;  
                          
                            args.set_cancel(true);  
                            return true;  
                        }                                     
                    }  
                      
                      
                      
                  
     
        </script> 
     
     
    <radT:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                                                        <AjaxSettings> 
                                                                <radT:AjaxSetting AjaxControlID="trvOne">  
                                                                    <UpdatedControls> 
                                                                        <radT:AjaxUpdatedControl ControlID="trvOne" /> 
                                                                    </UpdatedControls> 
                                                                </radT:AjaxSetting> 
                                                            </AjaxSettings> 
                                                        </radT:RadAjaxManager> 
                                            <radT:RadTreeView ID="trvOne" runat="server"   
                                                EnableViewState="true" SingleExpandPath="true" EnableDragAndDrop="true" OnClientNodeDropping="onNodeDropping"   Height="350px">  
     

     

     

     

     

     

Back to Top