📄 navigationmenu.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Collections;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;
namespace CommunityServer.Galleries.Controls
{
public class NavigationMenu : GalleryThemedControl
{
#region Child Controls
private Repeater adminFunctionsRepeater;
private Repeater navigationRepeater;
#endregion
#region Skin
protected override void AttachChildControls()
{
adminFunctionsRepeater = (Repeater)FindControl( "AdminFunctionsRepeater" );
navigationRepeater = (Repeater)FindControl( "NavigationRepeater" );
InitializeChildControls();
}
private void InitializeChildControls()
{
adminFunctionsRepeater.ItemDataBound += new RepeaterItemEventHandler(adminFunctionsRepeater_ItemDataBound);
navigationRepeater.ItemDataBound += new RepeaterItemEventHandler(navigationRepeater_ItemDataBound);
}
#endregion
protected override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
if(!Page.IsPostBack)
DataBind();
}
public override void DataBind()
{
base.DataBind();
ArrayList navItems = new ArrayList();
ArrayList adminItems = new ArrayList();
User user = CSContext.Current.User;
PostCategory currentCategory = null;
Picture currentPicture = null;
if(CSContext.Current.CategoryID != -1)
currentCategory = PostCategories.GetCategory(CSContext.Current.CategoryID, CategoryType.GalleryPicture, CurrentGallery.SectionID, CurrentUser.IsGalleryAdministrator);
if(CSContext.Current.PostID != -1)
currentPicture = Pictures.GetPicture(CSContext.Current.PostID);
if(CurrentGallery != null)
{
navItems.Add( CurrentGallery );
if( Permissions.ValidatePermissions( CurrentGallery, Permission.Post, user ))
{
adminItems.Add( CreateLink( "edit gallery", GalleryUrls.Instance().Admin_AdminGallery_ReturnUrl(CurrentGallery.ApplicationKey, "gallery_ViewGallery", CurrentGallery.ApplicationKey) ) );
}
if((currentCategory == null) && (currentPicture == null))
{
if( Permissions.ValidatePermissions( CurrentGallery, Permission.Post, user ))
{
adminItems.Add( CreateLink( "add category", GalleryUrls.Instance().Admin_AdminCategory_ReturnUrl(CurrentGallery.ApplicationKey, 0, "gallery_ViewGallery", CurrentGallery.ApplicationKey) ) );
adminItems.Add( CreateLink( "add picture", GalleryUrls.Instance().Admin_AdminPicture_ReturnUrl(CurrentGallery.ApplicationKey, -1, -1, "gallery_ViewGallery", CurrentGallery.ApplicationKey) ) );
}
}
}
if(currentCategory != null)
{
navItems.Add( currentCategory );
if( Permissions.ValidatePermissions( CurrentGallery, Permission.Post, user ))
{
adminItems.Add( CreateLink( "add sub category", GalleryUrls.Instance().Admin_AdminCategory_ReturnUrl(CurrentGallery.ApplicationKey, 0, "gallery_ViewGallery", CurrentGallery.ApplicationKey) ) );
adminItems.Add( CreateLink( "edit category", GalleryUrls.Instance().Admin_AdminCategory_ReturnUrl(CurrentGallery.ApplicationKey, currentCategory.CategoryID, "gallery_ViewCategory", CurrentGallery.ApplicationKey + "," + currentCategory.CategoryID.ToString()) ) );
if(currentPicture == null)
adminItems.Add( CreateLink( "add picture", GalleryUrls.Instance().Admin_AdminPicture_ReturnUrl(CurrentGallery.ApplicationKey, currentCategory.CategoryID, -1, "gallery_ViewCategory", CurrentGallery.ApplicationKey + "," + currentCategory.CategoryID.ToString()) ) );
}
}
if(currentPicture != null)
{
navItems.Add( currentPicture );
if( Permissions.ValidatePermissions( CurrentGallery, Permission.Post | Permission.EditOthers, user ))
{
if(currentCategory != null)
adminItems.Add( CreateLink( "edit picture", GalleryUrls.Instance().Admin_AdminPicture_ReturnUrl(CurrentGallery.ApplicationKey, -1, currentPicture.PostID, "gallery_ViewPicture_Category", CurrentGallery.ApplicationKey + "," + currentCategory.CategoryID.ToString() + "," + currentPicture.PostID.ToString()) ) );
else
adminItems.Add( CreateLink( "edit picture", GalleryUrls.Instance().Admin_AdminPicture_ReturnUrl(CurrentGallery.ApplicationKey, -1, currentPicture.PostID, "gallery_ViewPicture_Gallery", CurrentGallery.ApplicationKey + "," + currentPicture.PostID.ToString()) ) );
}
}
navigationRepeater.DataSource = navItems;
navigationRepeater.DataBind();
if(adminItems.Count > 0)
{
adminFunctionsRepeater.DataSource = adminItems;
adminFunctionsRepeater.DataBind();
}
else
adminFunctionsRepeater.Visible = false;
}
private HyperLink CreateLink(string text, string navigateUrl)
{
HyperLink link = new HyperLink();
link.Text = text;
link.NavigateUrl = navigateUrl;
return link;
}
private void navigationRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
HyperLink navLink = e.Item.FindControl( "NavLink" ) as HyperLink;
if(navLink == null)
return;
if(e.Item.DataItem is Gallery)
{
Gallery gallery = e.Item.DataItem as Gallery;
navLink.Text = gallery.Name;
navLink.NavigateUrl = GalleryUrls.Instance().ViewGallery( gallery.ApplicationKey );
}
else if(e.Item.DataItem is PostCategory)
{
PostCategory category = e.Item.DataItem as PostCategory;
navLink.Text = category.Name;
navLink.NavigateUrl = GalleryUrls.Instance().ViewCategory( CurrentGallery.ApplicationKey, category.CategoryID );
}
else if(e.Item.DataItem is Picture)
{
Picture picture = e.Item.DataItem as Picture;
int categoryID = -1;
if(CSContext.Current.CategoryID != -1)
categoryID = CSContext.Current.CategoryID;
if(picture.Subject != string.Empty)
navLink.Text = picture.Subject;
else
navLink.Text = ResourceManager.GetString( "Gallery_NoTitle" );
navLink.NavigateUrl = GalleryUrls.Instance().ViewPicture( CurrentGallery.ApplicationKey, categoryID, picture );
}
}
private void adminFunctionsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
HyperLink item = e.Item.DataItem as HyperLink;
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
if(item != null)
{
HyperLink adminLink = (HyperLink)e.Item.FindControl( "AdminLink" );
adminLink.Text = item.Text;
adminLink.NavigateUrl = item.NavigateUrl;
}
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -