/// -----------------------------------------------------------------------------
/// <summary>
/// DNNTxtBannerGroup_PopulateOnDemand runs when something is entered on the
/// BannerGroup field
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [vmasanas] 9/29/2006 Implement a callback to display current groups
/// to user so the BannerGroup can be easily selected
/// </history>
/// -----------------------------------------------------------------------------
protected void DNNTxtBannerGroup_PopulateOnDemand(object source, DNNTextSuggestEventArgs e)
{
DataTable dt;
DNNNode objNode;
var objBanners = new BannerController();
dt = objBanners.GetBannerGroups(PortalId);
DataRow[] dr;
dt.CaseSensitive = false;
dr = dt.Select("GroupName like '" + e.Text + "%'");
foreach (DataRow d in dr)
{
objNode = new DNNNode(d["GroupName"].ToString());
objNode.ID = e.Nodes.Count.ToString();
e.Nodes.Add(objNode);
}
}
private static void ProcessTab(DNNNode objRootNode, TabInfo objTab, Hashtable objTabLookup, Hashtable objBreadCrumbs, int intLastBreadCrumbId, ToolTipSource eToolTips, int intStartTabId,
int intDepth, int intNavNodeOptions)
{
PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
DNNNodeCollection objRootNodes = objRootNode.DNNNodes;
bool showHidden = (intNavNodeOptions & (int)NavNodeOptions.IncludeHiddenNodes) == (int)NavNodeOptions.IncludeHiddenNodes;
if (CanShowTab(objTab, TabPermissionController.CanAdminPage(), true, showHidden)) //based off of tab properties, is it shown
{
DNNNodeCollection objParentNodes;
DNNNode objParentNode = objRootNodes.FindNode(objTab.ParentId.ToString());
bool blnParentFound = objParentNode != null;
if (objParentNode == null)
{
objParentNode = objRootNode;
}
objParentNodes = objParentNode.DNNNodes;
if (objTab.TabID == intStartTabId)
{
//is this the starting tab
if ((intNavNodeOptions & (int) NavNodeOptions.IncludeParent) != 0)
{
//if we are including parent, make sure there is one, then add
if (objTabLookup[objTab.ParentId] != null)
{
AddNode((TabInfo) objTabLookup[objTab.ParentId], objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
objParentNode = objRootNodes.FindNode(objTab.ParentId.ToString());
objParentNodes = objParentNode.DNNNodes;
}
}
if ((intNavNodeOptions & (int) NavNodeOptions.IncludeSelf) != 0)
{
//if we are including our self (starting tab) then add
AddNode(objTab, objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
}
}
else if (((intNavNodeOptions & (int) NavNodeOptions.IncludeSiblings) != 0) && IsTabSibling(objTab, intStartTabId, objTabLookup))
{
//is this a sibling of the starting node, and we are including siblings, then add it
AddNode(objTab, objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
}
else
{
if (blnParentFound) //if tabs parent already in hierarchy (as is the case when we are sending down more than 1 level)
{
//parent will be found for siblings. Check to see if we want them, if we don't make sure tab is not a sibling
if (((intNavNodeOptions & (int) NavNodeOptions.IncludeSiblings) != 0) || IsTabSibling(objTab, intStartTabId, objTabLookup) == false)
{
//determine if tab should be included or marked as pending
bool blnPOD = (intNavNodeOptions & (int) NavNodeOptions.MarkPendingNodes) != 0;
if (IsTabPending(objTab, objParentNode, objRootNode, intDepth, objBreadCrumbs, intLastBreadCrumbId, blnPOD))
{
if (blnPOD)
{
objParentNode.HasNodes = true; //mark it as a pending node
}
}
else
{
AddNode(objTab, objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
}
}
}
else if ((intNavNodeOptions & (int) NavNodeOptions.IncludeSelf) == 0 && objTab.ParentId == intStartTabId)
{
//if not including self and parent is the start id then add
AddNode(objTab, objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
}
}
}
}
//Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object)
// If m_bNodeCollectionInterfaceCall = False Then Me.InsertAfter(index, CType(value, DNNNode))
//End Sub
//Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As Object)
// If m_bNodeCollectionInterfaceCall = False Then Me.Remove(CType(value, DNNNode))
//End Sub
//Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object)
// Me.Item(index) = CType(newValue, DNNNode)
//End Sub
//Protected Overrides Sub OnClear()
// Me.Clear()
//End Sub
//Public Shadows Sub Clear()
// Dim i As Integer
// For i = Me.XMLNode.ChildNodes.Count - 1 To 0 Step -1
// Me.XMLNode.RemoveChild(Me.XMLNode.ChildNodes(i))
// Next
//End Sub
public bool Contains( DNNNode value )
{
if( this.FindNode( value.ID ) == null )
{
return false;
}
else
{
return true;
}
}
private static bool IsTabPending(TabInfo objTab, DNNNode objParentNode, DNNNode objRootNode, int intDepth, Hashtable objBreadCrumbs, int intLastBreadCrumbId, bool blnPOD)
{
//
//A
//|
//--B
//| |
//| --B-1
//| | |
//| | --B-1-1
//| | |
//| | --B-1-2
//| |
//| --B-2
//| |
//| --B-2-1
//| |
//| --B-2-2
//|
//--C
// |
// --C-1
// | |
// | --C-1-1
// | |
// | --C-1-2
// |
// --C-2
// |
// --C-2-1
// |
// --C-2-2
//if we aren't restricting depth then its never pending
if (intDepth == -1)
{
return false;
}
//parents level + 1 = current node level
//if current node level - (roots node level) <= the desired depth then not pending
if (objParentNode.Level + 1 - objRootNode.Level <= intDepth)
{
return false;
}
//--- These checks below are here so tree becomes expands to selected node ---
if (blnPOD)
{
//really only applies to controls with POD enabled, since the root passed in may be some node buried down in the chain
//and the depth something like 1. We need to include the appropriate parent's and parent siblings
//Why is the check for POD required? Well to allow for functionality like RootOnly requests. We do not want any children
//regardless if they are a breadcrumb
//if tab is in the breadcrumbs then obviously not pending
if (objBreadCrumbs.Contains(objTab.TabID))
{
return false;
}
//if parent is in the breadcrumb and it is not the last breadcrumb then not pending
//in tree above say we our breadcrumb is (A, B, B-2) we want our tree containing A, B, B-2 AND B-1 AND C since A and B are expanded
//we do NOT want B-2-1 and B-2-2, thus the check for Last Bread Crumb
if (objBreadCrumbs.Contains(objTab.ParentId) && intLastBreadCrumbId != objTab.ParentId)
{
return false;
}
}
return true;
}
private void BuildNodes(DNNNode objNode)
{
DNNNodeCollection objNodes;
objNodes = GetNavigationNodes(objNode);
Control.ClearNodes(); //since we always bind we need to clear the nodes for providers that maintain their state
Bind(objNodes);
}
/// <summary>
/// Assigns common properties from passed in tab to newly created DNNNode that is added to the passed in DNNNodeCollection
/// </summary>
/// <param name="objTab">Tab to base DNNNode off of</param>
/// <param name="objNodes">Node collection to append new node to</param>
/// <param name="objBreadCrumbs">Hashtable of breadcrumb IDs to efficiently determine node's BreadCrumb property</param>
/// <param name="objPortalSettings">Portal settings object to determine if node is selected</param>
/// <remarks>
/// Logic moved to separate sub to make GetNavigationNodes cleaner
/// </remarks>
/// <history>
/// [Jon Henning] 8/9/2005 Created
/// </history>
/// <param name="eToolTips"></param>
private static void AddNode(TabInfo objTab, DNNNodeCollection objNodes, Hashtable objBreadCrumbs, PortalSettings objPortalSettings, ToolTipSource eToolTips)
{
DNNNode objNode = new DNNNode();
if (objTab.Title == "~") // NEW!
{
//A title (text) of ~ denotes a break
objNodes.AddBreak();
}
else
{
//assign breadcrumb and selected properties
if (objBreadCrumbs.Contains(objTab.TabID))
{
objNode.BreadCrumb = true;
if (objTab.TabID == objPortalSettings.ActiveTab.TabID)
{
objNode.Selected = true;
}
}
if (objTab.DisableLink)
{
objNode.Enabled = false;
}
objNode.ID = objTab.TabID.ToString();
objNode.Key = objNode.ID;
objNode.Text = objTab.TabName;
objNode.NavigateURL = objTab.FullUrl;
objNode.ClickAction = eClickAction.Navigate;
//admin tabs have their images found in a different location, since the DNNNode has no concept of an admin tab, this must be set here
if (objTab.IsAdminTab)
{
if (objTab.IconFile != "")
{
objNode.Image = Globals.ApplicationPath + "/images/" + objTab.IconFile;
}
}
else
{
if (objTab.IconFile != "")
{
objNode.Image = objTab.IconFile;
}
}
switch (eToolTips)
{
case ToolTipSource.TabName:
objNode.ToolTip = objTab.TabName;
break;
case ToolTipSource.Title:
objNode.ToolTip = objTab.Title;
break;
case ToolTipSource.Description:
objNode.ToolTip = objTab.Description;
break;
}
objNodes.Add(objNode);
}
}
/// <summary>
/// Recursive function to add module's actions to the DNNNodeCollection based off of passed in ModuleActions
/// </summary>
/// <param name="objParentAction">Parent action</param>
/// <param name="objParentNode">Parent node</param>
/// <param name="objRootNode"></param>
/// <param name="objModule">Module to base actions off of</param>
/// <param name="objUserInfo">User Info Object</param>
/// <param name="intDepth">How many levels deep should be populated</param>
/// <remarks>
/// </remarks>
/// <history>
/// [Jon Henning] 5/15/2006 Created
/// </history>
private static void AddChildActions(ModuleAction objParentAction, DNNNode objParentNode, DNNNode objRootNode, ActionBase objModule, UserInfo objUserInfo, int intDepth)
{
// Add Menu Items
foreach (ModuleAction objAction in objParentAction.Actions)
{
bool blnPending = IsActionPending(objParentNode, objRootNode, intDepth);
if (objAction.Title == "~")
{
if (blnPending == false)
{
//A title (text) of ~ denotes a break
objParentNode.DNNNodes.AddBreak();
}
}
else
{
//if action is visible and user has permission
if (objAction.Visible & PortalSecurity.HasNecessaryPermission(objAction.Secure, (PortalSettings)(HttpContext.Current.Items["PortalSettings"]), objModule.ModuleConfiguration, objUserInfo.UserID.ToString()))
{
//(if edit mode and not admintab and not admincontrol)
if (blnPending)
{
objParentNode.HasNodes = true;
}
else
{
int i = objParentNode.DNNNodes.Add();
DNNNode objNode = objParentNode.DNNNodes[i];
objNode.ID = objAction.ID.ToString();
objNode.Key = objAction.ID.ToString();
objNode.Text = objAction.Title; //no longer including SPACE in generic node collection, each control must handle how they want to display
// HACK : Modified to not error if object is null.
//if (objAction.ClientScript.Length > 0)
if (!String.IsNullOrEmpty(objAction.ClientScript))
{
objNode.JSFunction = objAction.ClientScript;
objNode.ClickAction = eClickAction.None;
}
else
{
objNode.NavigateURL = objAction.Url;
// HACK : Modified to handle null string in objNode.NavigateURL
//if (objAction.UseActionEvent == false && objNode.NavigateURL.Length > 0)
if (objAction.UseActionEvent == false && !String.IsNullOrEmpty(objNode.NavigateURL))
{
objNode.ClickAction = eClickAction.Navigate;
}
else
{
objNode.ClickAction = eClickAction.PostBack;
}
}
objNode.Image = objAction.Icon;
if (objAction.HasChildren()) //if action has children then call function recursively
{
AddChildActions(objAction, objNode, objRootNode, objModule, objUserInfo, intDepth);
}
}
}
}
}
}
/// <summary>
/// This function provides a central location to obtain a generic node collection of the pages/tabs included in
/// the current context's (user) navigation hierarchy
/// </summary>
/// <param name="objRootNode">Node in which to add children to</param>
/// <param name="eToolTips">Enumerator to determine what text to display in the tooltips</param>
/// <param name="intStartTabId">If using Populate On Demand, then this is the tab id of the root element to retrieve (-1 for no POD)</param>
/// <param name="intDepth">If Populate On Demand is enabled, then this parameter determines the number of nodes to retrieve beneath the starting tab passed in (intStartTabId) (-1 for no POD)</param>
/// <param name="intNavNodeOptions">Bitwise integer containing values to determine what nodes to display (self, siblings, parent)</param>
/// <returns>Collection of DNNNodes</returns>
/// <remarks>
/// Returns a subset of navigation nodes based off of passed in starting node id and depth
/// </remarks>
/// <history>
/// [Jon Henning] 8/9/2005 Created
/// </history>
public static DNNNodeCollection GetNavigationNodes(DNNNode objRootNode, ToolTipSource eToolTips, int intStartTabId, int intDepth, int intNavNodeOptions)
{
int i;
PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
bool blnAdminMode = PortalSecurity.IsInRoles(objPortalSettings.AdministratorRoleName) | PortalSecurity.IsInRoles(objPortalSettings.ActiveTab.AdministratorRoles.ToString());
//bool blnFoundStart = intStartTabId == -1; //if -1 then we want all
Hashtable objBreadCrumbs = new Hashtable();
Hashtable objTabLookup = new Hashtable();
DNNNodeCollection objRootNodes = objRootNode.DNNNodes;
int intLastBreadCrumbId = 0;
TabInfo objTab;
//--- cache breadcrumbs in hashtable so we can easily set flag on node denoting it as a breadcrumb node (without looping multiple times) ---'
for (i = 0; i <= (objPortalSettings.ActiveTab.BreadCrumbs.Count - 1); i++)
{
objBreadCrumbs.Add(((TabInfo)(objPortalSettings.ActiveTab.BreadCrumbs[i])).TabID, 1);
intLastBreadCrumbId = ((TabInfo)(objPortalSettings.ActiveTab.BreadCrumbs[i])).TabID;
}
for (i = 0; i < objPortalSettings.DesktopTabs.Count; i++)
{
objTab = (TabInfo)(objPortalSettings.DesktopTabs[i]);
objTabLookup.Add(objTab.TabID, objTab);
}
for (i = 0; i < objPortalSettings.DesktopTabs.Count; i++)
{
try
{
objTab = (TabInfo)(objPortalSettings.DesktopTabs[i]);
if (IsTabShown(objTab, blnAdminMode)) //based off of tab properties, is it shown
{
DNNNode objParentNode = objRootNodes.FindNode(objTab.ParentId.ToString());
bool blnParentFound = objParentNode != null;
if (objParentNode == null)
{
objParentNode = objRootNode;
}
DNNNodeCollection objParentNodes = objParentNode.DNNNodes;
//If objTab.ParentId = -1 OrElse ((intNavNodeOptions And NavNodeOptions.IncludeRootOnly) = 0) Then
if (objTab.TabID == intStartTabId)
{
//is this the starting tab
if ((intNavNodeOptions & (int)NavNodeOptions.IncludeParent) != 0)
{
//if we are including parent, make sure there is one, then add
if (objTabLookup[objTab.ParentId] != null)
{
AddNode((TabInfo)(objTabLookup[objTab.ParentId]), objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
objParentNode = objRootNodes.FindNode(objTab.ParentId.ToString());
objParentNodes = objParentNode.DNNNodes;
}
}
if ((intNavNodeOptions & (int)NavNodeOptions.IncludeSelf) != 0)
{
//if we are including our self (starting tab) then add
AddNode(objTab, objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
}
}
else if (((intNavNodeOptions & (int)NavNodeOptions.IncludeSiblings) != 0) && IsTabSibling(objTab, intStartTabId, objTabLookup))
{
//is this a sibling of the starting node, and we are including siblings, then add it
AddNode(objTab, objParentNodes, objBreadCrumbs, objPortalSettings, eToolTips);
}
else
{
if (blnParentFound) //if tabs parent already in hierarchy (as is the case when we are sending down more than 1 level)
{
//parent will be found for siblings. Check to see if we want them, if we don't make sure tab is not a sibling
if (((intNavNodeOptions & (int)NavNodeOptions.IncludeSiblings) != 0) || IsTabSibling(objTab, intStartTabId, objTabLookup) == false)
{
//determine if tab should be included or marked as pending
bool blnPOD = (intNavNodeOptions & (int)NavNodeOptions.MarkPendingNodes) != 0;
if (IsTabPending(objTab, objParentNode, objRootNode, intDepth, objBreadCrumbs, intLastBreadCrumbId, blnPOD))
{
if (blnPOD)
{
objParentNode.HasNodes = true; //mark it as a pending node
}
}
else
//.........这里部分代码省略.........
/// <summary>
/// This function provides a central location to obtain a generic node collection of the actions associated
/// to a module based off of the current user's context
/// </summary>
/// <param name="objActionRoot">Root module action</param>
/// <param name="objRootNode">Root node on which to populate children</param>
/// <param name="objModule">Module whose actions you wish to obtain</param>
/// <param name="intDepth">How many levels deep should be populated</param>
/// <returns></returns>
/// <remarks>
/// </remarks>
/// <history>
/// [Jon Henning] 5/15/2006 Created
/// </history>
public static DNNNodeCollection GetActionNodes(ModuleAction objActionRoot, DNNNode objRootNode, ActionBase objModule, int intDepth)
{
DNNNodeCollection objCol = objRootNode.ParentNode.DNNNodes;
AddChildActions(objActionRoot, objRootNode, objRootNode, objModule, UserController.GetCurrentUserInfo(), intDepth);
return objCol;
}
/// -----------------------------------------------------------------------------
/// <summary>
/// This function provides a central location to obtain a generic node collection of the actions associated
/// to a module based off of the current user's context
/// </summary>
/// <param name="objActionRoot">Root module action</param>
/// <param name="objRootNode">Root node on which to populate children</param>
/// <param name="objControl">ActionControl to base actions off of</param>
/// <param name="intDepth">How many levels deep should be populated</param>
/// <returns></returns>
/// <remarks>
/// </remarks>
/// <history>
/// [Jon Henning] 5/15/2006 Created
/// </history>
/// -----------------------------------------------------------------------------
public static DNNNodeCollection GetActionNodes(ModuleAction objActionRoot, DNNNode objRootNode, Control objControl, int intDepth)
{
DNNNodeCollection objCol = objRootNode.ParentNode.DNNNodes;
var objActionControl = objControl as IActionControl;
if (objActionControl != null)
{
AddChildActions(objActionRoot, objRootNode, objRootNode, objActionControl, intDepth);
}
return objCol;
}
/// -----------------------------------------------------------------------------
/// <summary>
/// This function provides a central location to obtain a generic node collection of the pages/tabs included in
/// the current context's (user) navigation hierarchy
/// </summary>
/// <param name="objRootNode">Node in which to add children to</param>
/// <param name="eToolTips">Enumerator to determine what text to display in the tooltips</param>
/// <param name="intStartTabId">If using Populate On Demand, then this is the tab id of the root element to retrieve (-1 for no POD)</param>
/// <param name="intDepth">If Populate On Demand is enabled, then this parameter determines the number of nodes to retrieve beneath the starting tab passed in (intStartTabId) (-1 for no POD)</param>
/// <param name="intNavNodeOptions">Bitwise integer containing values to determine what nodes to display (self, siblings, parent)</param>
/// <returns>Collection of DNNNodes</returns>
/// <remarks>
/// Returns a subset of navigation nodes based off of passed in starting node id and depth
/// </remarks>
/// <history>
/// [Jon Henning] 8/9/2005 Created
/// </history>
/// -----------------------------------------------------------------------------
public static DNNNodeCollection GetNavigationNodes(DNNNode objRootNode, ToolTipSource eToolTips, int intStartTabId, int intDepth, int intNavNodeOptions)
{
int i;
PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
bool blnFoundStart = intStartTabId == -1;
var objBreadCrumbs = new Hashtable();
var objTabLookup = new Hashtable();
DNNNodeCollection objRootNodes = objRootNode.DNNNodes;
int intLastBreadCrumbId = 0;
//--- cache breadcrumbs in hashtable so we can easily set flag on node denoting it as a breadcrumb node (without looping multiple times) ---
for (i = 0; i <= (objPortalSettings.ActiveTab.BreadCrumbs.Count - 1); i++)
{
objBreadCrumbs.Add(((TabInfo) objPortalSettings.ActiveTab.BreadCrumbs[i]).TabID, 1);
intLastBreadCrumbId = ((TabInfo) objPortalSettings.ActiveTab.BreadCrumbs[i]).TabID;
}
var objTabController = new TabController();
List<TabInfo> portalTabs = TabController.GetTabsBySortOrder(objPortalSettings.PortalId, objPortalSettings.CultureCode, true);
List<TabInfo> hostTabs = TabController.GetTabsBySortOrder(Null.NullInteger, Localization.SystemLocale, true);
foreach (TabInfo objTab in portalTabs)
{
objTabLookup.Add(objTab.TabID, objTab);
}
foreach (TabInfo objTab in hostTabs)
{
objTabLookup.Add(objTab.TabID, objTab);
}
foreach (TabInfo objTab in portalTabs)
{
try
{
ProcessTab(objRootNode, objTab, objTabLookup, objBreadCrumbs, intLastBreadCrumbId, eToolTips, intStartTabId, intDepth, intNavNodeOptions);
}
catch (Exception ex)
{
throw ex;
}
}
foreach (TabInfo objTab in hostTabs)
{
try
{
ProcessTab(objRootNode, objTab, objTabLookup, objBreadCrumbs, intLastBreadCrumbId, eToolTips, intStartTabId, intDepth, intNavNodeOptions);
}
catch (Exception ex)
{
throw ex;
}
}
return objRootNodes;
}
请发表评论