using System;
using System.Web.UI.WebControls;
using CMS.CMSHelper;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.UIControls;
public partial class CMSFormControls_Classes_SelectClassNames : FormEngineUserControl
{
#region "Variables"
private bool mDisplayClearButton = true;
#endregion
#region "Public properties"
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
if (uniSelector != null)
{
uniSelector.Enabled = value;
}
}
}
///
/// Returns ClientID of the textbox with classnames.
///
public override string ValueElementID
{
get
{
return uniSelector.TextBoxSelect.ClientID;
}
}
///
/// Gets or sets the field value.
///
public override object Value
{
get
{
return uniSelector.Value;
}
set
{
if (uniSelector == null)
{
pnlUpdate.LoadContainer();
}
uniSelector.Value = value;
}
}
///
/// Gets inner uniselector.
///
public UniSelector UniSelector
{
get
{
return uniSelector;
}
}
///
/// Gets dropdown list.
///
public DropDownList DropDownSingleSelect
{
get
{
EnsureChildControls();
return uniSelector.DropDownSingleSelect;
}
}
///
/// Gets or sets the value which determines, whether to display Clear button.
///
public bool DisplayClearButton
{
get
{
return mDisplayClearButton;
}
set
{
mDisplayClearButton = value;
if (uniSelector != null)
{
uniSelector.AllowEmpty = value;
}
}
}
///
/// Gets or sets the SiteID value to filter classnames.
///
public int SiteID
{
get
{
return ValidationHelper.GetInteger(GetValue("SiteID"), 0);
}
set
{
SetValue("SiteID", value);
}
}
///
/// Indicates if should be shown only document types.
///
public bool ShowOnlyCoupled
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowOnlyCoupled"), false);
}
set
{
SetValue("ShowOnlyCoupled", value);
}
}
///
/// If true, wireframe document type is hidden
///
public bool HideWireframe
{
get;
set;
}
#endregion
#region "Constructors"
public CMSFormControls_Classes_SelectClassNames()
{
SiteID = CMSContext.CurrentSiteID;
}
#endregion
#region "Methods"
protected void Page_Load(object sender, EventArgs e)
{
if (StopProcessing)
{
uniSelector.StopProcessing = true;
}
else
{
ReloadData(false);
}
}
protected override void EnsureChildControls()
{
if (uniSelector == null)
{
pnlUpdate.LoadContainer();
}
base.EnsureChildControls();
}
///
/// Reloads the data in the selector.
///
/// Indicates if data should be loaded from DB
public void ReloadData(bool forceReload)
{
uniSelector.IsLiveSite = IsLiveSite;
uniSelector.AllowEmpty = DisplayClearButton;
// Where condition
string where = null;
// Show only document types
if (ShowOnlyCoupled)
{
where = SqlHelperClass.AddWhereCondition(where, "ClassIsCoupledClass = 1");
}
// Hide wireframe doc type
if (HideWireframe)
{
where = SqlHelperClass.AddWhereCondition(where, "ClassName <> 'cms.wireframe'");
}
// Filter using Site ID
if (SiteID > 0)
{
where = SqlHelperClass.AddWhereCondition(where, "ClassID IN (SELECT ClassID FROM CMS_ClassSite WHERE SiteID = " + SiteID + ")");
}
uniSelector.WhereCondition = where;
uniSelector.Reload(forceReload);
}
///
/// Returns true if user control is valid.
///
public override bool IsValid()
{
string[] values = ValidationHelper.GetString(uniSelector.Value, "").Split(new char[] { ';' });
foreach (string className in values)
{
if ((className != "") && !MacroResolver.ContainsMacro(className) && !className.Contains("*"))
{
DataClassInfo di = DataClassInfoProvider.GetDataClass(className);
if (di == null)
{
ValidationError = GetString("formcontrols_selectclassnames.notexist").Replace("%%code%%", className);
return false;
}
}
}
return true;
}
#endregion
}