using System;
using System.Web.UI;
using System.Data;
using CMS.ExtendedControls;
using CMS.GlobalHelper;
using CMS.UIControls;
using CMS.SettingsProvider;
public partial class CMSModules_Content_Controls_Dialogs_Selectors_FileSystemSelector_FileSystemView : CMSUserControl
{
private const char ARG_SEPARATOR = '|';
#region "Private variables"
private FileSystemDialogConfiguration mConfig;
private string mStartingPath = "";
private string mSearchText = "";
protected string mSaveText;
#endregion
#region "Public properties"
///
/// Gets or sets the value which determineds whtether to show the Parent button or not.
///
public bool ShowParentButton
{
get
{
return plcParentButton.Visible;
}
set
{
plcParentButton.Visible = value;
}
}
///
/// Gets or sets ID of the parent of the curently selected node.
///
public string NodeParentID
{
get
{
return ValidationHelper.GetString(hdnLastNodeParentID.Value, "");
}
set
{
hdnLastNodeParentID.Value = value;
}
}
///
/// Gets or sets text of the information label.
///
public string InfoText
{
get
{
return innermedia.InfoText;
}
set
{
innermedia.InfoText = value;
}
}
///
/// Gets current dialog configuration.
///
public FileSystemDialogConfiguration Config
{
get
{
if (mConfig == null)
{
mConfig = new FileSystemDialogConfiguration();
}
return mConfig;
}
set
{
mConfig = value;
}
}
///
/// Indicates whether the content tree is displaying more than max tree nodes.
///
public bool IsDisplayMore
{
get
{
return innermedia.IsDisplayMore;
}
set
{
innermedia.IsDisplayMore = value;
}
}
///
/// Gets or sets starting path of control.
///
public string StartingPath
{
get
{
return mStartingPath;
}
set
{
mStartingPath = value.StartsWithCSafe("~/") ? Server.MapPath(value) : value;
}
}
///
/// Search text to filter data.
///
public string SearchText
{
get
{
mSearchText = ValidationHelper.GetString(ViewState["SearchText"], "");
return mSearchText;
}
set
{
mSearchText = value;
ViewState["SearchText"] = mSearchText;
}
}
///
/// Data source
///
public DataSet DataSource
{
get
{
return innermedia.DataSource;
}
set
{
innermedia.DataSource = value;
}
}
///
/// Gets or sets a view mode used to display files.
///
public DialogViewModeEnum ViewMode
{
get
{
return innermedia.ViewMode;
}
set
{
innermedia.ViewMode = value;
}
}
///
/// Messages placeholder
///
public override MessagesPlaceHolder MessagesPlaceHolder
{
get
{
return plcMess;
}
}
#endregion
#region "Control events"
protected void Page_Load(object sender, EventArgs e)
{
// If processing the request should not continue
if (StopProcessing)
{
Visible = false;
}
else
{
// Initialize controls
SetupControls();
}
}
///
/// PreRender event handler
///
/// Event arguments
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (String.IsNullOrEmpty(lblListingInfo.Text))
{
RefreshPathInfo();
}
}
///
/// Loads control's content.
///
public void Reload()
{
// Initialize controls
SetupControls();
ReloadData();
}
///
/// Displays listing info message.
///
/// Info message to display
public void DisplayListingInfo(string infoMsg)
{
if (!string.IsNullOrEmpty(infoMsg))
{
plcListingInfo.Visible = true;
lblListingInfo.Text = infoMsg;
}
}
#endregion
#region "Private methods"
///
/// Initializes all nested controls.
///
private void SetupControls()
{
InitializeControlScripts();
// Initialize inner view control
innermedia.FileSystemPath = StartingPath;
// Set grid definition
innermedia.ListViewControl.GridName = Config.ShowFolders ? "~/CMSModules/Content/Controls/Dialogs/Selectors/FileSystemSelector/FolderView.xml" : "~/CMSModules/Content/Controls/Dialogs/Selectors/FileSystemSelector/FileSystemView.xml";
// Set inner control binding columns
innermedia.FileIdColumn = "path";
innermedia.FileNameColumn = "name";
innermedia.FileExtensionColumn = "type";
innermedia.FileSizeColumn = "size";
innermedia.SearchText = SearchText;
// Register for inner media events
innermedia.GetArgumentSet += innermedia_GetArgumentSet;
// Parent directory button
if ((ShowParentButton) && (!string.IsNullOrEmpty(NodeParentID)))
{
plcParentButton.Visible = true;
imgParent.ImageUrl = GetImageUrl("CMSModules/CMS_Content/Dialogs/parent.png");
mSaveText = GetString("dialogs.mediaview.parentfolder");
btnParent.OnClientClick = String.Format("SelectNode('{0}');SetParentAction('{0}'); return false;", NodeParentID.Replace("\\", "\\\\").Replace("'", "\\'"));
}
innermedia.Configuration = Config;
innermedia.ViewMode = ViewMode;
}
///
/// Initializes scrips used by the control.
///
private void InitializeControlScripts()
{
const string script = @"
function SetTreeRefreshAction(path) {
SetAction('refreshtree', path);
RaiseHiddenPostBack();
}
function SetRefreshAction() {
SetAction('refresh', '');
RaiseHiddenPostBack();
}
function SetDeleteAction(argument) {
SetAction('delete', argument);
RaiseHiddenPostBack();
}
function SetSelectAction(argument) {
SetAction('select', argument);
RaiseHiddenPostBack();
}
function SetParentAction(argument) {
SetAction('parentselect', argument);
RaiseHiddenPostBack();
}";
ScriptManager.RegisterStartupScript(this, GetType(), "DialogsSelectAction", script, true);
}
///
/// Loads data from data source property.
///
private void ReloadData()
{
innermedia.Reload(true);
RefreshPathInfo();
}
///
/// Refreshes the path information
///
private void RefreshPathInfo()
{
// Get relative path
string path = StartingPath;
if (!String.IsNullOrEmpty(path))
{
string appPath = SettingsKeyProvider.WebApplicationPhysicalPath;
if (path.StartsWithCSafe(appPath, true))
{
path = "~" + path.Substring(appPath.Length).Replace('\\', '/');
}
// Display information about current path
string info = String.Format(GetString("FileSystemSelector.Info"), path);
DisplayListingInfo(info);
}
}
#endregion
#region "Inner media view event handlers"
///
/// Returns argument set according passed DataRow and flag indicating whether the set is obtained for selected item.
///
/// DataRow with all the item data
/// Indicates whether the set is required for an selected item
private string innermedia_GetArgumentSet(DataRow dr)
{
// Return required argument set
return GetArgumentSet(dr);
}
#endregion
#region "Helper methods"
///
/// Returns argument set for the passed file data row.
///
/// Data row object holding all the data on current file
private string GetArgumentSet(DataRow dr)
{
// Common information for both content & attachments
string result = String.Format("{1}{0}{2}{0}{3}", ARG_SEPARATOR, dr[innermedia.FileIdColumn].ToString().Replace("\\", "\\\\"), DataHelper.GetSizeString(ValidationHelper.GetLong(dr[innermedia.FileSizeColumn], 0)), dr["isfile"]);
return result;
}
///
/// Ensures no item is selected.
///
public void ResetSearch()
{
dialogSearch.ResetSearch();
SearchText = "";
}
#endregion
}