using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CMS.Controls; using CMS.GlobalHelper; using CMS.MediaLibrary; using CMS.PortalControls; using CMS.UIControls; public partial class CMSWebParts_MediaLibrary_MediaGallery : CMSAbstractWebPart { #region "Content properties" /// /// Gets or sets the number which indicates how many files should be displayed. /// public int SelectTopN { get { return ValidationHelper.GetInteger(GetValue("SelectTopN"), gallery.SelectTopN); } set { SetValue("SelectTopN", value); gallery.SelectTopN = value; } } /// /// Gets or sets the value that indicates whether control should be hidden if no data found. /// public bool HideControlForZeroRows { get { return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), gallery.HideControlForZeroRows); } set { SetValue("HideControlForZeroRows", value); gallery.HideControlForZeroRows = value; } } /// /// Gets or sets the text which is displayed for zero rows result. /// public string ZeroRowsText { get { return ValidationHelper.GetString(GetValue("ZeroRowsText"), gallery.ZeroRowsText); } set { SetValue("ZeroRowsText", value); gallery.ZeroRowsText = value; } } #endregion #region "UniPager properties" /// /// Gets or sets the value that indicates whether pager should be hidden for single page. /// public bool HidePagerForSinglePage { get { return ValidationHelper.GetBoolean(GetValue("HidePagerForSinglePage"), gallery.HidePagerForSinglePage); } set { SetValue("HidePagerForSinglePage", value); gallery.HidePagerForSinglePage = value; } } /// /// Gets or sets the number of records to display on a page. /// public int PageSize { get { return ValidationHelper.GetInteger(GetValue("PageSize"), gallery.PageSize); } set { SetValue("PageSize", value); gallery.PageSize = value; } } /// /// Gets or sets the number of pages displayed for current page range. /// public int GroupSize { get { return ValidationHelper.GetInteger(GetValue("GroupSize"), gallery.GroupSize); } set { SetValue("GroupSize", value); gallery.GroupSize = value; } } /// /// Gets or sets the querysting parameter. /// public string QueryStringKey { get { return ValidationHelper.GetString(GetValue("QueryStringKey"), gallery.QueryStringKey); } set { SetValue("QueryStringKey", value); gallery.QueryStringKey = value; } } /// /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view. /// public bool DisplayFirstLastAutomatically { get { return ValidationHelper.GetBoolean(GetValue("DisplayFirstLastAutomatically"), gallery.DisplayFirstLastAutomatically); } set { SetValue("DisplayFirstLastAutomatically", value); gallery.DisplayFirstLastAutomatically = value; } } /// /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view. /// public bool DisplayPreviousNextAutomatically { get { return ValidationHelper.GetBoolean(GetValue("DisplayPreviousNextAutomatically"), gallery.DisplayPreviousNextAutomatically); } set { SetValue("DisplayPreviousNextAutomatically", value); gallery.DisplayPreviousNextAutomatically = value; } } #endregion #region "UniPager Template properties" /// /// Gets or sets the pages template. /// public string PagesTemplate { get { return ValidationHelper.GetString(GetValue("Pages"), string.Empty); } set { SetValue("Pages", value); } } /// /// Gets or sets the current page template. /// public string CurrentPageTemplate { get { return ValidationHelper.GetString(GetValue("CurrentPage"), string.Empty); } set { SetValue("CurrentPage", value); } } /// /// Gets or sets the separator template. /// public string SeparatorTemplate { get { return ValidationHelper.GetString(GetValue("PageSeparator"), string.Empty); } set { SetValue("PageSeparator", value); gallery.SeparatorTemplate = value; } } /// /// Gets or sets the first page template. /// public string FirstPageTemplate { get { return ValidationHelper.GetString(GetValue("FirstPage"), string.Empty); } set { SetValue("FirstPage", value); } } /// /// Gets or sets the last page template. /// public string LastPageTemplate { get { return ValidationHelper.GetString(GetValue("LastPage"), string.Empty); } set { SetValue("LastPage", value); } } /// /// Gets or sets the previous page template. /// public string PreviousPageTemplate { get { return ValidationHelper.GetString(GetValue("PreviousPage"), string.Empty); } set { SetValue("PreviousPage", value); } } /// /// Gets or sets the next page template. /// public string NextPageTemplate { get { return ValidationHelper.GetString(GetValue("NextPage"), string.Empty); } set { SetValue("NextPage", value); } } /// /// Gets or sets the previous group template. /// public string PreviousGroupTemplate { get { return ValidationHelper.GetString(GetValue("PreviousGroup"), string.Empty); } set { SetValue("PreviousGroup", value); } } /// /// Gets or sets the next group template. /// public string NextGroupTemplate { get { return ValidationHelper.GetString(GetValue("NextGroup"), string.Empty); } set { SetValue("NextGroup", value); } } /// /// Gets or sets the layout template. /// public string LayoutTemplate { get { return ValidationHelper.GetString(GetValue("PagerLayout"), string.Empty); } set { SetValue("PagerLayout", value); gallery.LayoutTemplate = value; } } #endregion #region "Library properties" /// /// Gets or sets the name of the transformation which is used for displaying the results. /// public string TransformationName { get { return ValidationHelper.GetString(GetValue("TransformationName"), gallery.TransformationName); } set { SetValue("TransformationName", value); gallery.TransformationName = value; } } /// /// Gets or sets the name of the transformation which is used for displaying selected file. /// public string SelectedItemTransformation { get { return ValidationHelper.GetString(GetValue("SelectedItemTransformation"), gallery.SelectedItemTransformation); } set { SetValue("SelectedItemTransformation", value); gallery.SelectedItemTransformation = value; } } /// /// Gets or sets the name of the transformation which is used for displaying file list header. /// public string HeaderTransformation { get { return ValidationHelper.GetString(GetValue("HeaderTransformation"), gallery.HeaderTransformation); } set { SetValue("HeaderTransformation", value); gallery.HeaderTransformation = value; } } /// /// Gets or sets the name of the transformation which is used for displaying file list footer. /// public string FooterTransformation { get { return ValidationHelper.GetString(GetValue("FooterTransformation"), gallery.FooterTransformation); } set { SetValue("FooterTransformation", value); gallery.FooterTransformation = value; } } /// /// Gets or sets the name of the transformation which is used for item separator. /// public string SeparatorTransformation { get { return ValidationHelper.GetString(GetValue("SeparatorTransformation"), gallery.SeparatorTransformation); } set { SetValue("SeparatorTransformation", value); gallery.SeparatorTransformation = value; } } /// /// Gets or sets media library path to display files from. /// public string MediaLibraryPath { get { return ValidationHelper.GetString(GetValue("MediaLibraryPath"), gallery.MediaLibraryPath); } set { SetValue("MediaLibraryPath", value); gallery.MediaLibraryPath = value; } } /// /// Gets or sets media library name. /// public string MediaLibraryName { get { string libraryName = ValidationHelper.GetString(GetValue("MediaLibraryName"), gallery.MediaLibraryName); if ((string.IsNullOrEmpty(libraryName) || libraryName == MediaLibraryInfoProvider.CURRENT_LIBRARY) && (MediaLibraryContext.CurrentMediaLibrary != null)) { return MediaLibraryContext.CurrentMediaLibrary.LibraryName; } return libraryName; } set { SetValue("MediaLibraryName", value); gallery.MediaLibraryName = value; } } /// /// Hide folder tree. /// public bool HideFolderTree { get { return ValidationHelper.GetBoolean(GetValue("HideFolderTree"), gallery.HideFolderTree); } set { SetValue("HideFolderTree", value); gallery.HideFolderTree = value; } } /// /// Indicates whether the links to media file should be processed in a secure way. /// public bool UseSecureLinks { get { return ValidationHelper.GetBoolean(GetValue("UseSecureLinks"), true); } set { SetValue("UseSecureLinks", value); gallery.UseSecureLinks = value; } } /// /// Gets or sets media library name. /// public int FilterMethod { get { return ValidationHelper.GetInteger(GetValue("FilterMethod"), gallery.FilterMethod); } set { SetValue("FilterMethod", value); gallery.FilterMethod = value; } } /// /// Gets or sets the file id querysting parameter. /// public string FileIDQueryStringKey { get { return ValidationHelper.GetString(GetValue("FileIDQueryStringKey"), String.Empty); } set { SetValue("FileIDQueryStringKey", value); gallery.FileIDQueryStringKey = value; } } /// /// Gets or sets the sort querysting parameter. /// public string SortQueryStringKey { get { return ValidationHelper.GetString(GetValue("SortQueryStringKey"), String.Empty); } set { SetValue("SortQueryStringKey", value); gallery.SortQueryStringKey = value; } } /// /// Gets or sets the path querysting parameter. /// public string PathQueryStringKey { get { return ValidationHelper.GetString(GetValue("PathQueryStringKey"), String.Empty); } set { SetValue("PathQueryStringKey", value); gallery.PathQueryStringKey = value; } } /// /// Preview preffix for identification preview file. /// public string PreviewSuffix { get { return ValidationHelper.GetString(GetValue("PreviewSuffix"), String.Empty); } set { SetValue("PreviewSuffix", value); gallery.PreviewSuffix = value; } } /// /// Icon set name. /// public string IconSet { get { return ValidationHelper.GetString(GetValue("IconSet"), String.Empty); } set { SetValue("IconSet", value); gallery.IconSet = value; } } /// /// Indicates if active content (video, flash etc.) should be displayed. /// public bool DisplayActiveContent { get { return ValidationHelper.GetBoolean(GetValue("DisplayActiveContent"), gallery.DisplayActiveContent); } set { SetValue("DisplayActiveContent", value); gallery.DisplayActiveContent = value; } } /// /// Indicates if subfolders content should be displayed. /// public bool ShowSubfoldersContent { get { return ValidationHelper.GetBoolean(GetValue("ShowSubfoldersContent"), gallery.ShowSubfoldersContent); } set { SetValue("ShowSubfoldersContent", value); gallery.ShowSubfoldersContent = value; } } /// /// Indicates if files count should be displayed. /// public bool DisplayFileCount { get { return ValidationHelper.GetBoolean(GetValue("DisplayFileCount"), gallery.DisplayFileCount); } set { SetValue("DisplayFileCount", value); gallery.DisplayFileCount = value; } } /// /// Indicates if file upload form should be displayed. /// public bool AllowUpload { get { return ValidationHelper.GetBoolean(GetValue("AllowUpload"), gallery.AllowUpload); } set { SetValue("AllowUpload", value); gallery.AllowUpload = value; } } /// /// Indicates if preview file upload should be displayed in upload form. /// public bool AllowUploadPreview { get { return ValidationHelper.GetBoolean(GetValue("AllowUploadPreview"), gallery.AllowUploadPreview); } set { SetValue("AllowUploadPreview", value); gallery.AllowUploadPreview = value; } } #endregion public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { gallery.OnNotAllowed += gallery_OnNotAllowed; // Library properties gallery.MediaLibraryName = MediaLibraryName; gallery.MediaLibraryPath = MediaLibraryPath; gallery.TransformationName = TransformationName; gallery.SelectedItemTransformation = SelectedItemTransformation; gallery.HeaderTransformation = HeaderTransformation; gallery.FooterTransformation = FooterTransformation; gallery.SeparatorTransformation = SeparatorTransformation; gallery.HideFolderTree = HideFolderTree; gallery.PreviewSuffix = PreviewSuffix; gallery.IconSet = IconSet; gallery.DisplayActiveContent = DisplayActiveContent; gallery.DisplayFileCount = DisplayFileCount; gallery.ShowSubfoldersContent = ShowSubfoldersContent; gallery.ZeroRowsText = ZeroRowsText; gallery.HideControlForZeroRows = HideControlForZeroRows; gallery.UseSecureLinks = UseSecureLinks; // Filters properties gallery.FilterMethod = FilterMethod; gallery.FileIDQueryStringKey = FileIDQueryStringKey; gallery.PathQueryStringKey = PathQueryStringKey; gallery.SortQueryStringKey = SortQueryStringKey; // Content properties gallery.SelectTopN = SelectTopN; // Uploader properties gallery.AllowUpload = AllowUpload; gallery.AllowUploadPreview = AllowUploadPreview; // UniPager properties gallery.PageSize = PageSize; gallery.GroupSize = GroupSize; gallery.QueryStringKey = QueryStringKey; gallery.DisplayFirstLastAutomatically = DisplayFirstLastAutomatically; gallery.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically; gallery.HidePagerForSinglePage = HidePagerForSinglePage; switch (FilterMethod) { case 1: gallery.PagerMode = UniPagerMode.PostBack; break; default: gallery.PagerMode = UniPagerMode.Querystring; break; } // UniPager template properties gallery.PagesTemplate = PagesTemplate; gallery.CurrentPageTemplate = CurrentPageTemplate; gallery.SeparatorTemplate = SeparatorTemplate; gallery.FirstPageTemplate = FirstPageTemplate; gallery.LastPageTemplate = LastPageTemplate; gallery.PreviousPageTemplate = PreviousPageTemplate; gallery.NextPageTemplate = NextPageTemplate; gallery.PreviousGroupTemplate = PreviousGroupTemplate; gallery.NextGroupTemplate = NextGroupTemplate; gallery.LayoutTemplate = LayoutTemplate; } private void gallery_OnNotAllowed(string permissionType, CMSAdminControl sender) { if (sender != null) { sender.StopProcessing = true; } gallery.StopProcessing = true; gallery.Visible = false; gallery.UniPager.PageControl = null; messageElem.ErrorMessage = MediaLibraryHelper.GetAccessDeniedMessage(permissionType); messageElem.DisplayMessage = true; } /// /// Reload data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); gallery.ReloadData(); } }