protected void ThumbnailsViewControl_ItemDataBound(object sender, RepeaterItemEventArgs e) { #region "Load the item data" var data = new DataRowContainer((DataRowView)e.Item.DataItem); string fileNameColumn = FileNameColumn; string className = ""; bool isContent = (SourceType == MediaSourceEnum.Content); bool isContentFile = isContent && data.GetValue("ClassName").ToString().EqualsCSafe("cms.file", true); bool notAttachment = isContent && !(isContentFile && (data.GetValue("AttachmentGUID") != DBNull.Value)); if (notAttachment) { className = DataClassInfoProvider.GetDataClassInfo((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() == "<dir>")); bool libraryUiFolder = libraryFolder && !((DisplayMode == ControlDisplayModeEnum.Simple) && isInDatabase); int width = 0; int height = 0; // Get thumb preview image dimensions int[] thumbImgDimension = { 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 parameters IconParameters previewParameters = null; if ((SourceType == MediaSourceEnum.MediaLibraries) && isInDatabase) { previewParameters = RaiseOnGetThumbsItemUrl(importedMediaData, true, thumbImgDimension[0], thumbImgDimension[1], 0, notAttachment); } else { previewParameters = RaiseOnGetThumbsItemUrl(data, true, thumbImgDimension[0], thumbImgDimension[1], 0, notAttachment); } // Item parameters IconParameters selectUrlParameters = RaiseOnGetThumbsItemUrl(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 var btnWarning = e.Item.FindControl("btnWarning") as CMSAccessibleButton; if (btnWarning != null) { // If media file not imported yet - display warning sign if (isSelectable && (SourceType == MediaSourceEnum.MediaLibraries) && ((DisplayMode == ControlDisplayModeEnum.Simple) && !isInDatabase && !libraryFolder && !libraryUiFolder)) { btnWarning.ToolTip = GetString("media.file.import"); btnWarning.OnClientClick = String.Format("ColorizeRow({0}); SetAction('importfile',{1}); RaiseHiddenPostBack(); return false;", ScriptHelper.GetString(GetColorizeID(data)), ScriptHelper.GetString(fullFileName)); } else { PlaceHolder plcWarning = e.Item.FindControl("plcWarning") as PlaceHolder; if (plcWarning != null) { plcWarning.Visible = false; } } } // Initialize SELECTSUBDOCS button var btnSelectSubDocs = e.Item.FindControl("btnSelectSubDocs") as CMSAccessibleButton; 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 btnSelectSubDocs.OnClientClick = String.Format("SetParentAction('{0}'); return false;", nodeId); } else { PlaceHolder plcSelectSubDocs = e.Item.FindControl("plcSelectSubDocs") as PlaceHolder; if (plcSelectSubDocs != null) { plcSelectSubDocs.Visible = false; } } } // Initialize VIEW button var btnView = e.Item.FindControl("btnView") as CMSAccessibleButton; if (btnView != null) { if (!notAttachment && !libraryFolder) { if (String.IsNullOrEmpty(selectUrlParameters.Url)) { btnView.OnClientClick = "return false;"; btnView.Attributes["style"] = "cursor:default;"; btnView.Enabled = false; } else { btnView.ToolTip = GetString("dialogs.list.actions.view"); btnView.OnClientClick = String.Format("javascript: window.open({0}); return false;", ScriptHelper.GetString(URLHelper.ResolveUrl(selectUrlParameters.Url))); } } else { btnView.Visible = false; } } // Initialize EDIT button var btnContentEdit = e.Item.FindControl("btnContentEdit") as CMSAccessibleButton; if (btnContentEdit != null) { btnContentEdit.ToolTip = GetString("general.edit"); 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.Attributes["style"] = "cursor: default;"; btnContentEdit.Enabled = false; } else { btnContentEdit.OnClientClick = String.Format("$cmsj('#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.ScreenReaderDescription = 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.ScreenReaderDescription = 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.ScreenReaderDescription = 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 var btnEdit = e.Item.FindControl("btnEdit") as CMSAccessibleButton; 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.ScreenReaderDescription = String.Format("{0}|AttachmentGUID={1}&sitename={2}&versionHistoryId={3}", extension, guid, GetSiteName(data, false), VersionHistoryID); btnEdit.PreRender += img_PreRender; } } // Initialize UPDATE button var dfuElem = e.Item.FindControl("dfuElem") as DirectFileUploader; if (dfuElem != null) { GetAttachmentUpdateControl(ref dfuElem, data); } // Setup external edit var ctrl = ExternalEditHelper.LoadExternalEditControl(e.Item.FindControl("plcExtEdit"), FileTypeEnum.Attachment, null, data, IsLiveSite, TreeNodeObj, true); if (ctrl != null) { ctrl.CssClass = null; } // Initialize DELETE button var btnDelete = e.Item.FindControl("btnDelete") as CMSAccessibleButton; if (btnDelete != null) { btnDelete.ToolTip = GetString("general.delete"); // Initialize command btnDelete.OnClientClick = String.Format("if(DeleteConfirmation() == false){{return false;}} SetAction('attachmentdelete','{0}'); RaiseHiddenPostBack(); return false;", data.GetValue("AttachmentGUID")); } var 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 var btnDelete = e.Item.FindControl("btnDelete") as CMSAccessibleButton; if (btnDelete != null) { btnDelete.ToolTip = GetString("general.delete"); btnDelete.OnClientClick = 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 var 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(); var disabledIcon = new CMSAccessibleButton { EnableViewState = false, Enabled = false, IconCssClass = "icon-arrow-up-line", IconOnly = true }; pnlDisabledUpdate.Controls.Add(disabledIcon); dfuElemLib.Visible = false; } } } // Setup external edit if (isInDatabase) { ExternalEditHelper.LoadExternalEditControl(e.Item.FindControl("plcExtEditMfi"), FileTypeEnum.MediaFile, GetSiteName(data, true), importedMediaData, IsLiveSite, null, true); } } else if (((SourceType == MediaSourceEnum.Content) && (DisplayMode == ControlDisplayModeEnum.Default) && !notAttachment && !libraryFolder && !libraryUiFolder)) { // Setup external edit if (data.ContainsColumn("AttachmentGUID")) { LoadExternalEditControl(e.Item, FileTypeEnum.Attachment); } } else if (((SourceType == MediaSourceEnum.MediaLibraries) && (DisplayMode == ControlDisplayModeEnum.Default) && !libraryFolder && !libraryUiFolder)) { // Setup external edit if (data.ContainsColumn("FileGUID")) { LoadExternalEditControl(e.Item, FileTypeEnum.MediaFile); } } else { var plcLibraryUpdtAction = e.Item.FindControl("plcLibraryUpdtAction") as PlaceHolder; if (plcLibraryUpdtAction != null) { plcLibraryUpdtAction.Visible = false; } } if ((SourceType == MediaSourceEnum.MediaLibraries) && libraryFolder && IsFullListingMode) { // Initialize SELECT SUB-FOLDERS button var btn = e.Item.FindControl("imgSelectSubFolders") as CMSAccessibleButton; if (btn != null) { btn.Visible = true; btn.ToolTip = GetString("dialogs.list.actions.showsubfolders"); btn.OnClientClick = String.Format("SetLibParentAction({0}); return false;", ScriptHelper.GetString(fileName)); } } else { var 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, selectUrlParameters.Url))); } 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(); var previewUrl = previewParameters.Url; 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; } if (String.IsNullOrEmpty(previewParameters.IconClass)) { 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); } } else { var imgIcon = e.Item.FindControl(("imgFileIcon")) as Label; if ((imgIcon != null) && imgIcon.Controls.Count < 1) { className = ValidationHelper.GetString(data.GetValue("ClassName"), String.Empty); var icon = UIHelper.GetDocumentTypeIcon(null, className, previewParameters.IconClass, previewParameters.IconSize); imgIcon.Controls.Add(new LiteralControl(icon)); // Ensure tooltip - only text description if (isInDatabase) { UIHelper.EnsureTooltip(imgIcon, previewUrl, width, height, GetTitle(data, isContentFile), fileName, ext, GetDescription(data, isContentFile), null, 300); } imgFile.Visible = false; } } } #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 CMSCheckBox chkSelected = e.Item.FindControl("chkSelected") as CMSCheckBox; 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; } } } } }
/// <summary> /// External data binding handler. /// </summary> protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter) { int currentNodeId; sourceName = sourceName.ToLowerCSafe(); switch (sourceName) { case "view": { // Dialog view item DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); CMSGridActionButton btn = ((CMSGridActionButton)sender); // Current row is the Root document isRootDocument = (ValidationHelper.GetInteger(data["NodeParentID"], 0) == 0); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); isCurrentDocument = (currentNodeId == WOpenerNodeID); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); // Existing document culture if (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe()) { string className = ValidationHelper.GetString(data["ClassName"], string.Empty); if (DataClassInfoProvider.GetDataClassInfo(className).ClassHasURL) { var relativeUrl = isRootDocument ? "~/" : DocumentUIHelper.GetPageHandlerPreviewPath(currentNodeId, culture, CurrentUser.UserName); string url = ResolveUrl(relativeUrl); btn.OnClientClick = "ViewItem(" + ScriptHelper.GetString(url) + "); return false;"; } else { btn.Enabled = false; btn.Style.Add(HtmlTextWriterStyle.Cursor, "default"); } } // New culture version else { btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } break; case "edit": { CMSGridActionButton btn = ((CMSGridActionButton)sender); if (IsEditVisible) { DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (!RequiresDialog || (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe())) { // Go to the selected document or create a new culture version when not used in a dialog btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;"; } else { // New culture version in a dialog btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } else { btn.Visible = false; } } break; case "delete": { // Delete button CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the delete button for the root document btn.Visible = !isRootDocument; } break; case "contextmenu": { // Dialog context menu item CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the context menu for the root document btn.Visible = !isRootDocument && !ShowAllLevels; } break; case "versionnumber": { // Version number if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return(parameter); } case "documentname": { // Document name DataRowView data = (DataRowView)parameter; string className = ValidationHelper.GetString(data["ClassName"], string.Empty); string classDisplayName = ValidationHelper.GetString(data["classdisplayname"], null); string name = ValidationHelper.GetString(data["DocumentName"], string.Empty); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); string cultureString = null; currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (isRootDocument) { // User site name for the root document name = SiteContext.CurrentSiteName; } // Default culture if (culture.ToLowerCSafe() != CultureCode.ToLowerCSafe()) { cultureString = " (" + culture + ")"; } StringBuilder sb = new StringBuilder(); if (ShowDocumentTypeIcon) { // Prepare tooltip for document type icon string iconTooltip = ""; if (ShowDocumentTypeIconTooltip && (classDisplayName != null)) { string safeClassName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(classDisplayName)); iconTooltip = string.Format("onmouseout=\"UnTip()\" onmouseover=\"Tip('{0}')\"", HTMLHelper.EncodeForHtmlAttribute(safeClassName)); } var dataClass = DataClassInfoProvider.GetDataClassInfo(className); if (dataClass != null) { var iconClass = (string)dataClass.GetValue("ClassIconClass"); sb.Append(UIHelper.GetDocumentTypeIcon(Page, className, iconClass, additionalAttributes: iconTooltip)); } } string safeName = HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)); if (DocumentNameAsLink && !isRootDocument) { string tooltip = UniGridFunctions.DocumentNameTooltip(data); string selectFunction = SelectItemJSFunction + "(" + currentNodeId + ", " + nodeParentId + ");"; sb.Append("<a href=\"javascript: ", selectFunction, "\""); sb.Append(" onmouseout=\"UnTip()\" onmouseover=\"Tip('", HTMLHelper.EncodeForHtmlAttribute(tooltip), "')\">", safeName, cultureString, "</a>"); } else { sb.Append(safeName, cultureString); } // Show document marks only if method is not called from grid export and document marks are allowed if ((sender != null) && ShowDocumentMarks) { // Prepare parameters int workflowStepId = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0); WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined; if (workflowStepId > 0) { WorkflowStepInfo stepInfo = WorkflowStepInfo.Provider.Get(workflowStepId); if (stepInfo != null) { stepType = stepInfo.StepType; } } // Create data container IDataContainer container = new DataRowContainer(data); // Add icons and use current culture of processed node because of 'Not translated document' icon sb.Append(" ", DocumentUIHelper.GetDocumentMarks(Page, currentSiteName, ValidationHelper.GetString(container.GetValue("DocumentCulture"), string.Empty), stepType, container)); } return(sb.ToString()); } case "documentculture": { DocumentFlagsControl ucDocFlags = null; if (OnDocumentFlagsCreating != null) { // Raise event for obtaining custom DocumentFlagControl object result = OnDocumentFlagsCreating(this, sourceName, parameter); ucDocFlags = result as DocumentFlagsControl; // Check if something other than DocumentFlagControl was returned if ((ucDocFlags == null) && (result != null)) { return(result); } } // Dynamically load document flags control when not created if (ucDocFlags == null) { ucDocFlags = LoadUserControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl; } // Set document flags properties if (ucDocFlags != null) { DataRowView data = (DataRowView)parameter; // Get node ID currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); if (!string.IsNullOrEmpty(SelectLanguageJSFunction)) { ucDocFlags.SelectJSFunction = SelectLanguageJSFunction; } ucDocFlags.ID = "docFlags" + currentNodeId; ucDocFlags.SiteCultures = SiteCultures; ucDocFlags.NodeID = currentNodeId; ucDocFlags.StopProcessing = true; // Keep the control for later usage FlagsControls.Add(ucDocFlags); return(ucDocFlags); } } break; case "modifiedwhen": case "modifiedwhentooltip": // Modified when if (string.IsNullOrEmpty(parameter.ToString())) { return(string.Empty); } DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); currentUserInfo = currentUserInfo ?? MembershipContext.AuthenticatedUser; currentSiteInfo = currentSiteInfo ?? SiteContext.CurrentSite; return(sourceName.EqualsCSafe("modifiedwhen", StringComparison.InvariantCultureIgnoreCase) ? TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, true, currentUserInfo, currentSiteInfo) : TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo)); default: if (OnExternalAdditionalDataBound != null) { return(OnExternalAdditionalDataBound(sender, sourceName, parameter)); } break; } return(parameter); }
/// <summary> /// Handles actions occuring when some item in copy/move/link/select path dialog is selected. /// </summary> private void HandleDialogSelect() { if (TreeNodeObj != null) { string columns = SqlHelperClass.MergeColumns((IsLiveSite ? TreeProvider.SELECTNODES_REQUIRED_COLUMNS : DocumentHelper.GETDOCUMENTS_REQUIRED_COLUMNS), NODE_COLUMNS); // Get files TreeNodeObj.TreeProvider.SelectQueryName = "selectattachments"; DataSet nodeDetails = null; if (IsLiveSite) { // Get published files nodeDetails = TreeNodeObj.TreeProvider.SelectNodes(SiteName, TreeNodeObj.NodeAliasPath, CMSContext.CurrentUser.PreferredCultureCode, true, null, null, "DocumentName", 1, true, 1, columns); } else { // Get latest files nodeDetails = DocumentHelper.GetDocuments(SiteName, TreeNodeObj.NodeAliasPath, CMSContext.CurrentUser.PreferredCultureCode, true, null, null, "DocumentName", 1, false, 1, columns, TreeNodeObj.TreeProvider); } // If node details exists if (!DataHelper.IsEmpty(nodeDetails)) { IDataContainer data = new DataRowContainer(nodeDetails.Tables[0].Rows[0]); string argument = mediaView.GetArgumentSet(data); bool notAttachment = (SourceType == MediaSourceEnum.Content) && !((data.GetValue("ClassName").ToString().ToLower() == "cms.file") && (ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty) != Guid.Empty)); string url = mediaView.GetItemUrl(argument, 0, 0, 0, notAttachment); SelectMediaItem(String.Format("{0}|URL|{1}", argument, url)); } ItemToColorize = TreeNodeObj.NodeGUID; } else { // Remove selected item ItemToColorize = Guid.Empty; } ClearColorizedRow(); // Forget recent action ClearActionElems(); }
protected void ViewControl_ItemDataBound(object sender, RepeaterItemEventArgs e) { DataRowView drv = (DataRowView)e.Item.DataItem; IDataContainer data = new DataRowContainer(drv); string fileNameColumn = FileNameColumn; // Get information on file string fileName = HTMLHelper.HTMLEncode(data.GetValue(fileNameColumn).ToString()); string ext = HTMLHelper.HTMLEncode(data.GetValue(FileExtensionColumn).ToString()); // Load file type Label lblType = e.Item.FindControl("lblTypeValue") as Label; if (lblType != null) { fileName = fileName.Substring(0, fileName.Length - ext.Length); lblType.Text = ResHelper.LocalizeString(ext); } // Load file name Label lblName = e.Item.FindControl("lblFileName") as Label; if (lblName != null) { lblName.Text = fileName; } // Load file size Label lblSize = e.Item.FindControl("lblSizeValue") as Label; if (lblSize != null) { long size = ValidationHelper.GetLong(data.GetValue(FileSizeColumn), 0); lblSize.Text = DataHelper.GetSizeString(size); } string argument = RaiseOnGetArgumentSet(drv.Row); string selectAction = GetSelectScript(drv, argument); // Initialize EDIT button var btnEdit = e.Item.FindControl("btnEdit") as CMSAccessibleButton; if (btnEdit != null) { btnEdit.ToolTip = GetString("general.edit"); string path = data.GetValue("Path").ToString(); string editScript = GetEditScript(path, ext); if (!String.IsNullOrEmpty(editScript)) { btnEdit.OnClientClick = editScript; } else { btnEdit.Visible = false; } } // Initialize DELETE button var btnDelete = e.Item.FindControl("btnDelete") as CMSAccessibleButton; if (btnDelete != null) { btnDelete.ToolTip = GetString("general.delete"); btnDelete.OnClientClick = GetDeleteScript(argument); } // Image area Image fileImage = e.Item.FindControl("imgElem") as Image; if (fileImage != null) { string url; if (ImageHelper.IsImage(ext)) { url = URLHelper.UnMapPath(data.GetValue("Path").ToString()); // Generate new tooltip command if (!String.IsNullOrEmpty(url)) { url = String.Format("{0}?chset={1}", url, Guid.NewGuid()); UIHelper.EnsureTooltip(fileImage, ResolveUrl(url), 0, 0, null, null, ext, null, null, 300); } fileImage.ImageUrl = ResolveUrl(url); } else { fileImage.Visible = false; Literal literalImage = e.Item.FindControl("ltrImage") as Literal; if (literalImage != null) { literalImage.Text = UIHelper.GetFileIcon(Page, ext, FontIconSizeEnum.Dashboard); } } } // Selectable area Panel pnlItemInageContainer = e.Item.FindControl("pnlThumbnails") as Panel; if (pnlItemInageContainer != null) { pnlItemInageContainer.Attributes["onclick"] = selectAction; pnlItemInageContainer.Attributes["style"] = "cursor:pointer;"; } }
/// <summary> /// External data binding handler. /// </summary> protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter) { int currentNodeId; sourceName = sourceName.ToLowerCSafe(); switch (sourceName) { case "view": { // Dialog view item DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); CMSGridActionButton btn = ((CMSGridActionButton)sender); // Current row is the Root document isRootDocument = (ValidationHelper.GetInteger(data["NodeParentID"], 0) == 0); isCurrentDocument = (ValidationHelper.GetInteger(data["NodeID"], 0) == WOpenerNodeID); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); // Existing document culture if (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe()) { string url = ResolveUrl(!isRootDocument ? DocumentURLProvider.GetUrl(Convert.ToString(data["NodeAliasPath"])) : "~/"); btn.OnClientClick = "ViewItem(" + ScriptHelper.GetString(url) + "); return false;"; } // New culture version else { currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } break; case "edit": { CMSGridActionButton btn = ((CMSGridActionButton)sender); if (IsEditVisible) { DataRowView data = ((DataRowView)((GridViewRow)parameter).DataItem); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (!RequiresDialog || (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe())) { // Go to the selected document or create a new culture version when not used in a dialog btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;"; } else { // New culture version in a dialog btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;"; } } else { btn.Visible = false; } } break; case "delete": { // Delete button CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the delete button for the root document btn.Visible = !isRootDocument; } break; case "contextmenu": { // Dialog context menu item CMSGridActionButton btn = ((CMSGridActionButton)sender); // Hide the context menu for the root document btn.Visible = !isRootDocument && !ShowAllLevels; } break; case "published": { // Published state return UniGridFunctions.ColoredSpanYesNo(parameter); } case "versionnumber": { // Version number if (parameter == DBNull.Value) { parameter = "-"; } parameter = HTMLHelper.HTMLEncode(parameter.ToString()); return parameter; } case "documentname": { // Document name DataRowView data = (DataRowView)parameter; string className = ValidationHelper.GetString(data["ClassName"], string.Empty); string classDisplayName = ValidationHelper.GetString(data["classdisplayname"], null); string name = ValidationHelper.GetString(data["DocumentName"], string.Empty); string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty); string cultureString = null; currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0); if (isRootDocument) { // User site name for the root document name = SiteContext.CurrentSiteName; } // Default culture if (culture.ToLowerCSafe() != CultureCode.ToLowerCSafe()) { cultureString = " (" + culture + ")"; } StringBuilder sb = new StringBuilder(); if (ShowDocumentTypeIcon) { // Prepare tooltip for document type icon string iconTooltip = ""; if (ShowDocumentTypeIconTooltip && (classDisplayName != null)) { iconTooltip = string.Format("onmouseout=\"UnTip()\" onmouseover=\"Tip('{0}')\"", HTMLHelper.HTMLEncode(ResHelper.LocalizeString(classDisplayName))); } if (className.EqualsCSafe("cms.file", true)) { string extension = ValidationHelper.GetString(data["DocumentType"], string.Empty); sb.Append(UIHelper.GetFileIcon(Page, extension, additionalAttributes: iconTooltip)); } // Use class icons else { var dataClass = DataClassInfoProvider.GetDataClassInfo(className); if (dataClass != null) { var iconClass = (string)dataClass.GetValue("ClassIconClass"); sb.Append(UIHelper.GetDocumentTypeIcon(Page, className, iconClass, additionalAttributes: iconTooltip)); } } } string safeName = HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)); if (DocumentNameAsLink && !isRootDocument) { string tooltip = UniGridFunctions.DocumentNameTooltip(data); string selectFunction = SelectItemJSFunction + "(" + currentNodeId + ", " + nodeParentId + ");"; sb.Append("<a href=\"javascript: ", selectFunction, "\""); // Ensure onclick action on mobile devices. This is necessary due to Tip/UnTip functions. They block default click behavior on mobile devices. if (DeviceContext.CurrentDevice.IsMobile) { sb.Append(" ontouchend=\"", selectFunction, "\""); } sb.Append(" onmouseout=\"UnTip()\" onmouseover=\"Tip('", tooltip, "')\">", safeName, cultureString, "</a>"); } else { sb.Append(safeName, cultureString); } // Show document marks only if method is not called from grid export and document marks are allowed if ((sender != null) && ShowDocumentMarks) { // Prepare parameters int workflowStepId = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0); WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined; if (workflowStepId > 0) { WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId); if (stepInfo != null) { stepType = stepInfo.StepType; } } // Create data container IDataContainer container = new DataRowContainer(data); // Add icons and use current culture of processed node because of 'Not translated document' icon sb.Append(" ", DocumentHelper.GetDocumentMarks(Page, currentSiteName, ValidationHelper.GetString(container.GetValue("DocumentCulture"), string.Empty), stepType, container)); } return sb.ToString(); } case "documentculture": { DocumentFlagsControl ucDocFlags = null; if (OnDocumentFlagsCreating != null) { // Raise event for obtaining custom DocumentFlagControl object result = OnDocumentFlagsCreating(this, sourceName, parameter); ucDocFlags = result as DocumentFlagsControl; // Check if something other than DocumentFlagControl was returned if ((ucDocFlags == null) && (result != null)) { return result; } } // Dynamically load document flags control when not created if (ucDocFlags == null) { ucDocFlags = LoadUserControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl; } // Set document flags properties if (ucDocFlags != null) { DataRowView data = (DataRowView)parameter; // Get node ID currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0); if (!string.IsNullOrEmpty(SelectLanguageJSFunction)) { ucDocFlags.SelectJSFunction = SelectLanguageJSFunction; } ucDocFlags.ID = "docFlags" + currentNodeId; ucDocFlags.SiteCultures = SiteCultures; ucDocFlags.NodeID = currentNodeId; ucDocFlags.StopProcessing = true; ucDocFlags.ItemUrl = ResolveUrl(DocumentURLProvider.GetUrl(Convert.ToString(data["NodeAliasPath"]))); // Keep the control for later usage FlagsControls.Add(ucDocFlags); return ucDocFlags; } } break; case "modifiedwhen": case "modifiedwhentooltip": // Modified when if (string.IsNullOrEmpty(parameter.ToString())) { return string.Empty; } else { DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME); currentUserInfo = currentUserInfo ?? MembershipContext.AuthenticatedUser; currentSiteInfo = currentSiteInfo ?? SiteContext.CurrentSite; if (sourceName.EqualsCSafe("modifiedwhen", StringComparison.InvariantCultureIgnoreCase)) { return TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, true, currentUserInfo, currentSiteInfo); } else { return TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo); } } case "classdisplayname": case "classdisplaynametooltip": // Localize class display name if (!string.IsNullOrEmpty(parameter.ToString())) { return HTMLHelper.HTMLEncode(ResHelper.LocalizeString(parameter.ToString())); } return string.Empty; default: if (OnExternalAdditionalDataBound != null) { return OnExternalAdditionalDataBound(sender, sourceName, parameter); } break; } return parameter; }
/// <summary> /// Sets visibility of WebDAV edit control. /// </summary> /// <param name="repeaterItem">Repeater item</param> /// <param name="controlType">Control type</param> 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); } } } }
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() == "<dir>")); 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; } } } } }