| string cacheKey = "UserPreferences.PortalSession1." + HttpContext.Current.User.Identity.Name.ToString(); |
| |
| |
| private List<DockState> CurrentDockStates |
| { |
| get |
| { |
| |
| List<DockState> _currentDockStates = (List<DockState>)Cache[cacheKey]; |
| if (Object.Equals(_currentDockStates, null)) |
| { |
| //Make an empty configuration list |
| _currentDockStates = new List<DockState>(); |
| |
| //string strLoadedConfig = GetUserPreference("PortalConfiguration"); |
| |
| using (insidefbDataContext db = new insidefbDataContext()) |
| { |
| var dashboardItems = (from x in db.aspnet_Users |
| where x.aspnet_Application.ApplicationName == "/Insidefb" |
| select x).SingleOrDefault(c => c.UserName.Equals(User.Identity.Name.ToString())).dashboardItems; |
| |
| //If we found nothing, leave the current state empty |
| if (!string.IsNullOrEmpty(dashboardItems)) |
| { |
| string strLoadedConfig = dashboardItems.ToString(); |
| try |
| { |
| //Use the stored config |
| //Convert the stored config to an array, splitting at the *s |
| string[] aConfig = strLoadedConfig.Split('*'); |
| DockState dsWorking = default(DockState); |
| //Parse through the array, turning the dockstate strings into dockstates |
| //Then add the dockstates to the dockstate list |
| foreach (var strConfigItem in aConfig) |
| { |
| //Start a fresh dockstate |
| dsWorking = new DockState(); |
| //Parse the string back into dock settings |
| dsWorking = DockState.Deserialize(strConfigItem); |
| //Add the settings back into the current session |
| _currentDockStates.Add(dsWorking); |
| } |
| } |
| catch |
| { |
| } |
| |
| Cache[cacheKey] = _currentDockStates; |
| } |
| } |
| |
| } |
| return _currentDockStates; |
| } |
| set |
| { |
| Cache[cacheKey] = value; |
| |
| System.Text.StringBuilder sbListConverter = new System.Text.StringBuilder(); |
| foreach (DockState dockState in value) |
| { |
| sbListConverter.AppendFormat("{0}*", dockState.ToString()); |
| } |
| string strDockConfig = sbListConverter.ToString().TrimEnd(Convert.ToChar("*")); |
| using (insidefbDataContext db = new insidefbDataContext()) |
| { |
| |
| aspnet_User activeUser = (from x in db.aspnet_Users |
| where x.aspnet_Application.ApplicationName == "/Insidefb" |
| select x).SingleOrDefault(c => c.UserName.Equals(User.Identity.Name.ToString())); |
| |
| activeUser.dashboardItems = strDockConfig; |
| db.SubmitChanges(); |
| } |
| } |
| } |
| |
| protected void Page_Init(object sender, EventArgs e) |
| { |
| //Recreate the docks in order to ensure their proper operation |
| for (int i = 0; i < CurrentDockStates.Count; i++) |
| { |
| if (CurrentDockStates[i].Closed == false) |
| { |
| RadDock dock = CreateRadDockFromState(CurrentDockStates[i]); |
| RadDockLayout1.Controls.Add(dock); |
| CreateSaveStateTrigger(dock); |
| LoadWidget(dock); |
| } |
| } |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| LoadControlsCheckbox(); |
| } |
| } |
| |
| protected void LoadControlsCheckbox() |
| { |
| |
| IFBF.AspNet.Membership.IFBFMembership xEntity = new IFBF.AspNet.Membership.IFBFMembership(); |
| int entityid = xEntity.getEntityid(HttpContext.Current.User.Identity.Name); |
| |
| using (insidefbDataContext db = new insidefbDataContext()) |
| { |
| |
| countysecurity userCounty = (from z in db.countysecurities |
| where z.entityid.Equals(entityid) |
| select z).FirstOrDefault<countysecurity>(); |
| //if (userCounty != null) |
| if (true) |
| { |
| cbxWebParts.Items.Clear(); |
| ListItem itAlerts = new ListItem(); |
| itAlerts.Text = "Alerts"; |
| itAlerts.Value = "~/admin/dashboard/Alerts.ascx"; |
| cbxWebParts.Items.Add(itAlerts); |
| ListItem itTask = new ListItem(); |
| itTask.Text = "Tasks"; |
| itTask.Value = "~/admin/dashboard/Task.ascx"; |
| cbxWebParts.Items.Add(itTask); |
| } |
| if (User.IsInRole("MembershipAdmin") || User.IsInRole("membershipreadonly")) |
| { |
| ListItem itReports = new ListItem(); |
| itReports.Text = "Reports"; |
| itReports.Value = "~/admin/dashboard/Reports.ascx"; |
| cbxWebParts.Items.Add(itReports); |
| } |
| if (User.IsInRole("webAdmin")) |
| { |
| ListItem itWebAdmin = new ListItem(); |
| itWebAdmin.Text = "Web Admin"; |
| itWebAdmin.Value = "~/admin/dashboard/webadmin.ascx"; |
| cbxWebParts.Items.Add(itWebAdmin); |
| } |
| if (User.IsInRole("employee")) |
| { |
| ListItem employee = new ListItem(); |
| employee.Text = "Employee"; |
| employee.Value = "~/admin/dashboard/Employee.ascx"; |
| cbxWebParts.Items.Add(employee); |
| } |
| } |
| |
| //ListItem itQuotes = new ListItem(); |
| //itQuotes.Text = "Quotes"; |
| //itQuotes.Value = "~/admin/dashboard/Quotes.ascx"; |
| //cbxWebParts.Items.Add(itQuotes); |
| //ListItem itWeather = new ListItem(); |
| //itWeather.Text = "Weather"; |
| //itWeather.Value = "~/admin/dashboard/Weather.ascx"; |
| //cbxWebParts.Items.Add(itWeather); |
| } |
| |
| protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e) |
| { |
| //Populate the event args with the state information. The RadDockLayout control |
| // will automatically move the docks according that information. |
| foreach (DockState state in CurrentDockStates) |
| { |
| e.Positions[state.UniqueName] = state.DockZoneID; |
| e.Indices[state.UniqueName] = state.Index; |
| } |
| } |
| |
| protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e) |
| { |
| //Save the dock state in the session. This will enable us |
| // to recreate the dock in the next Page_Init. |
| CurrentDockStates = RadDockLayout1.GetRegisteredDocksState(); |
| } |
| |
| private RadDock CreateRadDockFromState(DockState Dstate) |
| { |
| RadDock dock = new RadDock(); |
| dock.ID = string.Format("RadDock{0}", Dstate.UniqueName); |
| dock.DockMode = DockMode.Docked; |
| dock.ApplyState(Dstate); |
| dock.EnableAnimation = true; |
| dock.Command += new DockCommandEventHandler(dock_Command); |
| dock.Commands.Add(new DockCloseCommand()); |
| dock.Commands.Add(new DockExpandCollapseCommand()); |
| |
| return dock; |
| } |
| |
| private RadDock CreateRadDock(string title) |
| { |
| int docksCount = CurrentDockStates.Count; |
| |
| RadDock dock = new RadDock(); |
| dock.UniqueName = Guid.NewGuid().ToString().Replace('-', 'a'); |
| dock.ID = string.Format("RadDock{0}", dock.UniqueName); |
| dock.DockMode = DockMode.Docked; |
| dock.EnableAnimation = true; |
| dock.Title = title; |
| dock.Text = string.Format("Added at {0}", DateTime.Now); |
| dock.Width = Unit.Pixel(300); |
| |
| dock.Command += new DockCommandEventHandler(dock_Command); |
| dock.Commands.Add(new DockCloseCommand()); |
| dock.Commands.Add(new DockExpandCollapseCommand()); |
| |
| return dock; |
| } |
| |
| void dock_Command(object sender, DockCommandEventArgs e) |
| { |
| if (e.Command.Name == "Close") |
| { |
| ScriptManager.RegisterStartupScript( |
| UpdatePanel1, |
| this.GetType(), |
| "RemoveDock", |
| string.Format(@"function _removeDock() {{ |
| Sys.Application.remove_load(_removeDock); |
| $find('{0}').undock(); |
| $get('{1}').appendChild($get('{0}')); |
| $find('{0}').doPostBack('DockPositionChanged'); |
| }}; |
| Sys.Application.add_load(_removeDock);", ((RadDock)sender).ClientID, UpdatePanel1.ClientID), |
| true); |
| |
| } |
| } |
| |
| private void CreateSaveStateTrigger(RadDock dock) |
| { |
| //Ensure that the RadDock control will initiate postback |
| // when its position changes on the client or any of the commands is clicked. |
| //Using the trigger we will "ajaxify" that postback. |
| dock.AutoPostBack = true; |
| dock.CommandsAutoPostBack = true; |
| |
| AsyncPostBackTrigger saveStateTrigger = new AsyncPostBackTrigger(); |
| saveStateTrigger.ControlID = dock.ID; |
| saveStateTrigger.EventName = "DockPositionChanged"; |
| UpdatePanel1.Triggers.Add(saveStateTrigger); |
| |
| saveStateTrigger = new AsyncPostBackTrigger(); |
| saveStateTrigger.ControlID = dock.ID; |
| saveStateTrigger.EventName = "command"; |
| UpdatePanel1.Triggers.Add(saveStateTrigger); |
| } |
| |
| private void LoadWidget(RadDock dock) |
| { |
| if (string.IsNullOrEmpty(dock.Tag)) |
| { |
| return; |
| } |
| try |
| { |
| Control widget = LoadControl(dock.Tag); |
| dock.ContentContainer.Controls.Add(widget); |
| } |
| catch |
| { |
| } |
| } |
| |
| |
| protected void ButtonAddDock_Click(object sender, EventArgs e) |
| { |
| foreach (ListItem li in cbxWebParts.Items) |
| { |
| if (li.Selected) |
| { |
| RadDock dock = CreateRadDock(li.Text); |
| UpdatePanel1.ContentTemplateContainer.Controls.Add(dock); |
| |
| ScriptManager.RegisterStartupScript( |
| dock, |
| this.GetType(), |
| "AddDock" + dock.ClientID, |
| string.Format(@"function _addDock() {{ |
| Sys.Application.remove_load(_addDock); |
| $find('{1}').dock($find('{0}')); |
| $find('{0}').doPostBack('DockPositionChanged'); |
| }}; |
| Sys.Application.add_load(_addDock);", dock.ClientID, chooseZone()), |
| true); |
| |
| CreateSaveStateTrigger(dock); |
| |
| //Load the selected widget in the RadDock control |
| dock.Tag = li.Value; |
| //dock.Title = DroptDownWidget.SelectedItem.Text; |
| LoadWidget(dock); |
| } |
| } |
| |
| selectModule_MPE.Hide(); |
| } |
| |
| protected string chooseZone() |
| { |
| int zoneOne = RadDockZone1.Docks.Count(); |
| int zoneTwo = RadDockZone2.Docks.Count(); |
| |
| if (zoneOne > zoneTwo) |
| { return "ctl00_ctl00_masterContent_mainContent_RadDockZone2"; } |
| else |
| { return "ctl00_ctl00_masterContent_mainContent_RadDockZone1"; } |
| } |