using System; using System.Text; using System.Web.UI; using CMS.CMSHelper; using CMS.Controls; using CMS.GlobalHelper; using CMS.IO; using CMS.SettingsProvider; using CMS.DocumentEngine; using CMS.UIControls; public partial class CMSModules_Content_Controls_Attachments_AttachmentLightboxGallery : CMSUserControl { #region "Variables" private string mPath = null; #endregion #region "LightBox properties" /// /// Gets or sets the external script path. /// public string LightBoxExternalScriptPath { get { return DataHelper.GetNotEmpty(GetValue("LightBoxExternalScriptPath"), extGalleryLightbox.LightBoxExternalScriptPath); } set { SetValue("LightBoxExternalScriptPath", value); extGalleryLightbox.LightBoxExternalScriptPath = value; } } /// /// Gets or sets the transparency of shadow overlay. /// public float LightBoxOverlayOpacity { get { return (float)ValidationHelper.GetDouble(GetValue("LightBoxOverlayOpacity"), extGalleryLightbox.LightBoxOverlayOpacity); } set { SetValue("LightBoxOverlayOpacity", value); extGalleryLightbox.LightBoxOverlayOpacity = value; } } /// /// Gets or sets the value that indicates whether resizing should be animated. /// public bool LightBoxAnimate { get { return ValidationHelper.GetBoolean(GetValue("LightBoxAnimate"), extGalleryLightbox.LightBoxAnimate); } set { SetValue("LightBoxAnimate", value); extGalleryLightbox.LightBoxAnimate = value; } } /// /// Gets or sets the window width. /// public int LightBoxWidth { get { return ValidationHelper.GetInteger(GetValue("LightBoxWidth"), extGalleryLightbox.LightBoxWidth); } set { SetValue("LightBoxWidth", value); extGalleryLightbox.LightBoxWidth = value; } } /// /// Gets or sets the window height. /// public int LightBoxHeight { get { return ValidationHelper.GetInteger(GetValue("LightBoxHeight"), extGalleryLightbox.LightBoxHeight); } set { SetValue("LightBoxHeight", value); extGalleryLightbox.LightBoxHeight = value; } } /// /// Gets or sets speed of resizing animations. /// public int LightBoxResizeSpeed { get { return ValidationHelper.GetInteger(GetValue("LightBoxResizeSpeed"), extGalleryLightbox.LightBoxResizeSpeed); } set { SetValue("LightBoxResizeSpeed", value); extGalleryLightbox.LightBoxResizeSpeed = value; } } /// /// Gets or sets the border size. /// public int LightBoxBorderSize { get { return ValidationHelper.GetInteger(GetValue("LightBoxBorderSize"), extGalleryLightbox.LightBoxBorderSize); } set { SetValue("LightBoxBorderSize", value); extGalleryLightbox.LightBoxBorderSize = value; } } /// /// Gets or sets the loading image URL. /// public string LightBoxLoadingImg { get { return DataHelper.GetNotEmpty(GetValue("LightBoxLoadingImg"), extGalleryLightbox.LightBoxLoadingImg); } set { SetValue("LightBoxLoadingImg", value); extGalleryLightbox.LightBoxLoadingImg = value; } } /// /// Gets or sets the close image URL. /// public string LightBoxCloseImg { get { return DataHelper.GetNotEmpty(GetValue("LightBoxCloseImg"), extGalleryLightbox.LightBoxCloseImg); } set { SetValue("LightBoxCloseImg", value); extGalleryLightbox.LightBoxCloseImg = value; } } /// /// Gets or sets the previous image URL. /// public string LightBoxPrevImg { get { return DataHelper.GetNotEmpty(GetValue("LightBoxPrevImg"), extGalleryLightbox.LightBoxPrevImg); } set { SetValue("LightBoxPrevImg", value); extGalleryLightbox.LightBoxPrevImg = value; } } /// /// Gets or sets the next image URL. /// public string LightBoxNextImg { get { return DataHelper.GetNotEmpty(GetValue("LightBoxNextImg"), extGalleryLightbox.LightBoxNextImg); } set { SetValue("LightBoxNextImg", value); extGalleryLightbox.LightBoxNextImg = value; } } /// /// Gets or sets the value that indicates whether the navigation buttons are still visible, /// not only on mouse over /// public bool LightBoxPermanentNavigation { get { return ValidationHelper.GetBoolean(GetValue("LightBoxPermanentNavigation"), false); } set { SetValue("LightBoxPermanentNavigation", value); extGalleryLightbox.LightBoxPermanentNavigation = value; } } /// /// Gets or sets the load delay time(in miliseconds). If you are using automatic resizing, /// this value indicates how long will be lightbox runtime wait for taking element size. /// If you have problem with displaying some content with lightbox, try use upper value. /// public int LightBoxLoadDelay { get { return ValidationHelper.GetInteger(GetValue("LightBoxLoadDelay"), 250); } set { SetValue("LightBoxLoadDelay", value); extGalleryLightbox.LightBoxLoadDelay = value; } } /// /// Gets or sets lightbox group name. It is necessary to set this property if you would like /// to display multiple lightboxes for different doc.types on a single page. /// public string LightBoxGroup { get { return DataHelper.GetNotEmpty(GetValue("LightBoxGroup"), extGalleryLightbox.LightBoxGroup); } set { SetValue("LightBoxGroup", value); extGalleryLightbox.LightBoxGroup = value; } } /// /// Determines whether to check JavaScript collisions. /// public bool CheckCollision { get { return ValidationHelper.GetBoolean(GetValue("CheckCollision"), false); } set { SetValue("CheckCollision", value); extGalleryLightbox.CheckCollision = value; } } #endregion #region "Basic repeater properties" /// /// Gets or sets AlternatingTemplate property. /// public string AlternatingTransformationName { get { return ValidationHelper.GetString(GetValue("AlternatingTransformationName"), string.Empty); } set { SetValue("AlternatingTransformationName", value); } } /// /// Gets or sets FooterTemplate property. /// public string FooterTransformationName { get { return ValidationHelper.GetString(GetValue("FooterTransformationName"), string.Empty); } set { SetValue("FooterTransformationName", value); } } /// /// Gets or sets HeaderTemplate property. /// public string HeaderTransformationName { get { return ValidationHelper.GetString(GetValue("HeaderTransformationName"), string.Empty); } set { SetValue("HeaderTransformationName", value); } } /// /// Gets or sets ItemTemplate property. /// public string TransformationName { get { return ValidationHelper.GetString(GetValue("TransformationName"), string.Empty); } set { SetValue("TransformationName", value); } } /// /// Gets or sets SelectedItemTransformationName property. /// public string SelectedItemTransformationName { get { return ValidationHelper.GetString(GetValue("SelectedItemTransformationName"), string.Empty); } set { SetValue("SelectedItemTransformationName", value); } } /// /// Gets or sets SeparatorTemplate property. /// public string SeparatorTransformationName { get { return ValidationHelper.GetString(GetValue("SeparatorTransformationName"), string.Empty); } set { SetValue("SeparatorTransformationName", value); } } /// /// Gets or sets HideControlForZeroRows property. /// public bool HideControlForZeroRows { get { return ucAttachments.HideControlForZeroRows; } set { ucAttachments.HideControlForZeroRows = value; } } /// /// Gets or sets ZeroRowsText property. /// public string ZeroRowsText { get { return ucAttachments.ZeroRowsText; } set { ucAttachments.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 ucAttachments.HidePagerForSinglePage; } set { ucAttachments.HidePagerForSinglePage = value; } } /// /// Gets or sets the number of records to display on a page. /// public int PageSize { get { return ucAttachments.PageSize; } set { ucAttachments.PageSize = value; } } /// /// Gets or sets the number of pages displayed for current page range. /// public int GroupSize { get { return ucAttachments.GroupSize; } set { ucAttachments.GroupSize = value; } } /// /// Gets or sets the pager mode. /// public UniPagerMode PagingMode { get { return ucAttachments.PagingMode; } set { ucAttachments.PagingMode = value; } } /// /// Gets or sets the querysting parameter. /// public string QueryStringKey { get { return ucAttachments.QueryStringKey; } set { ucAttachments.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 ucAttachments.DisplayFirstLastAutomatically; } set { ucAttachments.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 ucAttachments.DisplayPreviousNextAutomatically; } set { ucAttachments.DisplayPreviousNextAutomatically = value; } } #endregion #region "UniPager Template properties" /// /// Gets or sets the pages template. /// public string PagesTemplate { get { return ucAttachments.PagesTemplate; } set { ucAttachments.PagesTemplate = value; } } /// /// Gets or sets the current page template. /// public string CurrentPageTemplate { get { return ucAttachments.CurrentPageTemplate; } set { ucAttachments.CurrentPageTemplate = value; } } /// /// Gets or sets the separator template. /// public string SeparatorTemplate { get { return ucAttachments.SeparatorTemplate; } set { ucAttachments.SeparatorTemplate = value; } } /// /// Gets or sets the first page template. /// public string FirstPageTemplate { get { return ucAttachments.FirstPageTemplate; } set { ucAttachments.FirstPageTemplate = value; } } /// /// Gets or sets the last page template. /// public string LastPageTemplate { get { return ucAttachments.LastPageTemplate; } set { ucAttachments.LastPageTemplate = value; } } /// /// Gets or sets the previous page template. /// public string PreviousPageTemplate { get { return ucAttachments.PreviousPageTemplate; } set { ucAttachments.PreviousPageTemplate = value; } } /// /// Gets or sets the next page template. /// public string NextPageTemplate { get { return ucAttachments.NextPageTemplate; } set { ucAttachments.NextPageTemplate = value; } } /// /// Gets or sets the previous group template. /// public string PreviousGroupTemplate { get { return ucAttachments.PreviousGroupTemplate; } set { ucAttachments.PreviousGroupTemplate = value; } } /// /// Gets or sets the next group template. /// public string NextGroupTemplate { get { return ucAttachments.NextGroupTemplate; } set { ucAttachments.NextGroupTemplate = value; } } /// /// Gets or sets the layout template. /// public string LayoutTemplate { get { return ucAttachments.LayoutTemplate; } set { ucAttachments.LayoutTemplate = value; } } #endregion #region "Data source properties" /// /// Gets or sets WHERE condition. /// public string WhereCondition { get { return ucAttachments.WhereCondition; } set { ucAttachments.WhereCondition = value; } } /// /// Gets or sets top N. /// public int TopN { get { return ucAttachments.TopN; } set { ucAttachments.TopN = value; } } /// /// Gets or sets site name. /// public string SiteName { get { return ucAttachments.SiteName; } set { ucAttachments.SiteName = value; } } /// /// Gets or sets ORDER BY condition. /// public string OrderBy { get { return ucAttachments.OrderBy; } set { ucAttachments.OrderBy = value; } } /// /// Gets or sets the source filter name. /// public string FilterName { get { return ucAttachments.FilterName; } set { ucAttachments.FilterName = value; } } /// /// Gets or sets the cache item name. /// public string CacheItemName { get { return ucAttachments.CacheItemName; } set { ucAttachments.CacheItemName = value; } } /// /// Cache dependencies, each cache dependency on a new line. /// public string CacheDependencies { get { return ucAttachments.CacheDependencies; } set { ucAttachments.CacheDependencies = value; } } /// /// Gets or sets the cache minutes. /// public int CacheMinutes { get { return ucAttachments.CacheMinutes; } set { ucAttachments.CacheMinutes = value; } } /// /// Gets or sets selected columns. /// public string SelectedColumns { get { return ucAttachments.SelectedColumns; } set { ucAttachments.SelectedColumns = value; } } /// /// Tree provider instance used to access data. If no TreeProvider is assigned, a new TreeProvider instance is created. /// public TreeProvider TreeProvider { get { return ucAttachments.TreeProvider; } set { ucAttachments.TreeProvider = value; } } /// /// Indicates whether select also binary content of the attachments. /// public bool GetBinary { get { return ucAttachments.GetBinary; } set { ucAttachments.GetBinary = value; } } /// /// Group GUID (document field GUID) of the grouped attachments. /// public Guid AttachmentGroupGUID { get { return ucAttachments.AttachmentGroupGUID; } set { ucAttachments.AttachmentGroupGUID = value; } } /// /// Form GUID of the temporary attachments. /// public Guid AttachmentFormGUID { get { return ucAttachments.AttachmentFormGUID; } set { ucAttachments.AttachmentFormGUID = value; } } /// /// ID of version history. /// public int DocumentVersionHistoryID { get { return ucAttachments.DocumentVersionHistoryID; } set { ucAttachments.DocumentVersionHistoryID = value; } } /// /// Culture code, such as en-us. /// public string CultureCode { get { return ucAttachments.CultureCode; } set { ucAttachments.CultureCode = value; } } /// /// Indicates if the document should be selected eventually from the default culture. /// public bool CombineWithDefaultCulture { get { return ucAttachments.CombineWithDefaultCulture; } set { ucAttachments.CombineWithDefaultCulture = value; } } /// /// Gets or sets the alias path. /// public string Path { get { return mPath; } set { mPath = value; ucAttachments.Path = CMSContext.ResolveCurrentPath(value); } } /// /// Allows you to specify whether to check permissions of the current user. If the value is 'false' (default value) no permissions are checked. Otherwise, only nodes for which the user has read permission are displayed. /// public bool CheckPermissions { get { return ucAttachments.CheckPermissions; } set { ucAttachments.CheckPermissions = value; } } /// /// Gets whethter datasource is empty or not. /// public bool HasData { get { return ucAttachments.HasData; } } #endregion #region "Stop processing" /// /// Returns true if the control processing should be stopped. /// public override bool StopProcessing { get { return base.StopProcessing; } set { base.StopProcessing = value; ucAttachments.StopProcessing = value; extGalleryLightbox.StopProcessing = value; } } #endregion /// /// Sets value override. /// /// Property name /// Value public override void SetValue(string propertyName, object value) { if (propertyName != null) { switch (propertyName.ToLowerCSafe()) { case "sitename": SiteName = Convert.ToString(value); break; case "path": Path = Convert.ToString(value); break; case "culturecode": CultureCode = Convert.ToString(value); break; case "orderby": OrderBy = Convert.ToString(value); break; case "pagesize": PageSize = ValidationHelper.GetInteger(value, ucAttachments.PageSize); break; case "getbinary": GetBinary = ValidationHelper.GetBoolean(value, ucAttachments.GetBinary); break; case "cacheminutes": CacheMinutes = ValidationHelper.GetInteger(value, ucAttachments.CacheMinutes); break; } } base.SetValue(propertyName, value); } #region "Methods" protected void Page_Load(object sender, EventArgs e) { extGalleryLightbox.OnItemSelected += extGalleryLightbox_OnItemSelected; // Reload data if (!Page.IsCallback && !StopProcessing) { ReloadData(); } } /// /// OnPrerender override (Set visibility). /// protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); Visible = ucAttachments.Visible; if (HideControlForZeroRows && !HasData) { Visible = false; } extGalleryLightbox.StopProcessing = !Visible; } private string extGalleryLightbox_OnItemSelected(string selectedItem) { int idValue = ValidationHelper.GetInteger(selectedItem, 0); ucAttachments.StopProcessing = false; ucAttachments.TransformationName = SelectedItemTransformationName; string idColumnName = (DocumentVersionHistoryID == 0) ? "AttachmentID" : "AttachmentHistoryID"; ucAttachments.WhereCondition = SqlHelperClass.AddWhereCondition(ucAttachments.WhereCondition, idColumnName + "=" + idValue); ucAttachments.ReloadData(true); // Render repeater data to String StringBuilder stringBuilder = new StringBuilder(); StringWriter sw = new StringWriter(stringBuilder); Html32TextWriter writer = new Html32TextWriter(sw); ucAttachments.Repeater.RenderControl(writer); return TextHelper.EnsureLineEndings(stringBuilder.ToString(), string.Empty); } /// /// Reloads the data. /// public void ReloadData() { // Apply transformations if they exist ucAttachments.TransformationName = TransformationName; ucAttachments.AlternatingItemTransformationName = AlternatingTransformationName; ucAttachments.FooterTransformationName = FooterTransformationName; ucAttachments.HeaderTransformationName = HeaderTransformationName; ucAttachments.SeparatorTransformationName = SeparatorTransformationName; ucAttachments.SeparatorTemplate = SeparatorTemplate; } /// /// Clears control cache. /// public void ClearCache() { ucAttachments.ClearCache(); } #endregion }