This is a migrated thread and some comments may be shown as answers.

Checking only one dock in a zone script

3 Answers 105 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Alec
Top achievements
Rank 1
Alec asked on 10 Jul 2009, 03:47 AM
I have got my script working to restrict only one dock in a zone.

But the problem I am having is, it works only if I drag the dock below the current dock. Say there are two zones:

Zone Destination
---------------------------
Dock A

Zone Origin
---------------------------
Dock B

I am moving Dock B to Zone Destination, when it is dropped, the script will check if Zone Destination has more than 1 dock, if so, remove old dock and replace with new dock. Old dock will get sent back to Zone Origin.

It works fine, but only if I drag Dock B below Dock A. If I drag Dock B above Dock A, it will just append to the zone.

What am I missing here?

Here's the script:

 <script type="text/javascript">  
 
     function SetHandleDock(dock, args) {  
 
         dock.set_handle(document.getElementById(dock.get_id()));  
 
     }  
 
     var dockZoneID;  
     function checkMaximumDock(dock) {  
         var selectionZone = $find('<%= radDockZone.ClientID %>');  
         var newDockZoneID = dock.get_dockZoneID();  
         //if the dock is floated or dropped in the selection zone return    
         if (newDockZoneID == '' || selectionZone.get_clientID() == newDockZoneID) return;  
 
         if (dockZoneID != newDockZoneID) {  
             var dockZone = $find(newDockZoneID);  
             var docks = dockZone.get_docks();  
             if (docks.length > 1) {  
                 var oldDock = docks[0];  
                 oldDock.undock();  
                 selectionZone.dock(oldDock);  
                 dockZone.dock(dock);  
             }  
         }  
     }  
 
     function OnClientDragStart(dock) {  
         dockZoneID = dock.get_dockZoneID();  
          
     }    
      
 </script> 

For dock B:

radDock.OnClientDragEnd = "checkMaximumDock";  
radDock.OnClientDragStart = "OnClientDragStart"

3 Answers, 1 is accepted

Sort by
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 14 Jul 2009, 12:49 PM
If you dock a DockB above DockA -> dock[0] will be DockB. You can add a if else condition, e.g.

var oldDock;
if(docks[0].get_id()==dock.get_id())
{
    oldDock = docks[1];
}
else
{
    oldDock = docks[0];
}
Hope this helps.
0
Alec
Top achievements
Rank 1
answered on 30 Jul 2009, 02:11 AM
Is there anyway I could do this check on server side ajax?
0
Jim
Top achievements
Rank 1
answered on 03 Aug 2009, 12:46 PM
I think in general it is better to do this check on the client-side. It is a lot faster and you do not need a postback just to check if a condition is satisfied. However, if you need to do it you can handle the OnDockPositionChanged event and check the condition accordingly. The event handler should be similar to the following (note that this is not a complete code, just an example of how it can be done):

protected void RadDock_DockPositionChanged(object sender, DockPositionChangedEventArgs e) 
    RadDock oldDock = new RadDock(); 
    RadDock dock = (RadDock)sender; 
 
 
        /// get the docking zone 
    RadDockZone dockingZone = (RadDockZone)FindControl(e.DockZoneID); 
     
        /// a way to do the check 
    if (dockingZone.Docks[0].ID == dock.ID) 
    { 
        oldDock = dockingZone.Docks[1]; 
    } 
    else 
    { 
        oldDock = dockingZone.Docks[0]; 
    } 

Tags
Dock
Asked by
Alec
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
Alec
Top achievements
Rank 1
Jim
Top achievements
Rank 1
Share this question
or