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

Docking index problem

1 Answer 53 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Stuart
Top achievements
Rank 1
Stuart asked on 29 Sep 2008, 12:20 PM
Hi Guys

I have been working on a dynamic docking environment over the last few weeks and I made some very good progress loading dynamic zone layouts and adding docks to them with widgets, now at the moment i am a bit stuck regarding the drag and drop function , becuase everytime i drop a dock into the first index(top) of another zone it jumps back to its original position but when i drop it at the bottom of another zone it work perfectly and adds the dock to the zone correctly

First i set the layout (framework of the page) I declared a array of DockZones (5) then i initilise them in a for loop , load all the widget docks then add them to the page.
private void SetLayout(string layouts)  
    {  
        for (int i = 0; i < zone.Length; i++)  
        {  
            zone[i] = LoadZone(pageID, langID, i);  
            zone[i].Skin = "Default";  
            zone[i].ID = "ZoneLayout" + i;  
 
        }  
        Table tt = WebCMSTemplate.WidgetHelpers.WidgetHelper.GetLayout1(zone[0], zone[1], zone[2], zone[3], zone[4]);  
        siteLayout.Controls.Add(tt);  
        tt.ID = "bodyLayoutCC";  
 
    } 

The logic that loads each zone is the LoadZone method described here, it pulls the pageID, langID and the zone number that will call the Linq statement in the database to populate it from the CMSWidgets Table. AdminEnabled is just a boolean variable that defines if it is editable or not
public RadDockZone LoadZone(string pagename, string language, int zoneid)  
    {  
        RadDockZone zone = new RadDockZone();  
          
        if (!adminEnabled)  
        {  
            zone.MinHeight = Unit.Pixel(1);  
            zone.MinWidth = Unit.Pixel(1);  
        }  
        
        CMSLayerDataContext db = new CMSLayerDataContext();  
 
        var cmsWidgets = from p in db.CMSWidgets  
                         where p.pageName.Equals(pagename) && p.language.Equals(language) && p.zoneNo.Equals(zoneid)  
                         orderby p.sequence descending  
                         select p;  
 
        foreach (CMSWidget cmswidget in cmsWidgets)  
        {  
            Control cn = LoadControl(cmswidget.controlascx);  
            cn.ID = cmswidget.widget.ToString();  
            zone.Controls.Add(CreateDockWidget(cn, cmswidget.title, true, cmswidget.widget, cmswidget.height, cmswidget.width, cmswidget.nonadminStyle));  
        }  
 
        return zone;  
    } 

The Create DockWidget is the method that createds the RadDock and adds the appropriate control to it
public RadDock CreateDockWidget(Control cont, string title, bool showTitleBar, Guid widgetId, int? height, int? width, string nonadminHandle)  
    {  
        RadDock dock = new RadDock();  
          
        dock.Title = "Dock";  
        dock.Text = string.Format("Added at {0}", DateTime.Now);  
        dock.Width = Unit.Pixel(300);  
        dock.Skin = "Default";  
        dock.UniqueName = widgetId.ToString();  
        dock.ID = "dock(" + widgetId.ToString() + ")";  
 
        dock.Commands.Add(new DockExpandCollapseCommand());  
 
          
        //dock.Title = title;  
        dock.Title = dock.ID;  
        if (height.HasValue)  
        {  
            dock.Height = Unit.Pixel(int.Parse(height.ToString()));  
        }  
        if(width.HasValue)  
        {  
            dock.Width = Unit.Pixel(int.Parse(width.ToString()));  
        }  
        dock.ContentContainer.Controls.Add(cont);  
        dock.DockMode = DockMode.Docked;  
        if (adminEnabled)          
        {  
            dock.Commands.Add(new DockCloseCommand());  
            dock.DockHandle = DockHandle.TitleBar;  
            dock.AutoPostBack = true;  
        }  
        else 
        {  
            if (nonadminHandle != null)  
            {  
                if (nonadminHandle.Equals("Title"))  
                {  
                    dock.DockHandle = DockHandle.TitleBar;  
                }  
                else if (nonadminHandle.Equals("Grip"))  
                {  
                    dock.DockHandle = DockHandle.Grip;  
                }  
                else 
                {  
                    dock.DockHandle = DockHandle.None;  
                }  
            }  
            else 
            {  
                dock.DockHandle = DockHandle.None;  
            }  
            dock.EnableDrag = false;              
        }  
 
        dock.DockPositionChanged += new DockPositionChangedEventHandler(dock_DockPositionChanged);  
        return dock;  
    } 
As you can see I have registered my DockPositionChanged EventHander correctly and it makes the call to this method:

protected void dock_DockPositionChanged(object sender, DockPositionChangedEventArgs e)  
    {  
        RadDock dd = (RadDock)sender;        
          
        string guid = dd.ID.Substring(5, dd.ID.Length -(6));  
          
        WebCMSTemplate.WidgetHelpers.WidgetHelper.ChangeWidgetZone(guid, int.Parse(e.DockZoneID.Replace("ZoneLayout","")), e.Index);  
        Response.Redirect(Request.Url.ToString());  
    } 
if gets the guid string from the dock ID to properly reference to correct widget id

And lastly the ChangeWidgetZone property gets called to change teh zone and index  in the database before the page gets redirected to itself(to reload everything from top)
public static void ChangeWidgetZone(string widgetid, int zone, int index)  
        {  
            CMSLayerDataContext db = new CMSLayerDataContext();  
 
            CMSWidget widget = db.CMSWidgets.First(p => p.widget.Equals(widgetid));  
            widget.zoneNo = zone;  
            widget.sequence = index;  
 
            db.SubmitChanges();  
        } 

Now all this runs fine and works as expected except in the drag drop case where I dont drop the dragged widget to the last entry in the relevant zone

I used LINQ to code the database logic.

Any help will be welcome thanx

1 Answer, 1 is accepted

Sort by
0
Stuart
Top achievements
Rank 1
answered on 29 Sep 2008, 12:49 PM
found the fix

IT is best to load the zones and docks in a RadDockLayout LoadLayout event, not sure if it is Init or Pre-Init But it seemed to have fixed the problem,

Also I was able to remove the Reponse.Redirect out of the DockDragDrop event

Tags
Dock
Asked by
Stuart
Top achievements
Rank 1
Answers by
Stuart
Top achievements
Rank 1
Share this question
or