");
}
}
return extension;
}
///
/// Gets title text.
///
/// Source data row
private string GetTitle(IDataContainer data, bool isContentFile)
{
string title = null;
switch (SourceType)
{
case MediaSourceEnum.Attachment:
case MediaSourceEnum.DocumentAttachments:
title = ValidationHelper.GetString(data.GetValue("AttachmentTitle"), null);
break;
case MediaSourceEnum.Content:
if (isContentFile)
{
title = ValidationHelper.GetString(data.GetValue("AttachmentTitle"), null);
}
break;
case MediaSourceEnum.MediaLibraries:
title = ValidationHelper.GetString(data.GetValue("FileTitle"), null);
break;
case MediaSourceEnum.MetaFile:
title = ValidationHelper.GetString(data.GetValue("MetaFileTitle"), null);
break;
}
return title;
}
///
/// Gets description text.
///
/// Source data row
private string GetDescription(IDataContainer data, bool isContentFile)
{
string desc = null;
switch (SourceType)
{
case MediaSourceEnum.Attachment:
case MediaSourceEnum.DocumentAttachments:
desc = ValidationHelper.GetString(data.GetValue("AttachmentDescription"), null);
break;
case MediaSourceEnum.Content:
if (isContentFile)
{
desc = ValidationHelper.GetString(data.GetValue("AttachmentDescription"), null);
}
break;
case MediaSourceEnum.MediaLibraries:
desc = ValidationHelper.GetString(data.GetValue("FileDescription"), null);
break;
case MediaSourceEnum.MetaFile:
desc = ValidationHelper.GetString(data.GetValue("MetaFileDescription"), null);
break;
}
return desc;
}
#endregion
#region "List view methods"
///
/// Initializes list view controls.
///
private void InitializeListView()
{
switch (SourceType)
{
case MediaSourceEnum.Content:
gridList.OrderBy = "NodeOrder";
break;
case MediaSourceEnum.MediaLibraries:
gridList.OrderBy = "FileName";
break;
case MediaSourceEnum.DocumentAttachments:
gridList.OrderBy = "AttachmentOrder, AttachmentName, AttachmentID";
break;
case MediaSourceEnum.MetaFile:
gridList.OrderBy = "MetaFileName, MetaFileID";
break;
default:
break;
}
gridList.OnBeforeDataReload += gridList_OnBeforeDataReload;
}
private void gridList_OnBeforeDataReload()
{
gridList.PagerForceNumberOfResults = DataHelper.GetItemsCount(DataSource);
gridList.DataSource = DataSource;
}
///
/// Reloads list view according source type.
///
private void ReloadListView()
{
// Fill the grid data source
if (!DataHelper.DataSourceIsEmpty(DataSource))
{
// Disable sorting if is copy/move dialog
if ((IsCopyMoveLinkDialog) && (DisplayMode == ControlDisplayModeEnum.Simple))
{
gridList.GridView.AllowSorting = false;
}
gridList.ReloadData();
}
}
///
/// Ensures no item is selected.
///
public void ResetListSelection()
{
if (gridList != null)
{
gridList.ResetSelection();
}
}
///
/// Ensures first page is displayed in the control displaying the content.
///
public void ResetPageIndex()
{
if (ViewMode == DialogViewModeEnum.ListView)
{
ListViewControl.Pager.UniPager.CurrentPage = 1;
}
}
///
/// Returns panel with image according extension of the processed file.
///
/// Extension of the file used to determine icon
/// Class name
/// Url of the original image
/// Control inserted as a file name
/// Preview URL
/// Image width
/// Image height
/// Determines whether it can be selected
/// Determines if tooltip should be generated
/// File title
/// File description
/// File name without extension
private Panel GetListItem(string ext, string className, string url, string previewUrl, int width, int height, Control item, bool isSelectable, bool generateTooltip, string title, string description, string name)
{
Panel pnl = new Panel()
{
CssClass = "DialogListItem" + (isSelectable ? "" : "Unselectable")
};
pnl.Controls.Add(new LiteralControl(""));
// Cast media library folder as 'CMS.Folder'
if ((SourceType == MediaSourceEnum.MediaLibraries) && ext.ToLowerCSafe() == "
")
{
className = "cms.folder";
}
// Prepare image
Image docImg = new Image();
docImg.Attributes["style"] = "width: 16px; height: 16px;";
docImg.CssClass = "FloatLeft";
if ((className == "cms.file") || (className == ""))
{
docImg.ImageUrl = GetFileIconUrl(ext, "List");
// Tooltip
if (generateTooltip)
{
UIHelper.EnsureTooltip(docImg, previewUrl, width, height, title, name, ext, description, null, 300);
}
}
else
{
docImg.ImageUrl = GetDocumentTypeIconUrl(className);
}
pnl.Controls.Add(docImg);
if ((isSelectable) && (item is LinkButton))
{
// Create clickabe compelte panel
pnl.Attributes["onclick"] = ((LinkButton)item).Attributes["onclick"];
((LinkButton)item).Attributes["onclick"] = null;
}
// Add file name
pnl.Controls.Add(new LiteralControl(String.Format(" ", (!isSelectable ? "style=\"cursor:default;\"" : ""))));
pnl.Controls.Add(item);
pnl.Controls.Add(new LiteralControl(""));
return pnl;
}
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dr = (e.Row.DataItem as DataRowView);
if (dr != null)
{
IDataContainer data = new DataRowContainer(dr);
e.Row.Attributes["id"] = GetColorizeID(data);
}
}
}
protected object ListViewControl_OnExternalDataBound(object sender, string sourceName, object parameter)
{
object result = null;
string argument = "";
string url = "";
bool isContent = (SourceType == MediaSourceEnum.Content);
bool notAttachment = false;
bool isContentFile = false;
bool isWebDAVEnabled = CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName);
bool isWindowsAuthentication = RequestHelper.IsWindowsAuthentication();
sourceName = sourceName.ToLowerCSafe();
// Prepare the data
IDataContainer data = null;
if (parameter is DataRowView)
{
data = new DataRowContainer((DataRowView)parameter);
}
else
{
// Get the data row view from parameter
GridViewRow gvr = (parameter as GridViewRow);
if (gvr != null)
{
DataRowView dr = (DataRowView)gvr.DataItem;
if (dr != null)
{
data = new DataRowContainer(dr);
}
}
}
ImageButton btn = null;
DirectFileUploader dfuElem = null;
string ext = null;
string fileName = null;
bool libraryFolder = false;
string className = "";
// Get site id
int siteId = 0;
if (data != null)
{
if (data.ContainsColumn("NodeSiteID"))
{
siteId = ValidationHelper.GetInteger(data.GetValue("NodeSiteID"), 0);
}
else if (data.ContainsColumn("AttachmentSiteID"))
{
siteId = ValidationHelper.GetInteger(data.GetValue("AttachmentSiteID"), 0);
}
else if (data.ContainsColumn("MetaFileSiteID"))
{
siteId = ValidationHelper.GetInteger(data.GetValue("MetaFileSiteID"), 0);
}
else
{
siteId = ValidationHelper.GetInteger(data.GetValue("FileSiteID"), 0);
}
}
// Check if site is running
bool siteIsRunning = true;
SiteInfo siteInfo = CMSContext.CurrentSite;
if (siteId > 0)
{
siteInfo = SiteInfoProvider.GetSiteInfo(siteId);
if (siteInfo != null)
{
siteIsRunning = siteInfo.Status == SiteStatusEnum.Running;
}
}
switch (sourceName)
{
#region "Select"
case "select":
if (sender is ImageButton)
{
btn = ((ImageButton)sender);
// Is current item CMS.File or attachment ?
isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty));
if (notAttachment)
{
className = DataClassInfoProvider.GetDataClass((int)data.GetValue("NodeClassID")).ClassDisplayName;
}
ext = HTMLHelper.HTMLEncode(notAttachment ? className : data.GetValue(FileExtensionColumn).ToString().TrimStart('.'));
// Get file name
fileName = GetFileName(data);
libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
if ((SourceType == MediaSourceEnum.MediaLibraries) && ((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple)))
{
// If folders are displayed as well show SELECT button icon
if (libraryFolder && !IsCopyMoveLinkDialog)
{
btn.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png");
btn.ToolTip = GetString("dialogs.list.actions.showsubfolders");
btn.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else if (libraryFolder && IsCopyMoveLinkDialog)
{
btn.ImageUrl = ResolveUrl(ImagesPath + "next.png");
btn.ToolTip = GetString("general.select");
btn.Attributes["onclick"] = String.Format("SetAction('copymoveselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else
{
// If media file not imported yet - display warning sign
btn.ImageUrl = ResolveUrl(ImagesPath + "warning.png");
btn.ToolTip = GetString("media.file.import");
btn.Attributes["onclick"] = String.Format("SetAction('importfile', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(data.GetValue("FileName").ToString()));
}
}
else
{
// Check if item is selectable, if not remove select action button
bool isSelectable = CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile);
if (!isSelectable)
{
btn.ImageUrl = ResolveUrl(ImagesPath + "transparent.png");
btn.ToolTip = "";
btn.Attributes["style"] = "margin:0px 3px;cursor:default;";
btn.Enabled = false;
}
else
{
argument = RaiseOnGetArgumentSet(data);
// Get item URL
url = RaiseOnGetListItemUrl(data, false, notAttachment);
// Initialize command
btn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(argument + "|URL|" + url));
result = btn;
}
}
}
break;
#endregion
#region "Select sub docs"
case "selectsubdocs":
if (sender is ImageButton)
{
btn = ((ImageButton)sender);
int nodeId = ValidationHelper.GetInteger(data.GetValue("NodeID"), 0);
if (IsFullListingMode)
{
// Check if item is selectable, if not remove select action button
// Initialize command
btn.Attributes["onclick"] = String.Format("SetParentAction('{0}'); return false;", nodeId);
}
else
{
btn.Visible = false;
}
}
break;
#endregion
#region "Select sub folders"
case "selectsubfolders":
if (sender is ImageButton)
{
btn = ((ImageButton)sender);
if (btn != null)
{
string folderName = ValidationHelper.GetString(data.GetValue("FileName"), "");
ext = ValidationHelper.GetString(data.GetValue(FileExtensionColumn), "");
if (IsCopyMoveLinkDialog || (IsFullListingMode && (DisplayMode == ControlDisplayModeEnum.Default) && (ext == "")))
{
// Initialize command
btn.Attributes["onclick"] = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(folderName));
}
else
{
btn.Visible = false;
}
}
}
break;
#endregion
#region "View"
case "view":
if (sender is ImageButton)
{
btn = ((ImageButton)sender);
// Check if current item is library folder
fileName = GetFileName(data);
libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
// Is current item CMS.File or attachment ?
isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty));
if (!notAttachment && !libraryFolder && siteIsRunning)
{
// Get item URL
url = RaiseOnGetListItemUrl(data, false, false);
if (String.IsNullOrEmpty(url))
{
btn.ImageUrl = GetImageUrl("/Design/Controls/UniGrid/Actions/Viewdisabled.png");
btn.OnClientClick = "return false;";
btn.Attributes["style"] = "margin:0px 3px;cursor:default;";
btn.Enabled = false;
}
else
{
// Add latest version requirement for live site
if (IsLiveSite)
{
// Check version history ID
int versionHistoryId = VersionHistoryID;
if (versionHistoryId > 0)
{
// Add requirement for latest version of files for current document
string newparams = "latestforhistoryid=" + versionHistoryId;
newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId);
url = URLHelper.AppendQuery(url, newparams);
}
}
string finalUrl = URLHelper.ResolveUrl(url);
btn.OnClientClick = String.Format("javascript: window.open({0}); return false;", ScriptHelper.GetString(finalUrl));
}
}
else
{
btn.Visible = false;
}
}
break;
#endregion
#region "Edit"
case "edit":
if (sender is ImageButton)
{
// Is current item CMS.File or attachment ?
isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty));
// Get file extension
ext = (notAttachment ? "" : data.GetValue(FileExtensionColumn).ToString().TrimStart('.'));
Guid guid = Guid.Empty;
ImageButton imgEdit = (ImageButton)sender;
if ((SourceType == MediaSourceEnum.MediaLibraries) && siteIsRunning)
{
libraryFolder = (IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
if (!libraryFolder)
{
guid = ValidationHelper.GetGuid(data.GetValue("FileGUID"), Guid.Empty);
imgEdit.AlternateText = String.Format("{0}|MediaFileGUID={1}&sitename={2}", ext, guid, GetSiteName(data, true));
imgEdit.PreRender += img_PreRender;
imgEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png");
}
else
{
imgEdit.Visible = false;
}
}
else if (!notAttachment && siteIsRunning)
{
string nodeIdQuery = "";
if (SourceType == MediaSourceEnum.Content)
{
nodeIdQuery = "&nodeId=" + data.GetValue("NodeID");
}
// Get the node workflow
VersionHistoryID = ValidationHelper.GetInteger(data.GetValue("DocumentCheckedOutVersionHistoryID"), 0);
guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
imgEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}{3}&versionHistoryId={4}", ext, guid, GetSiteName(data, false), nodeIdQuery, VersionHistoryID);
imgEdit.PreRender += img_PreRender;
imgEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png");
}
else
{
imgEdit.Visible = false;
}
}
break;
#endregion
#region "WebDAV edit"
case "webdavedit":
{
// Prepare the data
DataRowView dr = parameter as DataRowView;
if (dr != null)
{
data = new DataRowContainer(dr);
}
if ((SourceType == MediaSourceEnum.MediaLibraries) && siteIsRunning)
{
PlaceHolder plcUpd = new PlaceHolder();
plcUpd.ID = "plcUdateColumn";
Panel pnlBlock = new Panel();
pnlBlock.ID = "pnlBlock";
pnlBlock.CssClass = "TableCell";
plcUpd.Controls.Add(pnlBlock);
string fileExtension = ValidationHelper.GetString(data.GetValue("FileExtension"), null);
// If the WebDAV is enabled and windows authentication and extension is allowed
if (isWebDAVEnabled && isWindowsAuthentication && WebDAVSettings.IsExtensionAllowedForEditMode(fileExtension, CMSContext.CurrentSiteName))
{
// Dynamically load control
WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl;
// Set editor's properties
if (webDAVElem != null)
{
GetWebDAVEditControl(ref webDAVElem, data);
// Add to panel
pnlBlock.Controls.Add(webDAVElem);
columnUpdateVisible = true;
}
}
return plcUpd;
}
else if ((SourceType == MediaSourceEnum.Content) && (OutputFormat != OutputFormatEnum.Custom) && siteIsRunning)
{
PlaceHolder plcUpd = new PlaceHolder();
plcUpd.ID = "plcUdateColumn";
Panel pnlBlock = new Panel();
pnlBlock.ID = "pnlBlock";
pnlBlock.CssClass = "TableCell";
plcUpd.Controls.Add(pnlBlock);
string fileExtension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), null);
// If the WebDAV is enabled and windows authentication and extension is allowed
if (isWebDAVEnabled && isWindowsAuthentication && WebDAVSettings.IsExtensionAllowedForEditMode(fileExtension, CMSContext.CurrentSiteName))
{
// Dynamically load control
WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl;
// Set editor's properties
if (webDAVElem != null)
{
webDAVElem.Visible = false;
GetWebDAVEditControl(ref webDAVElem, data);
// Add to panel
pnlBlock.Controls.Add(webDAVElem);
columnUpdateVisible = true;
}
}
return plcUpd;
}
}
break;
#endregion
#region "Edit library ui"
case "editlibraryui":
if (sender is ImageButton)
{
ImageButton imgEdit = (ImageButton)sender;
if (imgEdit != null)
{
// Get file name
fileName = GetFileName(data);
bool notInDatabase = ((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple));
// Check if current item is library folder
libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && notInDatabase && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
ext = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString();
if (libraryFolder)
{
imgEdit.Visible = false;
}
else if (notInDatabase)
{
imgEdit.ImageUrl = ResolveUrl(ImagesPath + "editdisabled.png");
imgEdit.Attributes["style"] = "margin:0px 3px;cursor:default;";
imgEdit.Enabled = false;
}
else
{
imgEdit.OnClientClick = String.Format("$j('#hdnFileOrigName').attr('value', {0}); SetAction('editlibraryui', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(EnsureFileName(fileName)), ScriptHelper.GetString(fileName));
}
}
}
break;
#endregion
#region "Delete"
case "delete":
if (sender is ImageButton)
{
// Get file name
fileName = GetFileName(data);
// Check if current item is library folder
libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
ImageButton btnDelete = (ImageButton)sender;
if (btnDelete != null)
{
//btnDelete.ImageUrl = ResolveUrl(ImagesPath + "Delete.png");
btnDelete.ToolTip = GetString("general.delete");
if (((RaiseOnFileIsNotInDatabase(fileName) == null) && (DisplayMode == ControlDisplayModeEnum.Simple)))
{
if (libraryFolder)
{
btnDelete.Visible = false;
}
else
{
btnDelete.Attributes["onclick"] = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
}
else
{
btnDelete.Attributes["onclick"] = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
}
}
break;
#endregion
#region "Name"
case "name":
{
// Is current item CMS.File or attachment ?
isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty));
// Get name and extension
string fileNameColumn = FileNameColumn;
if (notAttachment)
{
fileNameColumn = "DocumentName";
}
string name = HTMLHelper.HTMLEncode(data.GetValue(fileNameColumn).ToString());
ext = (notAttachment ? "" : data.GetValue(FileExtensionColumn).ToString().TrimStart('.'));
if ((SourceType == MediaSourceEnum.DocumentAttachments) || (SourceType == MediaSourceEnum.MetaFile))
{
name = Path.GetFileNameWithoutExtension(name);
}
// Width & height
int width = (data.ContainsColumn(FileWidthColumn) ? ValidationHelper.GetInteger(data.GetValue(FileWidthColumn), 0) : 0);
int height = (data.ContainsColumn(FileHeightColumn) ? ValidationHelper.GetInteger(data.GetValue(FileHeightColumn), 0) : 0);
string cmpltExt = (notAttachment ? "" : "." + ext);
fileName = (cmpltExt != "") ? name.Replace(cmpltExt, "") : name;
if (isContent && !notAttachment)
{
string attachmentName = Path.GetFileNameWithoutExtension(data.GetValue("AttachmentName").ToString());
if (fileName.ToLowerCSafe() != attachmentName.ToLowerCSafe())
{
fileName += String.Format(" ({0})", HTMLHelper.HTMLEncode(data.GetValue("AttachmentName").ToString()));
}
}
className = isContent ? HTMLHelper.HTMLEncode(data.GetValue("ClassName").ToString().ToLowerCSafe()) : "";
isContentFile = (className == "cms.file");
// Check if item is selectable
if (!CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile))
{
LiteralControl ltlName = new LiteralControl(fileName);
// Get final panel
result = GetListItem(ext, className, "", "", width, height, ltlName, false, false, GetTitle(data, isContentFile), GetDescription(data, isContentFile), name);
}
else
{
// Make a file name link
LinkButton lnkBtn = new LinkButton()
{
ID = "n",
Text = HTMLHelper.HTMLEncode(fileName)
};
// Is current item CMS.File or attachment ?
isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty));
fileName = GetFileName(data);
// Try to get imported file row
bool isImported = true;
IDataContainer importedData = null;
if (DisplayMode == ControlDisplayModeEnum.Simple)
{
importedData = RaiseOnFileIsNotInDatabase(fileName);
isImported = (importedData != null);
}
else
{
importedData = data;
}
if (!isImported)
{
importedData = data;
}
else
{
// Update WIDTH
if (importedData.ContainsColumn(FileWidthColumn))
{
width = ValidationHelper.GetInteger(importedData[FileWidthColumn], 0);
}
// Update HEIGHT
if (importedData.ContainsColumn(FileHeightColumn))
{
height = ValidationHelper.GetInteger(importedData[FileHeightColumn], 0);
}
}
argument = RaiseOnGetArgumentSet(data);
url = RaiseOnGetListItemUrl(importedData, false, notAttachment);
string previewUrl = RaiseOnGetListItemUrl(importedData, true, notAttachment);
if (!String.IsNullOrEmpty(previewUrl))
{
// Add chset
string chset = Guid.NewGuid().ToString();
previewUrl = URLHelper.AddParameterToUrl(previewUrl, "chset", chset);
}
// Add latest version requirement for live site
if (!String.IsNullOrEmpty(previewUrl) && IsLiveSite)
{
int versionHistoryId = VersionHistoryID;
if (versionHistoryId > 0)
{
// Add requirement for latest version of files for current document
string newparams = "latestforhistoryid=" + versionHistoryId;
newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId);
//url = URLHelper.AppendQuery(url, newparams);
previewUrl = URLHelper.AppendQuery(previewUrl, newparams);
}
}
// Check if current item is library folder
libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode &&
(data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
if ((SourceType == MediaSourceEnum.MediaLibraries) && (!isImported && (DisplayMode == ControlDisplayModeEnum.Simple)))
{
if (libraryFolder && !IsCopyMoveLinkDialog)
{
lnkBtn.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else if (libraryFolder && IsCopyMoveLinkDialog)
{
lnkBtn.Attributes["onclick"] = String.Format("SetAction('copymoveselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else
{
lnkBtn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fileName));
}
}
else
{
// Initialize command
lnkBtn.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, url)));
}
// Get final panel
result = GetListItem(ext, className, url, previewUrl, width, height, lnkBtn, true, isImported && siteIsRunning, GetTitle(data, isContentFile), GetDescription(data, isContentFile), name);
}
}
break;
#endregion
#region "Type"
case "type":
{
if (isContent)
{
// Is current item CMS.File or attachment ?
isContentFile = (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file");
notAttachment = !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty));
if (notAttachment || (OutputFormat == OutputFormatEnum.HTMLLink) || (OutputFormat == OutputFormatEnum.BBLink))
{
return HTMLHelper.HTMLEncode(ResHelper.LocalizeString(data.GetValue("ClassDisplayName").ToString()));
}
}
result = NormalizeExtenison(data.GetValue(FileExtensionColumn).ToString());
}
break;
#endregion
#region "Size"
case "size":
{
// Is current item CMS.File or attachment ?
isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
notAttachment = isContent && !(isContentFile && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty));
if (!notAttachment)
{
long size = 0;
if (data.GetValue(FileExtensionColumn).ToString() != "")
{
if (data.ContainsColumn(FileSizeColumn))
{
size = ValidationHelper.GetLong(data.GetValue(FileSizeColumn), 0);
}
else if (data.ContainsColumn("Size"))
{
IDataContainer importedData = RaiseOnFileIsNotInDatabase(GetFileName(data));
size = ValidationHelper.GetLong((importedData != null) ? importedData["FileSize"] : data.GetValue("Size"), 0);
}
}
else
{
return "";
}
result = DataHelper.GetSizeString(size);
}
}
break;
#endregion
#region "Attachment modified"
case "attachmentmodified":
case "attachmentmodifiedtooltip":
{
// If attachment is related to the workflow 'AttachmentLastModified' information isn't present
if (!data.ContainsColumn("AttachmentLastModified"))
{
int attachmentDocumentId = ValidationHelper.GetInteger(data.GetValue("AttachmentDocumentID"), 0);
result = GetLastModified(attachmentDocumentId);
}
else
{
result = data.GetValue("AttachmentLastModified").ToString();
}
bool displayGMT = (sourceName == "attachmentmodifiedtooltip");
result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo);
}
break;
#endregion
#region "Attachment update"
case "attachmentupdate":
{
// Dynamically load uploader control
dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader;
Panel updatePanel = new Panel()
{
ID = "updatePanel",
Width = ((isWebDAVEnabled && isWindowsAuthentication) ? 32 : 16)
};
updatePanel.Style.Add("margin", "0 auto");
// Initialize update control
GetAttachmentUpdateControl(ref dfuElem, data);
dfuElem.DisplayInline = true;
updatePanel.Controls.Add(dfuElem);
// Add Attachment WebDAV edit control
string attachmentExtension = ValidationHelper.GetString(data.GetValue(FileExtensionColumn), null);
Guid formGUID = ValidationHelper.GetGuid(data.GetValue("AttachmentFormGUID"), Guid.Empty);
// If the WebDAV is enabled and windows authentication and extension is allowed and form GUID is empty
if (isWebDAVEnabled && isWindowsAuthentication && (formGUID == Guid.Empty) && WebDAVSettings.IsExtensionAllowedForEditMode(attachmentExtension, CMSContext.CurrentSiteName))
{
// Dynamically load control
WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl;
GetWebDAVEditControl(ref webDAVElem, data);
updatePanel.Controls.Add(webDAVElem);
}
result = updatePanel;
}
break;
#endregion
#region "Library update"
case "libraryupdate":
{
Panel updatePanel = new Panel();
updatePanel.Style.Add("margin", "0 auto");
updatePanel.Width = ((isWebDAVEnabled && isWindowsAuthentication) ? 32 : 16);
libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode &&
(data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
// Get info on imported file
fileName = GetFileName(data);
IDataContainer existingData = RaiseOnFileIsNotInDatabase(fileName);
bool hasModifyPermission = RaiseOnGetModifyPermission(data);
ImageButton imgBtn = new ImageButton()
{
Enabled = false,
ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/uploaddisabled.png"))
};
imgBtn.Attributes["style"] = "cursor: default;";
updatePanel.Controls.Add(imgBtn);
if (hasModifyPermission && (existingData != null))
{
// Dynamically load uploader control
dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader;
if (dfuElem != null)
{
// Initialize update control
GetLibraryUpdateControl(ref dfuElem, existingData);
updatePanel.Controls.Add(dfuElem);
}
imgBtn.Style.Add("display", "none");
}
else
{
updatePanel.Visible = !libraryFolder || !hasModifyPermission;
}
// Add WebDAV icon
if (existingData != null)
{
string siteName = GetSiteName(existingData, true);
string extension = ValidationHelper.GetString(existingData["FileExtension"], null);
// If the WebDAV is enabled and windows authentication and extension is allowed
if (isWebDAVEnabled && isWindowsAuthentication && WebDAVSettings.IsExtensionAllowedForEditMode(extension, siteName))
{
// Dynamically load control
WebDAVEditControl webdavElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl;
// Set editor's properties
if (webdavElem != null)
{
// Initialize update control
GetWebDAVEditControl(ref webdavElem, existingData);
updatePanel.Controls.Add(webdavElem);
}
}
}
result = updatePanel;
}
break;
#endregion
#region "Attachment/MetaFile delete"
case "metafiledelete":
case "attachmentdelete":
if (sender is ImageButton)
{
// Initialize DELETE button
btn = ((ImageButton)sender);
btn.OnClientClick = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('{1}', '{0}'); RaiseHiddenPostBack(); return false;", data.GetValue(FileIdColumn), sourceName.ToLowerCSafe());
}
break;
#endregion
#region "Attachment moveup"
case "attachmentmoveup":
if (sender is ImageButton)
{
// Initialize MOVE UP button
btn = ((ImageButton)sender);
// Get attachment ID
Guid attachmentGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
btn.OnClientClick = String.Format("SetAction('attachmentmoveup', '{0}'); RaiseHiddenPostBack(); return false;", attachmentGuid);
}
break;
#endregion
#region "Attachment movedown"
case "attachmentmovedown":
if (sender is ImageButton)
{
// Initialize MOVE DOWN button
btn = ((ImageButton)sender);
// Get attachment ID
Guid attachmentGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
btn.OnClientClick = String.Format("SetAction('attachmentmovedown', '{0}'); RaiseHiddenPostBack(); return false;", attachmentGuid);
}
break;
#endregion
#region "Attachment edit"
case "attachmentedit":
if (sender is ImageButton)
{
// Get file extension
string attExtension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), "").ToLowerCSafe();
Guid attGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
ImageButton attImg = (ImageButton)sender;
attImg.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", attExtension, attGuid, GetSiteName(data, false), VersionHistoryID);
attImg.PreRender += img_PreRender;
}
break;
#endregion
#region "Library extension"
case "extension":
{
result = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString();
result = NormalizeExtenison(result.ToString());
}
break;
#endregion
#region "Modified"
case "modified":
case "modifiedtooltip":
{
bool displayGMT = (sourceName == "attachmentmodifiedtooltip");
result = data.ContainsColumn("FileModifiedWhen") ? data.GetValue("FileModifiedWhen").ToString() : data.GetValue("Modified").ToString();
result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo);
}
break;
#endregion
#region "Document modified when"
case "documentmodifiedwhen":
case "filemodifiedwhen":
case "documentmodifiedwhentooltip":
case "filemodifiedwhentooltip":
{
bool displayGMT = ((sourceName == "documentmodifiedwhentooltip") || (sourceName == "filemodifiedwhentooltip"));
result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(parameter, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo);
}
break;
#endregion
#region "MetaFile edit"
case "metafileedit":
if (sender is ImageButton)
{
// Get file extension
string metaExtension = ValidationHelper.GetString(data.GetValue("MetaFileExtension"), string.Empty).ToLowerCSafe();
Guid metaGuid = ValidationHelper.GetGuid(data.GetValue("MetaFileGUID"), Guid.Empty);
ImageButton attImg = (ImageButton)sender;
attImg.AlternateText = String.Format("{0}|metafileguid={1}", metaExtension, metaGuid);
attImg.PreRender += img_PreRender;
}
break;
#endregion
#region "MetaFile update"
case "metafileupdate":
{
// Dynamically load uploader control
dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader;
Panel updatePanel = new Panel()
{
ID = "updatePanel",
Width = 16
};
updatePanel.Style.Add("margin", "0 auto");
// Initialize update control
GetAttachmentUpdateControl(ref dfuElem, data);
dfuElem.DisplayInline = true;
updatePanel.Controls.Add(dfuElem);
result = updatePanel;
}
break;
#endregion
#region "MetaFile modified"
case "metafilemodified":
case "metafilemodifiedtooltip":
{
result = data.GetValue("MetaFileLastModified").ToString();
bool displayGMT = (sourceName == "metafilemodifiedtooltip");
result = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(result, DataHelper.DATETIME_NOT_SELECTED), displayGMT, CMSContext.CurrentUser, siteInfo);
}
break;
#endregion
}
return result;
}
protected void img_PreRender(object sender, EventArgs e)
{
ImageButton img = (ImageButton)sender;
string[] args = img.AlternateText.Split('|');
if (args.Length == 2)
{
string refreshType = CMSDialogHelper.GetMediaSource(SourceType);
int parentId = QueryHelper.GetInteger("parentId", 0);
Guid formGuid = QueryHelper.GetGuid("formGuid", Guid.Empty);
string query = String.Format("?clientid={0}{1}&refresh=1&refaction=0{2}&{3}", HTMLHelper.HTMLEncode(refreshType), ((parentId > 0) ? "&parentId=" + parentId : ""), ((formGuid != Guid.Empty) ? "&formGuid=" + formGuid : ""), args[1]);
// Get validation hash for current image
query = URLHelper.AddUrlParameter(query, "hash", QueryHelper.GetHash(query));
img.Attributes["onclick"] = ImageHelper.IsSupportedByImageEditor(args[0]) ?
String.Format("if(!($j(this).hasClass('Edited'))){{ EditImage(\"{0}\"); }} return false;", query) :
String.Format("if(!($j(this).hasClass('Edited'))){{ Edit(\"{0}\"); }} return false;", query);
img.ToolTip = GetString("general.edit");
img.AlternateText = GetString("general.edit");
}
}
#endregion
#region "Tiles view methods"
///
/// Initializes controls for the tiles view mode.
///
private void InitializeTilesView()
{
// Initialize page size
bool isAttachmentTab = SourceType == MediaSourceEnum.DocumentAttachments;
pagerElemTiles.PageSizeItems = isAttachmentTab ? new string[] { "20", "40", "100" } : new string[] { "16", "32", "100" };
pagerElemTiles.Pager.PageSize = pagerElemTiles.GetPageSize(isAttachmentTab ? 20 : 16);
// Basic control properties
repTilesView.HideControlForZeroRows = true;
// UniPager properties
SetupPager(pagerElemTiles.Pager);
}
///
/// Setups the UniPager
///
/// Pager to setup
private void SetupPager(UniPager pager)
{
pager.GroupSize = PAGER_GROUP_SIZE;
pager.DisplayFirstLastAutomatically = false;
pager.DisplayPreviousNextAutomatically = false;
pager.HidePagerForSinglePage = true;
pager.PagerMode = UniPagerMode.PostBack;
}
///
/// Loads content for media libraries tile view element.
///
private void ReloadTilesView()
{
// Connects repeater with data source
if (!DataHelper.DataSourceIsEmpty(DataSource))
{
repTilesView.DataSource = DataSource;
repTilesView.DataBind();
}
}
protected void TilesViewControl_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
#region "Load item data"
string className = "";
string fileNameColumn = FileNameColumn;
IDataContainer data = new DataRowContainer((DataRowView)e.Item.DataItem);
bool isContent = (SourceType == MediaSourceEnum.Content);
bool isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
bool notAttachment = isContent && !(isContentFile && (data.GetValue("AttachmentGUID") != DBNull.Value));
if (notAttachment)
{
className = DataClassInfoProvider.GetDataClass((int)data.GetValue("NodeClassID")).ClassDisplayName;
fileNameColumn = "DocumentName";
}
else
{
fileNameColumn = "AttachmentName";
}
// Get basic information on file (use field properties for CMS.File | attachment, document columns otherwise)
string fileName = HTMLHelper.HTMLEncode((data.ContainsColumn(fileNameColumn) ? data.GetValue(fileNameColumn).ToString() : data.GetValue(FileNameColumn).ToString()));
string ext = notAttachment ? className : data.GetValue(FileExtensionColumn).ToString().TrimStart('.');
string argument = RaiseOnGetArgumentSet(data);
// Get full media library file name
bool isInDatabase = true;
string fullFileName = GetFileName(data);
IDataContainer importedMediaData = null;
if ((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Simple))
{
importedMediaData = RaiseOnFileIsNotInDatabase(fullFileName);
isInDatabase = (importedMediaData != null);
}
string selectUrl = RaiseOnGetTilesThumbsItemUrl(data, false, 0, 0, 0, notAttachment);
bool isSelectable = CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile);
bool libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
bool libraryUiFolder = libraryFolder && !((DisplayMode == ControlDisplayModeEnum.Simple) && isInDatabase);
int width = 0;
int height = 0;
// Width
if (data.ContainsColumn(FileWidthColumn))
{
width = ValidationHelper.GetInteger(data.GetValue(FileWidthColumn), 0);
}
else if (isInDatabase && (DisplayMode == ControlDisplayModeEnum.Simple) && importedMediaData.ContainsColumn(FileWidthColumn))
{
width = ValidationHelper.GetInteger(importedMediaData.GetValue(FileWidthColumn), 0);
}
// Height
if (data.ContainsColumn(FileHeightColumn))
{
height = ValidationHelper.GetInteger(data.GetValue(FileHeightColumn), 0);
}
else if (isInDatabase && (DisplayMode == ControlDisplayModeEnum.Simple) && importedMediaData.ContainsColumn(FileHeightColumn))
{
height = ValidationHelper.GetInteger(importedMediaData.GetValue(FileHeightColumn), 0);
}
// Get item image URL from the parent set
string previewUrl = "";
if ((SourceType == MediaSourceEnum.MediaLibraries) && isInDatabase && (DisplayMode == ControlDisplayModeEnum.Simple))
{
previewUrl = RaiseOnGetTilesThumbsItemUrl(importedMediaData, true, 0, 0, 48, notAttachment);
}
else
{
previewUrl = RaiseOnGetTilesThumbsItemUrl(data, true, 0, 0, 48, notAttachment);
}
#endregion
#region "Standard controls and actions"
bool hideDocName = false;
Label lblDocumentName = null;
if (isContent && !notAttachment)
{
string docName = Path.GetFileNameWithoutExtension(data.GetValue(FileNameColumn).ToString());
fileName = Path.GetFileNameWithoutExtension(fileName);
hideDocName = (docName.ToLowerCSafe() == fileName.ToLowerCSafe());
if (!hideDocName)
{
fileName += "." + ext;
lblDocumentName = e.Item.FindControl("lblDocumentName") as Label;
if (lblDocumentName != null)
{
lblDocumentName.Attributes["class"] = "DialogTileTitleBold";
lblDocumentName.Text = HTMLHelper.HTMLEncode(docName);
}
}
else
{
fileName = docName;
}
}
// Do not display document name if the same as the file name
if (hideDocName || (lblDocumentName == null) || string.IsNullOrEmpty(lblDocumentName.Text))
{
PlaceHolder plcDocumentName = e.Item.FindControl("plcDocumentName") as PlaceHolder;
if (plcDocumentName != null)
{
plcDocumentName.Visible = false;
}
}
// Load file name
Label lblFileName = e.Item.FindControl("lblFileName") as Label;
if (lblFileName != null)
{
if (SourceType == MediaSourceEnum.DocumentAttachments)
{
fileName = Path.GetFileNameWithoutExtension(fileName);
}
lblFileName.Text = fileName;
}
// Load file type
Label lblType = e.Item.FindControl("lblTypeValue") as Label;
if (lblType != null)
{
lblType.Text = notAttachment ? ResHelper.LocalizeString(ext) : NormalizeExtenison(ext);
}
if (!notAttachment && !libraryFolder)
{
// Load file size
Label lblSize = e.Item.FindControl("lblSizeValue") as Label;
if (lblSize != null)
{
long size = 0;
if (data.ContainsColumn(FileSizeColumn))
{
size = ValidationHelper.GetLong(data.GetValue(FileSizeColumn), 0);
}
// Library files
else if (data.ContainsColumn("Size"))
{
size = ValidationHelper.GetLong((importedMediaData != null) ? importedMediaData["FileSize"] : data.GetValue("Size"), 0);
}
lblSize.Text = DataHelper.GetSizeString(size);
}
}
// Initialize SELECT button
ImageButton btnSelect = e.Item.FindControl("btnSelect") as ImageButton;
if (btnSelect != null)
{
// Check if item is selectable, if not remove select action button
if (!isSelectable)
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "transparent.png");
btnSelect.ToolTip = "";
btnSelect.Attributes.Remove("onclick");
btnSelect.Attributes["style"] = "cursor:default;";
btnSelect.Enabled = false;
}
else
{
// If media file not imported yet - display warning sign
if ((SourceType == MediaSourceEnum.MediaLibraries) && ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase && !libraryFolder))
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "warning.png");
btnSelect.ToolTip = GetString("media.file.import");
btnSelect.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile',{1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName));
}
else
{
// Initialize command
if (libraryFolder)
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png");
btnSelect.ToolTip = GetString("dialogs.list.actions.showsubfolders");
btnSelect.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "next.png");
btnSelect.ToolTip = GetString("dialogs.list.actions.select");
btnSelect.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, selectUrl)));
}
}
}
}
// Initialize SELECTSUBDOCS button
ImageButton btnSelectSubDocs = e.Item.FindControl("btnSelectSubDocs") as ImageButton;
if (btnSelectSubDocs != null)
{
btnSelectSubDocs.ToolTip = GetString("dialogs.list.actions.showsubdocuments");
if (IsFullListingMode && (SourceType == MediaSourceEnum.Content))
{
int nodeId = ValidationHelper.GetInteger(data.GetValue("NodeID"), 0);
// Check if item is selectable, if not remove select action button
// Initialize command
btnSelectSubDocs.Attributes["onclick"] = String.Format("SetParentAction('{0}'); return false;", nodeId);
btnSelectSubDocs.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png");
}
else
{
PlaceHolder plcSelectSubDocs = e.Item.FindControl("plcSelectSubDocs") as PlaceHolder;
if (plcSelectSubDocs != null)
{
plcSelectSubDocs.Visible = false;
}
}
}
// Initialize VIEW button
// Get media file URL according system settings
argument = RaiseOnGetArgumentSet(data);
ImageButton btnView = e.Item.FindControl("btnView") as ImageButton;
if (btnView != null)
{
if (!notAttachment && !libraryFolder && !libraryUiFolder)
{
if (String.IsNullOrEmpty(selectUrl))
{
btnView.ImageUrl = ResolveUrl(ImagesPath + "viewdisabled.png");
btnView.OnClientClick = "return false;";
btnView.Attributes["style"] = "cursor:default;";
btnView.Enabled = false;
}
else
{
btnView.ImageUrl = ResolveUrl(ImagesPath + "view.png");
btnView.ToolTip = GetString("dialogs.list.actions.view");
btnView.OnClientClick = String.Format("javascript: window.open({0}); return false;", ScriptHelper.GetString(URLHelper.ResolveUrl(selectUrl)));
}
}
else
{
btnView.Visible = false;
}
}
// Initialize EDIT button
ImageButton btnContentEdit = e.Item.FindControl("btnContentEdit") as ImageButton;
if (btnContentEdit != null)
{
Guid guid = Guid.Empty;
btnContentEdit.ToolTip = GetString("general.edit");
btnContentEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png");
if ((SourceType == MediaSourceEnum.MediaLibraries) && !libraryFolder && !libraryUiFolder)
{
// Media files coming from FS
if (!data.ContainsColumn("FileGUID"))
{
// Get file name
fileName = fullFileName;
ext = data.ContainsColumn("FileExtension") ? data.GetValue("FileExtension").ToString() : data.GetValue("Extension").ToString();
if (!((DisplayMode == ControlDisplayModeEnum.Simple) && isInDatabase))
{
btnContentEdit.ImageUrl = ResolveUrl(ImagesPath + "editdisabled.png");
btnContentEdit.Attributes["style"] = "cursor: default;";
btnContentEdit.Enabled = false;
}
else
{
btnContentEdit.OnClientClick = String.Format("$j('#hdnFileOrigName').attr('value', {0}); SetAction('editlibraryui', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(EnsureFileName(fileName)), ScriptHelper.GetString(fileName));
}
}
else
{
guid = ValidationHelper.GetGuid(data.GetValue("FileGUID"), Guid.Empty);
btnContentEdit.AlternateText = String.Format("{0}|MediaFileGUID={1}&sitename={2}", ext, guid, GetSiteName(data, true));
btnContentEdit.PreRender += img_PreRender;
}
}
else if (SourceType == MediaSourceEnum.MetaFile)
{
// If MetaFiles being displayed set EDIT action
string metaExtension = ValidationHelper.GetString(data.GetValue("MetaFileExtension"), string.Empty).ToLowerCSafe();
Guid metaGuid = ValidationHelper.GetGuid(data.GetValue("MetaFileGUID"), Guid.Empty);
btnContentEdit.AlternateText = String.Format("{0}|metafileguid={1}", metaExtension, metaGuid);
btnContentEdit.PreRender += img_PreRender;
}
else if (!notAttachment && (SourceType != MediaSourceEnum.DocumentAttachments) && !libraryFolder && !libraryUiFolder)
{
string nodeid = "";
if (SourceType == MediaSourceEnum.Content)
{
nodeid = "&nodeId=" + data.GetValue("NodeID");
// Get the node workflow
VersionHistoryID = ValidationHelper.GetInteger(data.GetValue("DocumentCheckedOutVersionHistoryID"), 0);
}
guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
btnContentEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}{3}{4}", ext, guid, GetSiteName(data, false), nodeid, ((VersionHistoryID > 0) ? "&versionHistoryId=" + VersionHistoryID : ""));
btnContentEdit.PreRender += img_PreRender;
}
else
{
btnContentEdit.Visible = false;
}
}
#endregion
#region "Special actions"
// If attachments being displayed show additional actions
if (SourceType == MediaSourceEnum.DocumentAttachments)
{
// Initialize UPDATE button
DirectFileUploader dfuElem = e.Item.FindControl("dfuElem") as DirectFileUploader;
if (dfuElem != null)
{
GetAttachmentUpdateControl(ref dfuElem, data);
}
string attExtension = data.GetValue("AttachmentExtension").ToString();
// If the WebDAV is enabled and windows authentication and extension is allowed
if (CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(attExtension, CMSContext.CurrentSiteName))
{
PlaceHolder plcWebDAV = e.Item.FindControl("plcWebDAV") as PlaceHolder;
if (plcWebDAV != null)
{
// Dynamically load control
WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl;
if (webDAVElem != null)
{
plcWebDAV.Controls.Clear();
plcWebDAV.Controls.Add(webDAVElem);
webDAVElem.Visible = false;
// Set WebDAV edit control
GetWebDAVEditControl(ref webDAVElem, data);
webDAVElem.CssClass = null;
plcWebDAV.Visible = true;
}
}
}
// Initialize EDIT button
ImageButton btnEdit = e.Item.FindControl("btnEdit") as ImageButton;
if (btnEdit != null)
{
if (!notAttachment)
{
btnEdit.ToolTip = GetString("general.edit");
// Get file extension
string extension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), "").ToLowerCSafe();
Guid guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
btnEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png");
btnEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", extension, guid, GetSiteName(data, false), VersionHistoryID);
btnEdit.PreRender += img_PreRender;
}
}
// Initialize DELETE button
ImageButton btnDelete = e.Item.FindControl("btnDelete") as ImageButton;
if (btnDelete != null)
{
btnDelete.ImageUrl = ResolveUrl(ImagesPath + "delete.png");
btnDelete.ToolTip = GetString("general.delete");
// Initialize command
btnDelete.Attributes["onclick"] = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('attachmentdelete','{0}'); RaiseHiddenPostBack(); return false;", data.GetValue("AttachmentGUID"));
}
PlaceHolder plcContentEdit = e.Item.FindControl("plcContentEdit") as PlaceHolder;
if (plcContentEdit != null)
{
plcContentEdit.Visible = false;
}
}
else if ((SourceType == MediaSourceEnum.MediaLibraries) && !data.ContainsColumn("FileGUID") && !((DisplayMode == ControlDisplayModeEnum.Simple) && (libraryFolder || libraryUiFolder)))
{
// Initialize DELETE button
ImageButton btnDelete = e.Item.FindControl("btnDelete") as ImageButton;
if (btnDelete != null)
{
btnDelete.ImageUrl = ResolveUrl(ImagesPath + "Delete.png");
btnDelete.ToolTip = GetString("general.delete");
btnDelete.Attributes["onclick"] = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fullFileName));
}
// Hide attachment specific actions
PlaceHolder plcAttachmentUpdtAction = e.Item.FindControl("plcAttachmentUpdtAction") as PlaceHolder;
if (plcAttachmentUpdtAction != null)
{
plcAttachmentUpdtAction.Visible = false;
}
}
else
{
PlaceHolder plcAttachmentActions = e.Item.FindControl("plcAttachmentActions") as PlaceHolder;
if (plcAttachmentActions != null)
{
plcAttachmentActions.Visible = false;
}
}
#endregion
#region "Library action"
if ((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Simple))
{
// Initialize UPDATE button
DirectFileUploader dfuElemLib = e.Item.FindControl("dfuElemLib") as DirectFileUploader;
if (dfuElemLib != null)
{
Panel pnlDisabledUpdate = (e.Item.FindControl("pnlDisabledUpdate") as Panel);
if (pnlDisabledUpdate != null)
{
bool hasModifyPermission = RaiseOnGetModifyPermission(data);
if (isInDatabase && hasModifyPermission)
{
GetLibraryUpdateControl(ref dfuElemLib, importedMediaData);
pnlDisabledUpdate.Visible = false;
}
else
{
pnlDisabledUpdate.Controls.Clear();
ImageButton imgBtn = new ImageButton()
{
Enabled = false,
ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/uploaddisabled.png"))
};
imgBtn.Attributes["style"] = "cursor: default;";
pnlDisabledUpdate.Controls.Add(imgBtn);
dfuElemLib.Visible = false;
}
}
}
string siteName = GetSiteName(data, true);
// If the WebDAV is enabled and windows authentication and extension is allowed and media file is in database
if (CMSContext.IsWebDAVEnabled(siteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(ext, siteName) && isInDatabase)
{
PlaceHolder plcWebDAVMfi = e.Item.FindControl("plcWebDAVMfi") as PlaceHolder;
if (plcWebDAVMfi != null)
{
// Dynamically load control
WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl;
if (webDAVElem != null)
{
webDAVElem.Visible = false;
plcWebDAVMfi.Controls.Clear();
plcWebDAVMfi.Controls.Add(webDAVElem);
// Set WebDAV edit control
GetWebDAVEditControl(ref webDAVElem, importedMediaData);
}
}
}
}
else if ((SourceType == MediaSourceEnum.Content && (DisplayMode == ControlDisplayModeEnum.Default) && !notAttachment && !libraryFolder && !libraryUiFolder))
{
// Initialize WebDAV edit button
if (data.ContainsColumn("AttachmentGUID"))
{
VisibleWebDAVEditControl(e.Item, WebDAVControlTypeEnum.Attachment);
}
}
else if ((SourceType == MediaSourceEnum.MediaLibraries && (DisplayMode == ControlDisplayModeEnum.Default) && !libraryFolder && !libraryUiFolder))
{
// Initialize WebDAV edit button
if (data.ContainsColumn("FileGUID"))
{
VisibleWebDAVEditControl(e.Item, WebDAVControlTypeEnum.Media);
}
}
else
{
PlaceHolder plcLibraryUpdtAction = e.Item.FindControl("plcLibraryUpdtAction") as PlaceHolder;
if (plcLibraryUpdtAction != null)
{
plcLibraryUpdtAction.Visible = false;
}
}
if ((SourceType == MediaSourceEnum.MediaLibraries) && libraryFolder && IsFullListingMode)
{
// Initialize SELECT SUB-FOLDERS button
ImageButton btn = e.Item.FindControl("imgSelectSubFolders") as ImageButton;
if (btn != null)
{
btn.Visible = true;
btn.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png");
btn.ToolTip = GetString("dialogs.list.actions.showsubfolders");
btn.Attributes["onclick"] = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(fileName));
}
}
else
{
PlaceHolder plcSelectSubFolders = e.Item.FindControl("plcSelectSubFolders") as PlaceHolder;
if (plcSelectSubFolders != null)
{
plcSelectSubFolders.Visible = false;
}
}
#endregion
#region "Load file image"
// Selectable area
Panel pnlItemInageContainer = e.Item.FindControl("pnlTiles") as Panel;
if (pnlItemInageContainer != null)
{
if (isSelectable)
{
if ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase)
{
if (libraryFolder || libraryUiFolder)
{
pnlItemInageContainer.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else
{
pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName));
}
}
else
{
pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, selectUrl)));
}
pnlItemInageContainer.Attributes["style"] = "cursor:pointer;";
}
else
{
pnlItemInageContainer.Attributes["style"] = "cursor:default;";
}
}
// Image area
Image fileImage = e.Item.FindControl("imgElem") as Image;
if (fileImage != null)
{
string chset = Guid.NewGuid().ToString();
previewUrl = URLHelper.AddParameterToUrl(previewUrl, "chset", chset);
// Add latest version requirement for live site
int versionHistoryId = VersionHistoryID;
if (IsLiveSite && (versionHistoryId > 0))
{
// Add requirement for latest version of files for current document
string newparams = "latestforhistoryid=" + versionHistoryId;
newparams += "&hash=" + ValidationHelper.GetHashString("h" + versionHistoryId);
previewUrl += "&" + newparams;
}
fileImage.ImageUrl = ResolveUrl(previewUrl);
// Ensure tooltip
if (isInDatabase)
{
UIHelper.EnsureTooltip(fileImage, previewUrl, width, height, GetTitle(data, isContentFile), fileName, ext, GetDescription(data, isContentFile), null, 300);
}
}
#endregion
// Display only for ML UI
if ((DisplayMode == ControlDisplayModeEnum.Simple) && !libraryFolder)
{
PlaceHolder plcSelectionBox = e.Item.FindControl("plcSelectionBox") as PlaceHolder;
if (plcSelectionBox != null)
{
plcSelectionBox.Visible = true;
// Multiple selection check-box
LocalizedCheckBox chkSelected = e.Item.FindControl("chkSelected") as LocalizedCheckBox;
if (chkSelected != null)
{
chkSelected.ToolTip = GetString("general.select");
chkSelected.InputAttributes["alt"] = fullFileName;
HiddenField hdnItemName = e.Item.FindControl("hdnItemName") as HiddenField;
if (hdnItemName != null)
{
hdnItemName.Value = fullFileName;
}
}
}
}
}
///
/// Sets visibility of WebDAV edit control.
///
/// Repeater item
/// Control type
private void VisibleWebDAVEditControl(RepeaterItem repeaterItem, WebDAVControlTypeEnum controlType)
{
PlaceHolder plcAttachmentActions = repeaterItem.FindControl("plcAttachmentActions") as PlaceHolder;
PlaceHolder plcAttachmentUpdtAction = repeaterItem.FindControl("plcAttachmentUpdtAction") as PlaceHolder;
PlaceHolder plcLibraryUpdtAction = repeaterItem.FindControl("plcLibraryUpdtAction") as PlaceHolder;
PlaceHolder plcWebDAV = repeaterItem.FindControl("plcWebDAV") as PlaceHolder;
PlaceHolder plcWebDAVMfi = repeaterItem.FindControl("plcWebDAVMfi") as PlaceHolder;
Panel pnlDisabledUpdate = (repeaterItem.FindControl("pnlDisabledUpdate") as Panel);
DirectFileUploader dfuLib = repeaterItem.FindControl("dfuElemLib") as DirectFileUploader;
DirectFileUploader dfu = repeaterItem.FindControl("dfuElem") as DirectFileUploader;
ImageButton btnEdit = repeaterItem.FindControl("btnEdit") as ImageButton;
ImageButton btnDelete = repeaterItem.FindControl("btnDelete") as ImageButton;
if ((plcAttachmentActions != null) && (plcLibraryUpdtAction != null) && (plcAttachmentUpdtAction != null) && (plcWebDAV != null)
&& (plcWebDAVMfi != null) && (pnlDisabledUpdate != null) && (dfuLib != null) && (dfu != null) && (btnEdit != null) && (btnDelete != null))
{
WebDAVEditControl webDAVElem = null;
if (controlType == WebDAVControlTypeEnum.Media)
{
plcAttachmentActions.Visible = true;
plcAttachmentUpdtAction.Visible = false;
plcLibraryUpdtAction.Visible = true;
pnlDisabledUpdate.Visible = false;
dfuLib.Visible = false;
dfu.Visible = false;
btnEdit.Visible = false;
btnDelete.Visible = false;
plcWebDAV.Visible = false;
webDAVElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl;
if (webDAVElem != null)
{
plcWebDAVMfi.Controls.Clear();
plcWebDAVMfi.Controls.Add(webDAVElem);
}
}
else if (controlType == WebDAVControlTypeEnum.Attachment)
{
plcAttachmentActions.Visible = true;
plcAttachmentUpdtAction.Visible = false;
plcLibraryUpdtAction.Visible = false;
pnlDisabledUpdate.Visible = false;
dfuLib.Visible = false;
dfu.Visible = false;
btnEdit.Visible = false;
btnDelete.Visible = false;
plcWebDAV.Visible = true;
// Dynamically load control
webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl;
if (webDAVElem != null)
{
plcWebDAV.Controls.Clear();
plcWebDAV.Controls.Add(webDAVElem);
}
}
if (webDAVElem != null)
{
webDAVElem.Visible = false;
webDAVElem.CssClass = null;
IDataContainer data = new DataRowContainer((DataRowView)repeaterItem.DataItem);
string extension = data.GetValue(FileExtensionColumn).ToString();
// If the WebDAV is enabled and windows authentication and extension is allowed
if (CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(extension, CMSContext.CurrentSiteName))
{
// Set WebDAV edit control
GetWebDAVEditControl(ref webDAVElem, data);
}
}
}
}
#endregion
#region "Thumbnails view methods"
///
/// Initializes controls for the thumbnails view mode.
///
private void InitializeThumbnailsView()
{
bool isAttachmentTab = SourceType == MediaSourceEnum.DocumentAttachments;
// Initialize page size
pagerElemThumbnails.PageSizeItems = (isAttachmentTab ? new string[] { "12", "24", "48", "96" } : new string[] { "10", "20", "50", "100" });
pagerElemThumbnails.Pager.PageSize = pagerElemThumbnails.GetPageSize(isAttachmentTab ? 12 : 10);
// Basic control properties
repThumbnailsView.HideControlForZeroRows = true;
// UniPager properties
SetupPager(pagerElemThumbnails.Pager);
}
///
/// Loads content for media libraries thumbnails view element.
///
private void ReloadThumbnailsView()
{
// Connects repeater with data source
if (!DataHelper.DataSourceIsEmpty(DataSource))
{
repThumbnailsView.DataSource = DataSource;
repThumbnailsView.DataBind();
}
}
protected void ThumbnailsViewControl_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
#region "Load the item data"
IDataContainer data = new DataRowContainer((DataRowView)e.Item.DataItem);
string fileNameColumn = FileNameColumn;
string className = "";
bool isContent = (SourceType == MediaSourceEnum.Content);
bool isContentFile = isContent ? (data.GetValue("ClassName").ToString().ToLowerCSafe() == "cms.file") : false;
bool notAttachment = isContent && !(isContentFile && (data.GetValue("AttachmentGUID") != DBNull.Value));
if (notAttachment)
{
className = DataClassInfoProvider.GetDataClass((int)data.GetValue("NodeClassID")).ClassDisplayName;
fileNameColumn = "DocumentName";
}
// Get information on file
string fileName = HTMLHelper.HTMLEncode(data.GetValue(fileNameColumn).ToString());
string ext = HTMLHelper.HTMLEncode(notAttachment ? className : data.GetValue(FileExtensionColumn).ToString().TrimStart('.'));
string argument = RaiseOnGetArgumentSet(data);
// Get full media library file name
bool isInDatabase = true;
string fullFileName = GetFileName(data);
IDataContainer importedMediaData = null;
if (SourceType == MediaSourceEnum.MediaLibraries)
{
importedMediaData = RaiseOnFileIsNotInDatabase(fullFileName);
isInDatabase = (importedMediaData != null);
}
bool libraryFolder = ((SourceType == MediaSourceEnum.MediaLibraries) && IsFullListingMode && (data.GetValue(FileExtensionColumn).ToString().ToLowerCSafe() == ""));
bool libraryUiFolder = libraryFolder && !((DisplayMode == ControlDisplayModeEnum.Simple) && isInDatabase);
int width = 0;
int height = 0;
// Get thumb preview image dimensions
int[] thumbImgDimension = new int[] { 0, 0 };
if (ImageHelper.IsSupportedByImageEditor(ext))
{
// Width & height
if (data.ContainsColumn(FileWidthColumn))
{
width = ValidationHelper.GetInteger(data.GetValue(FileWidthColumn), 0);
}
else if (isInDatabase && importedMediaData.ContainsColumn(FileWidthColumn))
{
width = ValidationHelper.GetInteger(importedMediaData.GetValue(FileWidthColumn), 0);
}
if (data.ContainsColumn(FileHeightColumn))
{
height = ValidationHelper.GetInteger(data.GetValue(FileHeightColumn), 0);
}
else if (isInDatabase && importedMediaData.ContainsColumn(FileHeightColumn))
{
height = ValidationHelper.GetInteger(importedMediaData.GetValue(FileHeightColumn), 0);
}
thumbImgDimension = CMSDialogHelper.GetThumbImageDimensions(height, width, MaxThumbImgHeight, MaxThumbImgWidth);
}
// Preview URL
string previewUrl = "";
if ((SourceType == MediaSourceEnum.MediaLibraries) && isInDatabase)
{
previewUrl = RaiseOnGetTilesThumbsItemUrl(importedMediaData, true, thumbImgDimension[0], thumbImgDimension[1], 0, notAttachment);
}
else
{
previewUrl = RaiseOnGetTilesThumbsItemUrl(data, true, thumbImgDimension[0], thumbImgDimension[1], 0, notAttachment);
}
// Item URL
string selectUrl = RaiseOnGetTilesThumbsItemUrl(data, false, 0, 0, 0, notAttachment);
bool isSelectable = CMSDialogHelper.IsItemSelectable(SelectableContent, ext, isContentFile);
#endregion
#region "Standard controls and actions"
// Load file name
Label lblName = e.Item.FindControl("lblFileName") as Label;
if (lblName != null)
{
lblName.Text = fileName;
}
// Initialize SELECT button
ImageButton btnSelect = e.Item.FindControl("btnSelect") as ImageButton;
if (btnSelect != null)
{
// Check if item is selectable, if not remove select action button
if (!isSelectable)
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "transparent.png");
btnSelect.ToolTip = "";
btnSelect.Attributes.Remove("onclick");
btnSelect.Attributes["style"] = "cursor: default;";
btnSelect.Enabled = false;
}
else
{
// If media file not imported yet - display warning sign
if ((SourceType == MediaSourceEnum.MediaLibraries) && ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase && !libraryFolder && !libraryUiFolder))
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "warning.png");
btnSelect.ToolTip = GetString("media.file.import");
btnSelect.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile',{1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName));
}
else
{
if (libraryFolder || libraryUiFolder)
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png");
btnSelect.ToolTip = GetString("dialogs.list.actions.showsubfolders");
btnSelect.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else
{
btnSelect.ImageUrl = ResolveUrl(ImagesPath + "next.png");
btnSelect.ToolTip = GetString("dialogs.list.actions.select");
btnSelect.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(argument + "|URL|" + selectUrl));
}
}
}
}
// Initialize SELECTSUBDOCS button
ImageButton btnSelectSubDocs = e.Item.FindControl("btnSelectSubDocs") as ImageButton;
if (btnSelectSubDocs != null)
{
if (IsFullListingMode && (SourceType == MediaSourceEnum.Content))
{
int nodeId = ValidationHelper.GetInteger(data.GetValue("NodeID"), 0);
btnSelectSubDocs.ToolTip = GetString("dialogs.list.actions.showsubdocuments");
// Check if item is selectable, if not remove select action button
// Initialize command
btnSelectSubDocs.Attributes["onclick"] = String.Format("SetParentAction('{0}'); return false;", nodeId);
btnSelectSubDocs.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png");
}
else
{
PlaceHolder plcSelectSubDocs = e.Item.FindControl("plcSelectSubDocs") as PlaceHolder;
if (plcSelectSubDocs != null)
{
plcSelectSubDocs.Visible = false;
}
}
}
// Initialize VIEW button
ImageButton btnView = e.Item.FindControl("btnView") as ImageButton;
if (btnView != null)
{
if (!notAttachment && !libraryFolder)
{
if (String.IsNullOrEmpty(selectUrl))
{
btnView.ImageUrl = ResolveUrl(ImagesPath + "viewdisabled.png");
btnView.OnClientClick = "return false;";
btnView.Attributes["style"] = "cursor:default;";
btnView.Enabled = false;
}
else
{
btnView.ImageUrl = ResolveUrl(ImagesPath + "view.png");
btnView.ToolTip = GetString("dialogs.list.actions.view");
btnView.OnClientClick = String.Format("javascript: window.open({0}); return false;", ScriptHelper.GetString(URLHelper.ResolveUrl(selectUrl)));
}
}
else
{
btnView.Visible = false;
}
}
// Initialize EDIT button
ImageButton btnContentEdit = e.Item.FindControl("btnContentEdit") as ImageButton;
if (btnContentEdit != null)
{
btnContentEdit.ToolTip = GetString("general.edit");
btnContentEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png");
Guid guid = Guid.Empty;
if (SourceType == MediaSourceEnum.MediaLibraries && !libraryFolder && !libraryUiFolder)
{
// Media files coming from FS
if (!data.ContainsColumn("FileGUID"))
{
if ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase)
{
btnContentEdit.ImageUrl = ResolveUrl(ImagesPath + "editdisabled.png");
btnContentEdit.Attributes["style"] = "cursor: default;";
btnContentEdit.Enabled = false;
}
else
{
btnContentEdit.OnClientClick = String.Format("$j('#hdnFileOrigName').attr('value', {0}); SetAction('editlibraryui', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(EnsureFileName(fileName)), ScriptHelper.GetString(fileName));
}
}
else
{
guid = ValidationHelper.GetGuid(data.GetValue("FileGUID"), Guid.Empty);
btnContentEdit.AlternateText = String.Format("{0}|MediaFileGUID={1}&sitename={2}", ext, guid, GetSiteName(data, true));
btnContentEdit.PreRender += img_PreRender;
}
}
else if (SourceType == MediaSourceEnum.MetaFile)
{
// If MetaFiles being displayed set EDIT action
string metaExtension = ValidationHelper.GetString(data.GetValue("MetaFileExtension"), string.Empty).ToLowerCSafe();
Guid metaGuid = ValidationHelper.GetGuid(data.GetValue("MetaFileGUID"), Guid.Empty);
btnContentEdit.AlternateText = String.Format("{0}|metafileguid={1}", metaExtension, metaGuid);
btnContentEdit.PreRender += img_PreRender;
}
else if (!notAttachment && !libraryFolder && !libraryUiFolder)
{
string nodeid = "";
if (SourceType == MediaSourceEnum.Content)
{
nodeid = "&nodeId=" + data.GetValue("NodeID");
// Get the node workflow
VersionHistoryID = ValidationHelper.GetInteger(data.GetValue("DocumentCheckedOutVersionHistoryID"), 0);
}
guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
btnContentEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}{3}{4}", ext, guid, GetSiteName(data, false), nodeid, ((VersionHistoryID > 0) ? "&versionHistoryId=" + VersionHistoryID : ""));
btnContentEdit.PreRender += img_PreRender;
}
else
{
btnContentEdit.Visible = false;
}
}
#endregion
#region "Special actions"
// If attachments being displayed show additional actions
if (SourceType == MediaSourceEnum.DocumentAttachments)
{
// Initialize EDIT button
ImageButton btnEdit = e.Item.FindControl("btnEdit") as ImageButton;
if (btnEdit != null)
{
if (!notAttachment)
{
btnEdit.ToolTip = GetString("general.edit");
// Get file extension
string extension = ValidationHelper.GetString(data.GetValue("AttachmentExtension"), "").ToLowerCSafe();
Guid guid = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty);
btnEdit.ImageUrl = ResolveUrl(ImagesPath + "edit.png");
btnEdit.AlternateText = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", extension, guid, GetSiteName(data, false), VersionHistoryID);
btnEdit.PreRender += img_PreRender;
}
}
// Initialize UPDATE button
DirectFileUploader dfuElem = e.Item.FindControl("dfuElem") as DirectFileUploader;
if (dfuElem != null)
{
GetAttachmentUpdateControl(ref dfuElem, data);
}
string attExtension = data.GetValue("AttachmentExtension").ToString();
// If the WebDAV is enabled and windows authentication and extension is allowed
if (CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(attExtension, CMSContext.CurrentSiteName))
{
PlaceHolder plcWebDAV = e.Item.FindControl("plcWebDAV") as PlaceHolder;
if (plcWebDAV != null)
{
// Dynamically load control
WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl;
if (webDAVElem != null)
{
plcWebDAV.Controls.Clear();
plcWebDAV.Controls.Add(webDAVElem);
webDAVElem.Visible = false;
// Set WebDAV edit control
GetWebDAVEditControl(ref webDAVElem, data);
webDAVElem.CssClass = null;
plcWebDAV.Visible = true;
}
}
}
// Initialize DELETE button
ImageButton btnDelete = e.Item.FindControl("btnDelete") as ImageButton;
if (btnDelete != null)
{
btnDelete.ImageUrl = ResolveUrl(ImagesPath + "delete.png");
btnDelete.ToolTip = GetString("general.delete");
// Initialize command
btnDelete.Attributes["onclick"] = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('attachmentdelete','{0}'); RaiseHiddenPostBack(); return false;", data.GetValue("AttachmentGUID"));
}
PlaceHolder plcContentEdit = e.Item.FindControl("plcContentEdit") as PlaceHolder;
if (plcContentEdit != null)
{
plcContentEdit.Visible = false;
}
}
else if ((SourceType == MediaSourceEnum.MediaLibraries) && !data.ContainsColumn("FileGUID") && ((DisplayMode == ControlDisplayModeEnum.Simple) && !libraryFolder && !libraryUiFolder))
{
// Initialize DELETE button
ImageButton btnDelete = e.Item.FindControl("btnDelete") as ImageButton;
if (btnDelete != null)
{
btnDelete.ImageUrl = ResolveUrl(ImagesPath + "Delete.png");
btnDelete.ToolTip = GetString("general.delete");
btnDelete.Attributes["onclick"] = String.Format("if(DeleteMediaFileConfirmation() == false){{return false;}} SetAction('deletefile',{0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fullFileName));
}
// Hide attachment specific actions
PlaceHolder plcAttachmentUpdtAction = e.Item.FindControl("plcAttachmentUpdtAction") as PlaceHolder;
if (plcAttachmentUpdtAction != null)
{
plcAttachmentUpdtAction.Visible = false;
}
}
else
{
PlaceHolder plcAttachmentActions = e.Item.FindControl("plcAttachmentActions") as PlaceHolder;
if (plcAttachmentActions != null)
{
plcAttachmentActions.Visible = false;
}
}
#endregion
#region "Library update action"
if ((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Simple))
{
// Initialize UPDATE button
DirectFileUploader dfuElemLib = e.Item.FindControl("dfuElemLib") as DirectFileUploader;
if (dfuElemLib != null)
{
Panel pnlDisabledUpdate = (e.Item.FindControl("pnlDisabledUpdate") as Panel);
if (pnlDisabledUpdate != null)
{
bool hasModifyPermission = RaiseOnGetModifyPermission(data);
if (isInDatabase && hasModifyPermission)
{
GetLibraryUpdateControl(ref dfuElemLib, importedMediaData);
pnlDisabledUpdate.Visible = false;
}
else
{
pnlDisabledUpdate.Controls.Clear();
ImageButton imgBtn = new ImageButton()
{
Enabled = false,
ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/uploaddisabled.png"))
};
imgBtn.Attributes["style"] = "cursor: default;";
pnlDisabledUpdate.Controls.Add(imgBtn);
dfuElemLib.Visible = false;
}
}
}
string siteName = GetSiteName(data, true);
// If the WebDAV is enabled and windows authentication and extension is allowed and media file is in database
if (CMSContext.IsWebDAVEnabled(siteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(ext, siteName) && isInDatabase)
{
PlaceHolder plcWebDAVMfi = e.Item.FindControl("plcWebDAVMfi") as PlaceHolder;
if (plcWebDAVMfi != null)
{
// Dynamically load control
WebDAVEditControl webDAVElem = Page.LoadUserControl("~/CMSModules/MediaLibrary/Controls/WebDAV/MediaFileWebDAVEditControl.ascx") as WebDAVEditControl;
if (webDAVElem != null)
{
webDAVElem.Visible = false;
plcWebDAVMfi.Controls.Clear();
plcWebDAVMfi.Controls.Add(webDAVElem);
// Set WebDAV edit control
GetWebDAVEditControl(ref webDAVElem, importedMediaData);
}
}
}
}
else if ((SourceType == MediaSourceEnum.Content && (DisplayMode == ControlDisplayModeEnum.Default) && !notAttachment && !libraryFolder && !libraryUiFolder))
{
// Initialize WebDAV edit button
if (data.ContainsColumn("AttachmentGUID"))
{
VisibleWebDAVEditControl(e.Item, WebDAVControlTypeEnum.Attachment);
}
}
else if ((SourceType == MediaSourceEnum.MediaLibraries && (DisplayMode == ControlDisplayModeEnum.Default) && !libraryFolder && !libraryUiFolder))
{
// Initialize WebDAV edit button
if (data.ContainsColumn("FileGUID"))
{
VisibleWebDAVEditControl(e.Item, WebDAVControlTypeEnum.Media);
}
}
else
{
PlaceHolder plcLibraryUpdtAction = e.Item.FindControl("plcLibraryUpdtAction") as PlaceHolder;
if (plcLibraryUpdtAction != null)
{
plcLibraryUpdtAction.Visible = false;
}
}
if ((SourceType == MediaSourceEnum.MediaLibraries) && libraryFolder && IsFullListingMode)
{
// Initialize SELECT SUB-FOLDERS button
ImageButton btn = e.Item.FindControl("imgSelectSubFolders") as ImageButton;
if (btn != null)
{
btn.Visible = true;
btn.ImageUrl = ResolveUrl(ImagesPath + "subdocument.png");
btn.ToolTip = GetString("dialogs.list.actions.showsubfolders");
btn.Attributes["onclick"] = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(fileName));
}
}
else
{
PlaceHolder plcSelectSubFolders = e.Item.FindControl("plcSelectSubFolders") as PlaceHolder;
if (plcSelectSubFolders != null)
{
plcSelectSubFolders.Visible = false;
}
}
#endregion
#region "File image"
// Selectable area
Panel pnlItemInageContainer = e.Item.FindControl("pnlThumbnails") as Panel;
if (pnlItemInageContainer != null)
{
if (isSelectable)
{
if ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase)
{
if (libraryFolder || libraryUiFolder)
{
pnlItemInageContainer.Attributes["onclick"] = String.Format("SetAction('morefolderselect', {0}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(fileName));
}
else
{
pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetAction('importfile', {1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName));
}
}
else
{
pnlItemInageContainer.Attributes["onclick"] = String.Format("ColorizeRow({0}); SetSelectAction({1}); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(String.Format("{0}|URL|{1}", argument, selectUrl)));
}
pnlItemInageContainer.Attributes["style"] = "cursor:pointer;";
}
else
{
pnlItemInageContainer.Attributes["style"] = "cursor:default;";
}
}
// Image area
Image imgFile = e.Item.FindControl("imgFile") as Image;
if (imgFile != null)
{
string chset = Guid.NewGuid().ToString();
previewUrl = URLHelper.AddParameterToUrl(previewUrl, "chset", chset);
// Add latest version requirement for live site
int versionHistoryId = VersionHistoryID;
if (IsLiveSite && (versionHistoryId > 0))
{
// Add requirement for latest version of files for current document
string newparams = String.Format("latestforhistoryid={0}&hash={1}", versionHistoryId, ValidationHelper.GetHashString("h" + versionHistoryId));
previewUrl += "&" + newparams;
}
imgFile.ImageUrl = previewUrl;
imgFile.AlternateText = TextHelper.LimitLength(fileName, 10);
imgFile.Attributes["title"] = fileName.Replace("\"", "\\\"");
// Ensure tooltip - only text description
if (isInDatabase)
{
UIHelper.EnsureTooltip(imgFile, previewUrl, width, height, GetTitle(data, isContentFile), fileName, ext, GetDescription(data, isContentFile), null, 300);
}
}
#endregion
// Display only for ML UI
if ((DisplayMode == ControlDisplayModeEnum.Simple) && !libraryFolder)
{
PlaceHolder plcSelectionBox = e.Item.FindControl("plcSelectionBox") as PlaceHolder;
if (plcSelectionBox != null)
{
plcSelectionBox.Visible = true;
// Multiple selection check-box
LocalizedCheckBox chkSelected = e.Item.FindControl("chkSelected") as LocalizedCheckBox;
if (chkSelected != null)
{
chkSelected.ToolTip = GetString("general.select");
chkSelected.InputAttributes["alt"] = fullFileName;
HiddenField hdnItemName = e.Item.FindControl("hdnItemName") as HiddenField;
if (hdnItemName != null)
{
hdnItemName.Value = fullFileName;
}
}
}
}
}
#endregion
#region "Raise events methods"
///
/// Fires specific action and returns result provided by the parent control.
///
/// Data related to the action
private string RaiseOnGetArgumentSet(IDataContainer data)
{
if (GetArgumentSet != null)
{
return GetArgumentSet(data);
}
return "";
}
///
/// Fires specific action and returns result provided by the parent control.
///
/// Data related to the action
/// Indicates whether the URL is required for preview item
/// Indicates whether the URL is required for non-attachment item
private string RaiseOnGetListItemUrl(IDataContainer data, bool isPreview, bool notAttachment)
{
if (GetListItemUrl != null)
{
return GetListItemUrl(data, isPreview, notAttachment);
}
return "";
}
///
/// Fires specific action and returns result provided by the parent control.
///
/// Data related to the action
/// Indicates whether the image is required as part of preview
/// Maximum width of the preview image
/// Maximum size of the preview image. If full-size required parameter gets zero value
/// Indicates whether the URL is required for non-attachment item
/// Maximum height of the preview image
private string RaiseOnGetTilesThumbsItemUrl(IDataContainer data, bool isPreview, int height, int width, int maxSideSize, bool notAttachment)
{
if (GetTilesThumbsItemUrl != null)
{
return GetTilesThumbsItemUrl(data, isPreview, height, width, maxSideSize, notAttachment);
}
return "";
}
///
/// Raises event when information on import status of specified file is required.
///
/// Name of the file (including extension)
private IDataContainer RaiseOnFileIsNotInDatabase(string fileName)
{
if (GetInformation != null)
{
object result = GetInformation("fileisnotindatabase", fileName);
if (result != null)
{
// Ensure the data container
return (result is DataRow ? new DataRowContainer((DataRow)result) : (result is DataRowView ? new DataRowContainer((DataRowView)result) : (IDataContainer)result));
}
return null;
}
return null;
}
///
/// Raises event when ID of the current site is required.
///
private int RaiseOnSiteIdRequired()
{
if (GetInformation != null)
{
return (int)GetInformation("siteidrequired", null);
}
return 0;
}
///
/// Raises event when modify permission is required.
///
/// Data container
private bool RaiseOnGetModifyPermission(IDataContainer data)
{
if (GetModifyPermission != null)
{
return GetModifyPermission(data);
}
return true;
}
#endregion
}