using System;
using System.Data;
using System.Web;
using System.Web.UI;
using CMS.CMSHelper;
using CMS.Controls;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.DocumentEngine;
public partial class CMSWebParts_Text_pagedtext : CMSAbstractWebPart
{
#region "Document properties"
///
/// Gets or sets the value that indicates whether the permissions are checked.
///
public bool CheckPermissions
{
get
{
return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), false);
}
set
{
SetValue("CheckPermissions", value);
}
}
///
/// Gets or sets the value that indicates whether the default language version of the document
/// should be displayed if the document is not translated to the current language.
///
public bool CombineWithDefaultCulture
{
get
{
return ValidationHelper.GetBoolean(GetValue("CombineWithDefaultCulture"), true);
}
set
{
SetValue("CombineWithDefaultCulture", value);
}
}
///
/// Gets or sets the culture version of the displayed content.
///
public string CultureCode
{
get
{
return DataHelper.GetNotEmpty(GetValue("CultureCode"), CMSContext.PreferredCultureCode);
}
set
{
SetValue("CultureCode", value);
}
}
///
/// Gets or sets the path to the document.
///
public string Path
{
get
{
return ValidationHelper.GetString(GetValue("Path"), "");
}
set
{
SetValue("Path", value);
}
}
///
/// Gets or sets the value that indicates whether to show only published documents.
///
public bool SelectOnlyPublished
{
get
{
return ValidationHelper.GetBoolean(GetValue("SelectOnlyPublished"), true);
}
set
{
SetValue("SelctOnlyPublished", value);
}
}
///
/// Gets or sets the codename of the site from which you want do display the content.
///
public string SiteName
{
get
{
return DataHelper.GetNotEmpty(GetValue("SiteName"), CMSContext.CurrentSiteName);
}
set
{
SetValue("SiteName", value);
}
}
///
/// Gets or sets the name of the document field that should be used as a source of the text.
///
public string ColumnName
{
get
{
return ValidationHelper.GetString(GetValue("ColumnName"), "");
}
set
{
SetValue("ColumnName", value);
}
}
#endregion
#region "Pager properties"
///
/// Gets or sets the pager position (position of page numbers).
///
public PagingPlaceTypeEnum PagerPosition
{
get
{
return textPager.PagerControl.GetPagerPosition(DataHelper.GetNotEmpty(GetValue("PagerPosition"), textPager.PagerControl.PagerPosition.ToString()));
}
set
{
SetValue("PagerPosition", value.ToString());
textPager.PagerControl.PagerPosition = value;
}
}
///
/// Gets or sets the page size (number of characters displayed per page).
///
public int PageSize
{
get
{
return ValidationHelper.GetInteger(GetValue("PageSize"), textPager.PageSize);
}
set
{
SetValue("PageSize", value);
textPager.PageSize = value;
}
}
///
/// Gets or sets the pager query string key.
///
public string QueryStringKey
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("QueryStringKey"), textPager.PagerControl.QueryStringKey), textPager.PagerControl.QueryStringKey);
}
set
{
SetValue("QueryStringKey", value);
textPager.PagerControl.QueryStringKey = value;
}
}
///
/// Gets or sets the pager format string, you can use standard macros (ie. Page {0} of {2}).
///
public string PagerFormat
{
get
{
return ValidationHelper.GetString(GetValue("PagerFormat"), textPager.PagerControl.ResultsFormat);
}
set
{
SetValue("PagerFormat", value);
textPager.PagerControl.ResultsFormat = value;
}
}
///
/// Gets or sets the paging mode.
///
public PagingModeTypeEnum PagingMode
{
get
{
return textPager.PagerControl.GetPagingMode(DataHelper.GetNotEmpty(GetValue("PagingMode"), textPager.PagerControl.PagingMode.ToString()));
}
set
{
SetValue("PagingMode", value.ToString());
textPager.PagerControl.PagingMode = value;
}
}
///
/// Gets or sets the value that indicates whether to show links to first / last page
///
public bool ShowFirstLast
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowFirstLast"), textPager.PagerControl.ShowFirstLast);
}
set
{
SetValue("ShowFirstLast", value);
textPager.PagerControl.ShowFirstLast = value;
}
}
///
/// Gets or sets the pager separator text (text which is displayed at the end of each page).
///
public string PagerSeparator
{
get
{
return ValidationHelper.GetString(GetValue("PagerSeparator"), textPager.PagerSeparator);
}
set
{
SetValue("PagerSeparator", value);
textPager.PagerSeparator = value;
}
}
///
/// Gets or sets the name of the text CSS class (css class of the div around the text).
///
public string TextCSSClass
{
get
{
return ValidationHelper.GetString(GetValue("TextCSSClass"), textPager.TextCSSClass);
}
set
{
SetValue("TextCSSClass", value);
textPager.TextCSSClass = value;
}
}
///
/// Gets or sets the name of the pager CSS class (css class of the div around the page numbers).
///
public string PagerCSSClass
{
get
{
return ValidationHelper.GetString(GetValue("PagerCSSClass"), textPager.PagerCSSClass);
}
set
{
SetValue("PagerCSSClass", value);
textPager.PagerCSSClass = value;
}
}
///
/// Gets or sets pager numbers separator.
///
public string PageNumbersSeparator
{
get
{
return ValidationHelper.GetString(GetValue("PageNumbersSeparator"), textPager.PagerControl.PageNumbersSeparator);
}
set
{
SetValue("PageNumbersSeparator", value);
textPager.PagerControl.PageNumbersSeparator = value;
}
}
///
/// Gets or sets html contect before pager.
///
public string PagerHTMLBefore
{
get
{
return ValidationHelper.GetString(GetValue("PagerHTMLBefore"), textPager.PagerControl.PagerHTMLBefore);
}
set
{
SetValue("PagerHTMLBefore", value);
textPager.PagerControl.PagerHTMLBefore = value;
}
}
///
/// Gets or sets html contect after pager.
///
public string PagerHTMLAfter
{
get
{
return ValidationHelper.GetString(GetValue("PagerHTMLAfter"), textPager.PagerControl.PagerHTMLAfter);
}
set
{
SetValue("PagerHTMLAfter", value);
textPager.PagerControl.PagerHTMLAfter = value;
}
}
///
/// Gets or sets the navigation mode.
///
public BackNextLocationTypeEnum BackNextLocation
{
get
{
return textPager.PagerControl.GetBackNextLocation(DataHelper.GetNotEmpty(GetValue("BackNextLocation"), textPager.PagerControl.BackNextLocation.ToString()));
}
set
{
SetValue("BackNextLocation", value.ToString());
textPager.PagerControl.BackNextLocation = value;
}
}
#endregion
#region "Methods & events"
///
/// Content loaded event handler.
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
if (StopProcessing)
{
// Do nothing
}
else
{
textPager.PagerControl.PagerPosition = PagerPosition;
textPager.PagerControl.QueryStringKey = QueryStringKey;
textPager.PagerControl.PagingMode = PagingMode;
textPager.PagerControl.ShowFirstLast = ShowFirstLast;
textPager.PagerControl.ResultsFormat = PagerFormat;
textPager.PagerSeparator = PagerSeparator;
textPager.PagerCSSClass = PagerCSSClass;
textPager.TextCSSClass = TextCSSClass;
textPager.PageSize = PageSize;
textPager.PagerControl.PageNumbersSeparator = PageNumbersSeparator;
textPager.PagerControl.PagerHTMLBefore = PagerHTMLBefore;
textPager.PagerControl.PagerHTMLAfter = PagerHTMLAfter;
textPager.PagerControl.BackNextLocation = BackNextLocation;
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
LoadData();
}
///
/// Loads the data to the control.
///
protected void LoadData()
{
SetContext();
string text = string.Empty;
TreeNode node = null;
if (Path == string.Empty)
{
node = CMSContext.CurrentDocument;
}
else
{
// Try to get data from cache
using (CachedSection cs = new CachedSection(ref node, CacheMinutes, true, CacheItemName, "pagedtext", CacheHelper.GetBaseCacheKey(CheckPermissions, false), SiteName, Path, CultureCode, CombineWithDefaultCulture, SelectOnlyPublished))
{
if (cs.LoadData)
{
// Ensure that the path is only for one single document
Path = CMSContext.CurrentResolver.ResolvePath(Path.TrimEnd('%').TrimEnd('/'));
node = TreeHelper.GetDocument(SiteName, Path, CultureCode, CombineWithDefaultCulture, null, SelectOnlyPublished, CheckPermissions, CMSContext.CurrentUser);
// Prepare the cache dependency
if (cs.Cached)
{
cs.CacheDependency = GetCacheDependency();
}
cs.Data = node;
}
}
}
if ((node != null) && (ColumnName != string.Empty))
{
text = ValidationHelper.GetString(node.GetValue(ColumnName), string.Empty);
if (text != string.Empty)
{
textPager.TextSource = text;
textPager.ReloadData(false);
}
else
{
Visible = false;
}
}
else
{
Visible = false;
}
ReleaseContext();
}
///
/// Reloads the data.
///
public override void ReloadData()
{
base.ReloadData();
SetupControl();
textPager.ReloadData(true);
}
#endregion
}