using System; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.Controls; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.SettingsProvider; using DataPager = CMS.Controls.DataPager; public partial class CMSWebParts_Viewers_Documents_cmsdatalist : CMSAbstractWebPart { #region "Document properties" /// /// Gets or sets the cache item name. /// public override string CacheItemName { get { return base.CacheItemName; } set { base.CacheItemName = value; lstElem.CacheItemName = value; } } /// /// Cache dependencies, each cache dependency on a new line. /// public override string CacheDependencies { get { return ValidationHelper.GetString(base.CacheDependencies, lstElem.CacheDependencies); } set { base.CacheDependencies = value; lstElem.CacheDependencies = value; } } /// /// Gets or sets the cache minutes. /// public override int CacheMinutes { get { return base.CacheMinutes; } set { base.CacheMinutes = value; lstElem.CacheMinutes = value; } } /// /// Gets or sets the value that indicates whether permissions should be checked. /// public bool CheckPermissions { get { return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), lstElem.CheckPermissions); } set { SetValue("CheckPermissions", value); lstElem.CheckPermissions = value; } } /// /// Gets or sets the class names which should be displayed. /// public string ClassNames { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("Classnames"), lstElem.ClassNames), lstElem.ClassNames); } set { SetValue("ClassNames", value); lstElem.ClassNames = value; } } /// /// Code name of the category to display documents from. /// public string CategoryName { get { return ValidationHelper.GetString(GetValue("CategoryName"), lstElem.CategoryName); } set { SetValue("CategoryName", value); lstElem.CategoryName = value; } } /// /// Gets or sets the value that indicates whether documents are combined with default culture version. /// public bool CombineWithDefaultCulture { get { return ValidationHelper.GetBoolean(GetValue("CombineWithDefaultCulture"), lstElem.CombineWithDefaultCulture); } set { SetValue("CombineWithDefaultCulture", value); lstElem.CombineWithDefaultCulture = value; } } /// /// Gets or sets the culture code of the documents. /// public string CultureCode { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("CultureCode"), lstElem.CultureCode), lstElem.CultureCode); } set { SetValue("CultureCode", value); lstElem.CultureCode = value; } } /// /// Gets or sets the maximal relative level of the documents to be shown. /// public int MaxRelativeLevel { get { return ValidationHelper.GetInteger(GetValue("MaxRelativeLevel"), lstElem.MaxRelativeLevel); } set { SetValue("MaxRelativeLevel", value); lstElem.MaxRelativeLevel = value; } } /// /// Gets or sets the order by clause. /// public string OrderBy { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("OrderBy"), lstElem.OrderBy), lstElem.OrderBy); } set { SetValue("OrderBy", value); lstElem.OrderBy = value; } } /// /// Gets or sets the path of the documents. /// public string Path { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("Path"), null), null); } set { SetValue("Path", value); lstElem.Path = value; } } /// /// Gets or sets the value that indicates whether only published documents are selected. /// public bool SelectOnlyPublished { get { return ValidationHelper.GetBoolean(GetValue("SelectOnlyPublished"), lstElem.SelectOnlyPublished); } set { SetValue("SelctOnlyPublished", value); lstElem.SelectOnlyPublished = value; } } /// /// Gets or sets the value that indicates whether filter out duplicate documents. /// public bool FilterOutDuplicates { get { return ValidationHelper.GetBoolean(GetValue("FilterOutDuplicates"), lstElem.FilterOutDuplicates); } set { SetValue("FilterOutDuplicates", value); lstElem.FilterOutDuplicates = value; } } /// /// Gets or sets the site name. /// public string SiteName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("SiteName"), lstElem.SiteName), lstElem.SiteName); } set { SetValue("SiteName", value); lstElem.SiteName = value; } } /// /// Gets or sets the where condition. /// public string WhereCondition { get { return DataHelper.GetNotEmpty(GetValue("WhereCondition"), lstElem.WhereCondition); } set { SetValue("WhereCondition", value); lstElem.WhereCondition = value; } } /// /// Gets or sets the number which indicates how many documents should be displayed. /// public int SelectTopN { get { return ValidationHelper.GetInteger(GetValue("SelectTopN"), lstElem.SelectTopN); } set { SetValue("SelectTopN", value); lstElem.SelectTopN = value; } } /// /// Gets or sets the columns to get. /// public string Columns { get { return DataHelper.GetNotEmpty(GetValue("Columns"), lstElem.Columns); } set { SetValue("Columns", value); lstElem.Columns = value; } } #endregion #region "Pager properties" /// /// Gets DataPager instance. /// public DataPager PagerControl { get { return lstElem.PagerControl; } } /// /// Gets or sets the value that indicates whether paging is enabled. /// public bool EnablePaging { get { return ValidationHelper.GetBoolean(GetValue("EnablePaging"), lstElem.EnablePaging); } set { SetValue("EnablePaging", value); lstElem.EnablePaging = value; } } /// /// Gets or sets the pager position. /// public PagingPlaceTypeEnum PagerPosition { get { return PagerControl.GetPagerPosition(DataHelper.GetNotEmpty(GetValue("PagerPosition"), PagerControl.PagerPosition.ToString())); } set { SetValue("PagerPosition", value.ToString()); PagerControl.PagerPosition = value; } } /// /// Gets or sets the number of the documents displayed on each sigle page. /// public int PageSize { get { return ValidationHelper.GetInteger(GetValue("PageSize"), lstElem.PageSize); } set { SetValue("PageSize", value); lstElem.PageSize = value; } } /// /// Gets or sets the pager query string key. /// public string QueryStringKey { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("QueryStringKey"), PagerControl.QueryStringKey), PagerControl.QueryStringKey); } set { SetValue("QueryStringKey", value); PagerControl.QueryStringKey = value; } } /// /// Gets or sets the paging mode. /// public PagingModeTypeEnum PagingMode { get { return PagerControl.GetPagingMode(DataHelper.GetNotEmpty(GetValue("PagingMode"), PagerControl.PagingMode.ToString())); } set { SetValue("PagingMode", value.ToString()); PagerControl.PagingMode = value; } } /// /// Gets or sets the navigation mode. /// public BackNextLocationTypeEnum BackNextLocation { get { return PagerControl.GetBackNextLocation(DataHelper.GetNotEmpty(GetValue("BackNextLocation"), PagerControl.BackNextLocation.ToString())); } set { SetValue("BackNextLocation", value.ToString()); PagerControl.BackNextLocation = value; } } /// /// Gets or sets the value that indicates whether first and last page is shown if paging is allowed. /// public bool ShowFirstLast { get { return ValidationHelper.GetBoolean(GetValue("ShowFirstLast"), PagerControl.ShowFirstLast); } set { SetValue("ShowFirstLast", value); PagerControl.ShowFirstLast = value; } } /// /// Gets or sets the html before pager. /// public string PagerHTMLBefore { get { return ValidationHelper.GetString(GetValue("PagerHTMLBefore"), PagerControl.PagerHTMLBefore); } set { SetValue("PagerHTMLBefore", value); PagerControl.PagerHTMLBefore = value; } } /// /// Gets or sets the html after pager. /// public string PagerHTMLAfter { get { return ValidationHelper.GetString(GetValue("PagerHTMLAfter"), PagerControl.PagerHTMLAfter); } set { SetValue("PagerHTMLAfter", value); PagerControl.PagerHTMLAfter = value; } } /// /// Gets or sets the results position. /// public ResultsLocationTypeEnum ResultsPosition { get { return PagerControl.GetResultPosition(ValidationHelper.GetString(GetValue("ResultsPosition"), "")); } set { SetValue("ResultsPosition", value); PagerControl.ResultsLocation = value; } } /// /// Gets or sets page numbers separator. /// public string PageNumbersSeparator { get { return ValidationHelper.GetString(GetValue("PageNumbersSeparator"), PagerControl.PageNumbersSeparator); } set { SetValue("PageNumbersSeparator", value); PagerControl.PageNumbersSeparator = value; } } #endregion #region "Relationships properties" /// /// Gets or sets the value that indicates whether related node is on the left side. /// public bool RelatedNodeIsOnTheLeftSide { get { return ValidationHelper.GetBoolean(GetValue("RelatedNodeIsOnTheLeftSide"), lstElem.RelatedNodeIsOnTheLeftSide); } set { SetValue("RelatedNodeIsOnTheLeftSide", value); lstElem.RelatedNodeIsOnTheLeftSide = value; } } /// /// Gets or sets the relationship name. /// public string RelationshipName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("RelationshipName"), lstElem.RelationshipName), lstElem.RelationshipName); } set { SetValue("RelationshipName", value); lstElem.RelationshipName = value; } } /// /// Gets or sets the relationship with node GUID. /// public Guid RelationshipWithNodeGUID { get { return ValidationHelper.GetGuid(GetValue("RelationshipWithNodeGuid"), lstElem.RelationshipWithNodeGuid); } set { SetValue("RelationshipWithNodeGuid", value); lstElem.RelationshipWithNodeGuid = value; } } #endregion #region "Transformation properties" /// /// Gets or sets the name of the transforamtion which is used for displaying the results. /// public string TransformationName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("TransformationName"), lstElem.TransformationName), lstElem.TransformationName); } set { SetValue("TransformationName", value); lstElem.TransformationName = value; } } /// /// Gets or sets the name of the transforamtion which is used for displaying the results of the selected item. /// public string SelectedItemTransformationName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("SelectedItemTransformationName"), lstElem.SelectedItemTransformationName), lstElem.SelectedItemTransformationName); } set { SetValue("SelectedItemTransformationName", value); lstElem.SelectedItemTransformationName = value; } } /// /// Gets or sets the name of the transforamtion which is used for displaying the alternate results. /// public string AlternatingTransformationName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("AlternatingTransformationName"), lstElem.AlternatingTransformationName), lstElem.AlternatingTransformationName); } set { SetValue("AlternatingTransformationName", value); lstElem.AlternatingTransformationName = value; } } #endregion #region "Public properties" /// /// Gets or sets the nested controls IDs. Use ';' like separator. /// public string NestedControlsID { get { return ValidationHelper.GetString(GetValue("NestedControlsID"), lstElem.NestedControlsID); } set { SetValue("NestedControlsID", value); lstElem.NestedControlsID = 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"), lstElem.HideControlForZeroRows); } set { SetValue("HideControlForZeroRows", value); lstElem.HideControlForZeroRows = value; } } /// /// Gets or sets the text which is displayed for zero rows result. /// public string ZeroRowsText { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("ZeroRowsText"), lstElem.ZeroRowsText), lstElem.ZeroRowsText); } set { SetValue("ZeroRowsText", value); lstElem.ZeroRowsText = value; } } /// /// Gets or sets the count of repeat columns. /// public int RepeatColumns { get { return ValidationHelper.GetInteger(GetValue("RepeatColumns"), lstElem.RepeatColumns); } set { SetValue("RepeatColumns", value); lstElem.RepeatColumns = value; } } /// /// Gets or sets whether control is displayed in a table or flow layout. /// public RepeatLayout RepeatLayout { get { return CMSDataList.GetRepeatLayout(DataHelper.GetNotEmpty(GetValue("RepeatLayout"), lstElem.RepeatLayout.ToString())); } set { SetValue("RepeatLayout", value.ToString()); lstElem.RepeatLayout = value; } } /// /// Gets or sets whether DataList control displays vertically or horizontally. /// public RepeatDirection RepeatDirection { get { return CMSDataList.GetRepeatDirection(DataHelper.GetNotEmpty(GetValue("RepeatDirection"), lstElem.RepeatDirection.ToString())); } set { SetValue("RepeatDirection", value.ToString()); lstElem.RepeatDirection = value; } } /// /// Filter name. /// public string FilterName { get { return ValidationHelper.GetString(GetValue("FilterName"), lstElem.FilterName); } set { SetValue("FilterName", value); lstElem.FilterName = value; } } /// /// DataList control. /// public CMSDataList DataListControl { get { return lstElem; } } #endregion #region "Editing mode buttons properties" /// /// Gets or sets the value that inidcates whether 'New button' should be displayed. /// public bool ShowNewButton { get { return ValidationHelper.GetBoolean(GetValue("ShowNewButton"), btnAdd.Visible); } set { SetValue("ShowNewButton", value); btnAdd.Visible = value; } } /// /// Gets or sets the new button text. /// public string NewButtonText { get { return DataHelper.GetNotEmpty(GetValue("NewButtonText"), btnAdd.Text); } set { SetValue("NewButtonText", value); btnAdd.Text = value; } } /// /// Gets or sets the value that indicates whether edit and delete buttons should be displayed. /// public bool ShowEditDeleteButtons { get { return ValidationHelper.GetBoolean(GetValue("ShowEditDeleteButtons"), lstElem.ShowEditDeleteButtons); } set { SetValue("ShowEditDeleteButtons", value); lstElem.ShowEditDeleteButtons = value; } } #endregion #region "Data binding properties" /// /// Gets or sets the value that indicates whether databind will be proceeded automatically. /// public bool DataBindByDefault { get { return ValidationHelper.GetBoolean(GetValue("DataBindByDefault"), lstElem.DataBindByDefault); } set { SetValue("DataBindByDefault", value); lstElem.DataBindByDefault = value; } } #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; lstElem.StopProcessing = value; } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { // In design mode is pocessing of control stoped if (StopProcessing) { lstElem.StopProcessing = true; } else { lstElem.ControlContext = ControlContext; // Document properties lstElem.NestedControlsID = NestedControlsID; lstElem.CacheItemName = CacheItemName; lstElem.CacheDependencies = CacheDependencies; lstElem.CacheMinutes = CacheMinutes; lstElem.CheckPermissions = CheckPermissions; lstElem.ClassNames = ClassNames; lstElem.CategoryName = CategoryName; lstElem.CombineWithDefaultCulture = CombineWithDefaultCulture; lstElem.FilterOutDuplicates = FilterOutDuplicates; lstElem.CultureCode = CultureCode; lstElem.Path = Path; lstElem.MaxRelativeLevel = MaxRelativeLevel; lstElem.OrderBy = OrderBy; lstElem.SelectTopN = SelectTopN; lstElem.Columns = Columns; lstElem.SelectOnlyPublished = SelectOnlyPublished; lstElem.SiteName = SiteName; lstElem.WhereCondition = WhereCondition; // Relationships lstElem.RelatedNodeIsOnTheLeftSide = RelatedNodeIsOnTheLeftSide; lstElem.RelationshipName = RelationshipName; lstElem.RelationshipWithNodeGuid = RelationshipWithNodeGUID; // Transformations lstElem.SelectedItemTransformationName = SelectedItemTransformationName; lstElem.AlternatingTransformationName = AlternatingTransformationName; lstElem.TransformationName = TransformationName; // Pager lstElem.EnablePaging = EnablePaging; lstElem.PageSize = PageSize; PagerControl.PagerPosition = PagerPosition; PagerControl.QueryStringKey = QueryStringKey; PagerControl.PagingMode = PagingMode; PagerControl.BackNextLocation = BackNextLocation; PagerControl.ShowFirstLast = ShowFirstLast; PagerControl.PagerHTMLBefore = PagerHTMLBefore; PagerControl.PagerHTMLAfter = PagerHTMLAfter; PagerControl.ResultsLocation = ResultsPosition; PagerControl.PageNumbersSeparator = PageNumbersSeparator; // Public lstElem.RepeatColumns = RepeatColumns; lstElem.RepeatLayout = RepeatLayout; lstElem.RepeatDirection = RepeatDirection; lstElem.HideControlForZeroRows = HideControlForZeroRows; lstElem.ZeroRowsText = ZeroRowsText; lstElem.FilterName = FilterName; // Binding lstElem.DataBindByDefault = DataBindByDefault; // Editing buttons lstElem.ShowEditDeleteButtons = ShowEditDeleteButtons; // CMSEditModeButtonAdd btnAdd.Visible = ShowNewButton; btnAdd.Text = NewButtonText; string[] mClassNames = lstElem.ClassNames.Split(';'); btnAdd.ClassName = DataHelper.GetNotEmpty(mClassNames[0], ""); string mPath = ""; if (lstElem.Path.EndsWithCSafe("/%")) { mPath = lstElem.Path.Remove(lstElem.Path.Length - 2); } if (lstElem.Path.EndsWithCSafe("/")) { mPath = lstElem.Path.Remove(lstElem.Path.Length - 1); } btnAdd.Path = DataHelper.GetNotEmpty(mPath, ""); // Add repeater to the filter collection CMSControlsHelper.SetFilter(ValidationHelper.GetString(GetValue("WebPartControlID"), ClientID), lstElem); } } /// /// OnPrerender override (Set visibility). /// protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); Visible = lstElem.Visible && !StopProcessing; if (DataHelper.DataSourceIsEmpty(lstElem.DataSource) && HideControlForZeroRows) { Visible = false; } // Hide the Add button for selected items which have the SelectedItem transformation specified if (lstElem.IsSelected && !string.IsNullOrEmpty(lstElem.SelectedItemTransformationName)) { btnAdd.Visible = false; } } /// /// Reloads data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); lstElem.ReloadData(true); } /// /// Clears cache. /// public override void ClearCache() { lstElem.ClearCache(); } }