using System;
using CMS.CMSHelper;
using CMS.ExtendedControls;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.SiteProvider;
public partial class CMSModules_Content_FormControls_Documents_SelectPath : FormEngineUserControl
{
#region "Variables"
private bool mEnableSiteSelection = false;
private DialogConfiguration mConfig = null;
private string selectedSiteName = null;
private bool siteNameIsAll = false;
private int mSiteId = 0;
#endregion
#region "Private properties"
///
/// Gets the configuration for Copy and Move dialog.
///
private DialogConfiguration Config
{
get
{
if (mConfig == null)
{
mConfig = new DialogConfiguration();
mConfig.HideLibraries = true;
mConfig.HideAnchor = true;
mConfig.HideAttachments = true;
mConfig.HideContent = false;
mConfig.HideEmail = true;
mConfig.HideLibraries = true;
mConfig.HideWeb = true;
mConfig.EditorClientID = txtPath.ClientID;
bool onlyCurrentSite = String.IsNullOrEmpty(selectedSiteName) || (selectedSiteName.ToLowerCSafe() == "##currentsite##");
if (ControlsHelper.CheckControlContext(this, ControlContext.WIDGET_PROPERTIES)
&& (!siteNameIsAll))
{
// If used in a widget, site selection is provided by a site selector form control (using HasDependingField/DependsOnAnotherField principle)
// therefore the site selector drop-down list in the SelectPath dialog contains only a single site - preselected by the site selector form control
mConfig.ContentSites = onlyCurrentSite ? AvailableSitesEnum.OnlyCurrentSite : AvailableSitesEnum.OnlySingleSite;
}
else
{
mConfig.ContentSites = AvailableSitesEnum.All;
}
mConfig.ContentSelectedSite = onlyCurrentSite ? CMSContext.CurrentSiteName : selectedSiteName;
mConfig.OutputFormat = OutputFormatEnum.Custom;
mConfig.CustomFormatCode = "selectpath";
mConfig.SelectableContent = SelectableContentEnum.AllContent;
if (SubItemsNotByDefault)
{
mConfig.AdditionalQueryParameters = "SubItemsNotByDefault=1";
}
}
return mConfig;
}
}
#endregion
#region "Public properties"
///
/// Gets or sets the ID of the site from which the path is selected.
///
public int SiteID
{
get
{
return mSiteId;
}
set
{
mSiteId = value;
if (value > 0)
{
Config.ContentSites = AvailableSitesEnum.OnlySingleSite;
SiteInfo si = SiteInfoProvider.GetSiteInfo(value);
if (si != null)
{
Config.ContentSelectedSite = si.SiteName;
}
}
}
}
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
txtPath.Enabled = value;
btnSelectPath.Enabled = value;
}
}
///
/// Gets or sets field value.
///
public override object Value
{
get
{
return txtPath.Text;
}
set
{
txtPath.Text = (string)value;
}
}
///
/// Gets ClientID of the textbox with path.
///
public override string ValueElementID
{
get
{
return txtPath.ClientID;
}
}
///
/// Determines whether to enable site selection or not.
///
public bool EnableSiteSelection
{
get
{
return mEnableSiteSelection;
}
set
{
mEnableSiteSelection = value;
Config.ContentSites = (value ? AvailableSitesEnum.All : AvailableSitesEnum.OnlyCurrentSite);
}
}
///
/// Indicates whether check box "Only sub items" is checked by default or not.
///
public bool SubItemsNotByDefault
{
get;
set;
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
ScriptHelper.RegisterDialogScript(Page);
SetFormSiteName();
btnSelectPath.Text = GetString("general.select");
btnSelectPath.OnClientClick = GetDialogScript();
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (URLHelper.IsPostback()
&& DependsOnAnotherField)
{
if (siteNameIsAll)
{
// Refresh the dialog script if the site name was changed to "ALL" (this enables the site selection in the dialog window)
btnSelectPath.OnClientClick = GetDialogScript();
}
pnlUpdate.Update();
}
}
///
/// Gets the javascript which opens the dialog window.
///
/// Javascript which opens the dialog window.
private string GetDialogScript()
{
return "modalDialog('" + GetDialogUrl() + "','PathSelection', '90%', '85%'); return false;";
}
///
/// Returns Correct URL of the copy or move dialog.
///
private string GetDialogUrl()
{
string url = CMSDialogHelper.GetDialogUrl(Config, IsLiveSite, false, null, false);
return url;
}
///
/// Sets the site name if the SiteName field is available in the form.
/// The outcome of this method is used for the configuration of the "Config" property
///
private void SetFormSiteName()
{
if (DependsOnAnotherField
&& (Form != null)
&& Form.IsFieldAvailable("SiteName"))
{
string siteName = ValidationHelper.GetString(Form.GetFieldValue("SiteName"), "");
if (siteName.EqualsCSafe(string.Empty, true) || siteName.EqualsCSafe("##all##", true))
{
selectedSiteName = string.Empty;
siteNameIsAll = true;
return;
}
if (!String.IsNullOrEmpty(siteName))
{
selectedSiteName = siteName;
return;
}
}
selectedSiteName = null;
}
}