📄 emailsubscriptionlist.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;
namespace CommunityServer.Blogs.Controls
{
/// <summary>
/// Enables the management of email subscriptions to an individual weblog
/// </summary>
public class EmailSubscriptionList : WeblogThemedControl
{
public EmailSubscriptionList()
{
}
/// <summary>
/// Validates we only allow authenticated users to see this page
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
if(!Context.Request.IsAuthenticated)
{
Context.Response.Redirect(Globals.GetSiteUrls().Login);
Context.Response.End();
}
base.OnInit (e);
}
#region Private Members
private RadioButtonList GlobalList = null;
private CheckBoxList PostList = null;
private Button UnSubGlobal = null;
private Button UnSubAll = null;
private Button UnSub = null;
private ResourceControl NoSubscriptionsMessage = null;
#endregion
/// <summary>
/// Wire up controls
/// </summary>
protected override void AttachChildControls()
{
GlobalList = FindControl("GlobalList") as RadioButtonList;
PostList = FindControl("PostList") as CheckBoxList;
UnSubGlobal = FindControl("UnSubGlobal") as Button;
UnSubAll = FindControl("UnSubAll") as Button;
UnSub = FindControl("UnSub") as Button;
NoSubscriptionsMessage = FindControl("NoSubscriptionsMessage") as ResourceControl;
UnSubGlobal.Click +=new EventHandler(UnSubGlobal_Click);
UnSubAll.Click +=new EventHandler(UnSubAll_Click);
UnSub.Click +=new EventHandler(UnSub_Click);
this.SetPageTitle(ResourceManager.GetString("Weblog_Email_Subscriptions"));
UnSubGlobal.Text = ResourceManager.GetString("Weblog_Email_GlobalButton");
UnSubAll.Text = ResourceManager.GetString("Weblog_Email_UnSubAllButton");
UnSub.Text = ResourceManager.GetString("Weblog_Email_UnSubButton");
}
const string urlFormat = "<a href = \"{0}\">{1}</a>";
private string BuildUrl(WeblogPost post)
{
return string.Format(urlFormat,BlogUrls.Instance().Post(post,CurrentWeblog), post.Subject);
}
//Wire up databinding
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
if(!Page.IsPostBack)
DataBind();
}
public override void DataBind()
{
base.DataBind ();
PostSet ps = WeblogPosts.GetTrackedThreadsByUser(CurrentWeblog.SectionID,CurrentUser.UserID);
PostList.Items.Clear();
foreach(WeblogPost post in ps.Posts)
{
PostList.Items.Add(new ListItem(BuildUrl(post), post.PostID.ToString()));
}
SetMessage();
GlobalList.Items.Clear();
GlobalList.Items.Add(new ListItem(ResourceManager.GetString("Weblog_Email_Never"), EmailSubscriptionType.None.ToString()));
GlobalList.Items.Add(new ListItem(ResourceManager.GetString("Weblog_Email_NewPosts"), EmailSubscriptionType.Thread.ToString()));
GlobalList.Items.Add(new ListItem(ResourceManager.GetString("Weblog_Email_NewPostsandComments"), EmailSubscriptionType.Post.ToString()));
EmailSubscriptionType subType = ThreadTracking.GetSectionSubscriptionType(CurrentWeblog.SectionID, CurrentUser.UserID);
ListItem li = GlobalList.Items.FindByValue(subType.ToString());
if(li != null)
li.Selected = true;
}
private void SetMessage()
{
bool vis = (PostList.Items.Count > 0);
NoSubscriptionsMessage.Visible = !vis;
UnSub.Enabled = vis;
UnSubAll.Enabled = vis;
}
private void UnSubGlobal_Click(object sender, EventArgs e)
{
EmailSubscriptionType subType = (EmailSubscriptionType)Enum.Parse(typeof(EmailSubscriptionType),GlobalList.SelectedValue);
ThreadTracking.SetSectionSubscriptionType(CurrentWeblog.SectionID,CurrentUser.UserID,subType);
}
private void UnSubAll_Click(object sender, EventArgs e)
{
if(PostList.Items.Count > 0)
{
ThreadTracking.RemoveThreadTracking(CurrentWeblog.SectionID,CurrentUser.UserID);
PostList.Items.Clear();
SetMessage();
}
}
private void UnSub_Click(object sender, EventArgs e)
{
if(PostList.Items.Count > 0)
{
//walk the list backwards
for(int i = PostList.Items.Count -1; i >= 0; i--)
{
ListItem li = PostList.Items[i];
if(li.Selected)
{
ThreadTracking.ReverseThreadTrackingOptions(CurrentUser.UserID, Int32.Parse(li.Value));
PostList.Items.Remove(li);
}
}
SetMessage();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -