📄 posteditcontrol.ascx.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Controls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CommunityServer.Galleries;
using CommunityServer.Galleries.Components;
using CommunityServer.Galleries.Controls;
using System.Collections;
using Calendar = ComponentArt.Web.UI.Calendar;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;
using Script = CommunityServer.Controls.Script;
namespace CommunityServer.ControlPanel.Photos
{
/// <summary>
/// Summary description for Skin_CreateEditBlogPost.
/// </summary>
public class PostEditControl : BaseGalleryControl
{
protected Literal PreviewTitle;
protected Literal PreviewBody;
protected HtmlGenericControl Preview;
protected Editor PostBody;
protected TextBox postName;
protected TextBox postExcerpt;
protected CommentModerationDropDownList ModerationDDL;
protected GalleryImage Galleryimage1;
protected System.Web.UI.WebControls.CustomValidator pictureDataValidator; //PictureData
protected RequiredFieldValidator postSubjectValidator;
protected RegularExpressionValidator vRegexPostName;
protected CategoryChecklistControl CategoryChecklist1;
protected Calendar DatePicker;
protected DropDownRange HourPicker;
protected DropDownRange MinutePicker;
protected DropDownList AMPM;
protected Modal Modal1;
protected Modal Modal2;
protected int PostID;
protected FeedbackNotificationDropDownList NotificationType;
protected Script Script1;
protected Panel ExistingAttachmentPanel;
protected Panel ServerUploadPanel;
protected Literal ExistingFileName;
protected HtmlInputHidden ServeruploadtempID;
protected TextBox ServerFriendlyFileName;
protected TextBox ServerFileName;
protected Script Script2;
protected CommunityServer.ControlPanel.Controls.StatusMessage Status;
protected PlaceHolder AlbumSelectionContainer, TagSelectionContainer;
protected TagEditor Tags;
protected CSContext context = null;
private void Page_Load(object sender, EventArgs e)
{
AjaxManager.Register(this,"PostEditControl");
context = CSContext.Current;
PostID = context.PostID;
this.PanelPage.IsInEdit = true;
pictureDataValidator.Enabled = (context.PostID <= 0); //Picture is required
if (!Page.IsPostBack && !this.GalleryPage.IsCallBack)
{
Bind();
}
ValidatePictureDataClient();
//Page.RegisterStartupScript("DisableFileNameBox","<SCRIPT type='text/javascript'>document.getElementById('" + this.ServerFileName.ClientID + "').disabled=true;</script>") ;
}
// private void RegisterAddAttachmentPopup()
// {
// string script = @"<script type=""text/javascript"">initPopUp();{0};</script>";
// Page.RegisterStartupScript("AttachmentPopup",String.Format(script, ModalHelper.BuildHandler(Modal2).TrimEnd(';'))) ;
// }
private void Bind()
{
GalleryPost post = null;
vRegexPostName.ValidationExpression = GalleryPosts.PostNamePattern;
vRegexPostName.Text = ResourceManager.GetString("CP_Photos_PostEdit_Name_RegexValidator");
if (context.PostID > 0)
{
post = GalleryPosts.GetPicture(context.PostID, true);
if (post != null)
{
PostBody.Text = post.Body;
postExcerpt.Text = post.Excerpt;
postName.Text = post.Name;
ModerationDDL.Items.FindByValue(post.ModerationType.ToString()).Selected = true;
SetDate(post.PostDate);
NotificationType.SelectedValue = post.FeedbackNotificationType;
// Update the thumbnail
Galleryimage1.GalleryPost = post;
Galleryimage1.PostID = post.PostID;
Galleryimage1.NavigateUrl = GalleryUrls.Instance().ViewPicture(CurrentGallery.ApplicationKey, post );
Galleryimage1.DataBind();
if(Globals.IsNullorEmpty(post.AttachmentFilename))
{
ExistingAttachmentPanel.Visible = false;
}
else
{
PostAttachmentMetaData attachment = post.Attachment;
if(attachment != null)
{
ExistingAttachmentPanel.Visible = true;
ExistingFileName.Text = attachment.FileName;
//Galleryies uses the ServerFriendlyFileName as the post subject
ServerFriendlyFileName.Text = post.Subject;
}
}
bool hasMultipleOwners = post.Gallery.OwnerArray.Length > 1;
SetYesNo(post.PostConfig, post.IsApproved, !post.IsLocked, post.EnableAllOwnerNotification, post.EnableRatings, post.EnableTrackBacks, hasMultipleOwners);
if (CurrentGallery.CategorizationType == CategorizationType.Album)
{
CategoryChecklist1.SelectedNodes = GalleryPosts.GetPictureCategories(post);
TagSelectionContainer.Visible = false;
}
else
{
PopulateCategories();
Tags.SelectedTags = GetTagNamesFromCategories(GalleryPosts.GetPictureCategories(post));
AlbumSelectionContainer.Visible = false;
}
}
}
else
{
//RegisterAddAttachmentPopup();
ExistingAttachmentPanel.Visible = false;
SetDate(UserTime.CurrentUserTime);
ModerationDDL.Items.FindByValue(CurrentGallery.ModerationTypeDefault.ToString()).Selected = true;
SetYesNo(CurrentGallery.DefaultPostConfig, true, true, false, this.CurrentGallery.EnableRatingsDefault, CurrentGallery.EnableTrackbacksDefault, false);
int categoryID = context.GetIntFromQueryString("cid",context.GetIntFromQueryString("categoryid", -1));
CategoryChecklist1.SetSingleSelectedNode(categoryID, this.GalleryPage.CurrentGallery.SectionID);
if (CurrentGallery.CategorizationType == CategorizationType.Album)
{
TagSelectionContainer.Visible = false;
}
else
{
AlbumSelectionContainer.Visible = false;
PopulateCategories();
}
}
}
private string[] GetTagNamesFromCategories(ArrayList categories)
{
string[] tags = new string[categories.Count];
int i = 0;
foreach (PostCategory pc in categories)
{
tags[i] = pc.Name;
i++;
}
return tags;
}
private void PopulateCategories()
{
Tags.AvailableTags = PostCategories.GetCategories(this.CurrentGallery.SectionID, true, true);
}
private bool GetYesNo(string ynID)
{
return (FindControl(ynID) as YesNoRadioButtonList).SelectedValue;
}
private void PopulateFromYesNo(GalleryPost post)
{
bool isPost = this.PostType == GalleryPostType.Image;
post.IsLocked = !GetYesNo("ynEnableReplies");
post.IsApproved = GetYesNo("ynPublished");
post.EnableRatings = GetYesNo("ynEnableRatings");
post.EnableTrackBacks = GetYesNo("ynEnableTrackBacks");
post.EnableOrderPrints = GetYesNo("ynEnableOrderPrints");
post.EnableAllOwnerNotification = GetYesNo("ynNotifyAllOwners");
if (isPost)
{
//these features are not implimented in the gallery
//post.IsAggregated = GetYesNo("ynAggregatePost");
//post.IsCommunityAggregated = GetYesNo("ynCommunity");
//post.SyndicateExcerpt = GetYesNo("ynSyndicateExcerpt");
}
}
private void EnableYesNo(string ynID, bool Selected, bool enable)
{
YesNoRadioButtonList yn = FindControl(ynID) as YesNoRadioButtonList;
if (yn != null)
{
yn.SelectedValue = Selected;
if (!enable)
FindControl(ynID + "_row").Visible = false;
}
}
private void SetYesNo(GalleryPostConfig gc, bool isPublished, bool allowReplies, bool notifyAllOwners, bool rate, bool track, bool hasMultipleOwners)
{
bool isPost = this.PostType == GalleryPostType.Image;
EnableYesNo("ynEnableReplies", allowReplies, true);
EnableYesNo("ynPublished", isPublished, true);
EnableYesNo("ynAggregatePost", PostConfigHelper.IsPostConfigSelected(gc, GalleryPostConfig.IsAggregated), isPost);
EnableYesNo("ynCommunity", PostConfigHelper.IsPostConfigSelected(gc, GalleryPostConfig.IsCommunityAggregated), isPost);
EnableYesNo("ynSyndicateExcerpt", PostConfigHelper.IsPostConfigSelected(gc, GalleryPostConfig.SyndicateExcerpt), isPost);
EnableYesNo("ynEnableOrderPrints", CurrentGallery.EnableOrderPrints, CurrentGallery.EnableOrderPrintsOverride);
EnableYesNo("ynEnableRatings", rate, true);
EnableYesNo("ynEnableTrackBacks", track, true);
EnableYesNo("ynNotifyAllOwners", notifyAllOwners, hasMultipleOwners);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -