protected void dfuElem_PreRender(object sender, EventArgs e) { DirectFileUploader dfuElem = (DirectFileUploader)sender; if (Enabled) { dfuElem.ForceLoad = true; dfuElem.FormGUID = FormGUID; dfuElem.AttachmentGroupGUID = GroupGUID; dfuElem.DocumentID = DocumentID; dfuElem.NodeParentNodeID = NodeParentNodeID; dfuElem.NodeClassName = NodeClassName; dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; dfuElem.ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/upload.png")); dfuElem.ImageHeight = 16; dfuElem.ImageWidth = 16; dfuElem.InsertMode = false; dfuElem.ParentElemID = ClientID; dfuElem.CheckPermissions = CheckPermissions; dfuElem.IsLiveSite = IsLiveSite; dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.MaxNumberToUpload = 1; dfuElem.Height = 16; dfuElem.Width = 16; } else { dfuElem.Visible = false; } }
/// <summary> /// Returns updated IFrame URL when required. /// </summary> /// <param name="dr">Data row holding information on imported media file</param> public string GetUpdateIFrameUrl(IDataContainer data) { string result = null; // Uploader is displayed only for imported files - have FileIDs if ((data != null) && data.ContainsColumn("FileID")) { DirectFileUploader dfuElem = (Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader); innermedia.GetLibraryUpdateControl(ref dfuElem, data); result = dfuElem.IFrameUrl; } return(result); }
private void CreateUploaderControl(DataRowView drv, Panel pnlBlock) { // Add update control // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadUserControl(CONTENT_FOLDER + "Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; // Set uploader's properties if (dfuElem != null) { dfuElem.ID = "dfuElem" + DocumentID; dfuElem.SourceType = MediaSourceEnum.Attachment; dfuElem.DisplayInline = true; if (!createTempAttachment) { dfuElem.AttachmentGUID = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty); } dfuElem.ForceLoad = true; dfuElem.FormGUID = FormGUID; dfuElem.AttachmentGUIDColumnName = GUIDColumnName; dfuElem.DocumentID = DocumentID; dfuElem.NodeParentNodeID = NodeParentNodeID; dfuElem.NodeClassName = NodeClassName; dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; dfuElem.ShowIconMode = true; dfuElem.InsertMode = false; dfuElem.ParentElemID = ClientID; dfuElem.IncludeNewItemInfo = true; dfuElem.CheckPermissions = CheckPermissions; dfuElem.NodeSiteName = SiteName; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.MaxNumberToUpload = 1; dfuElem.PreRender += dfuElem_PreRender; pnlBlock.Controls.Add(dfuElem); } }
/// <summary> /// Gets HTML code of rendered DirectFileUploader control. /// </summary> /// <param name="mfi">Media file information</param> public string GetDirectFileUploaderHTML(MediaFileInfo mfi) { StringBuilder sb = new StringBuilder(); using (StringWriter tw = new StringWriter(sb)) { HtmlTextWriter hw = new HtmlTextWriter(tw); DirectFileUploader dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; if (dfuElem != null) { using (Panel updatePanel = new Panel()) { // Initialize update control innermedia.GetLibraryUpdateControl(ref dfuElem, mfi); dfuElem.ReloadData(); updatePanel.Attributes["style"] = "height:16px;display:inline;"; updatePanel.Controls.Add(dfuElem); updatePanel.RenderControl(hw); } } } return(sb.ToString()); }
protected void Page_Load(object sender, EventArgs e) { // Validate query string if (!QueryHelper.ValidateHash("hash")) { // Do nothing } else { String identifier = QueryHelper.GetString("identifier", null); if (String.IsNullOrEmpty(identifier)) { return; } properties = WindowHelper.GetItem(identifier) as Hashtable; if (properties == null) { return; } // Get information on current source type string sourceType = ValidationHelper.GetString(GetProp("source"), "attachments"); SourceType = CMSDialogHelper.GetMediaSource(sourceType); // Ensure additional styles CurrentMaster.HeadElements.Visible = true; CurrentMaster.HeadElements.Text += CssHelper.GetStyle("*{direction:ltr !important;}body{background:transparent !important;}input,input:focus,input:hover,input:active{border:none;border-color:transparent;outline:none;}"); // Get uploader control based on the current source type string uploaderPath = ""; if (SourceType == MediaSourceEnum.MediaLibraries) { // If media library module is running if (ModuleManager.IsModuleLoaded(ModuleName.MEDIALIBRARY)) { uploaderPath = "~/CMSModules/MediaLibrary/Controls/Dialogs/DirectFileUploader/DirectMediaFileUploaderControl.ascx"; } } else { uploaderPath = "~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploaderControl.ascx"; } // Load direct file uploader if (uploaderPath != "") { DirectFileUploader fileUploaderElem = this.LoadUserControl(uploaderPath) as DirectFileUploader; if (fileUploaderElem != null) { // Insert uploader to parent container pnlUploaderElem.Controls.Add(fileUploaderElem); // Initialize uploader control properties by query string values fileUploaderElem.AttachmentGUID = ValidationHelper.GetGuid(GetProp("attachmentguid"), Guid.Empty); fileUploaderElem.AttachmentGroupGUID = ValidationHelper.GetGuid(GetProp("attachmentgroupguid"), Guid.Empty); fileUploaderElem.AttachmentGUIDColumnName = ValidationHelper.GetString(GetProp("attachmentguidcolumnname"), null); fileUploaderElem.FormGUID = ValidationHelper.GetGuid(GetProp("formguid"), Guid.Empty); fileUploaderElem.DocumentID = ValidationHelper.GetInteger(GetProp("documentid"), 0); fileUploaderElem.NodeParentNodeID = ValidationHelper.GetInteger(GetProp("parentid"), 0); fileUploaderElem.NodeClassName = ValidationHelper.GetString(GetProp("classname"), ""); fileUploaderElem.InsertMode = ValidationHelper.GetBoolean(GetProp("insertmode"), false); fileUploaderElem.OnlyImages = ValidationHelper.GetBoolean(GetProp("onlyimages"), false); fileUploaderElem.ParentElemID = QueryHelper.GetString("parentelemid", String.Empty); fileUploaderElem.CheckPermissions = ValidationHelper.GetBoolean(GetProp("checkperm"), true); fileUploaderElem.IsLiveSite = false; fileUploaderElem.RaiseOnClick = ValidationHelper.GetBoolean(GetProp("click"), false); fileUploaderElem.NodeSiteName = ValidationHelper.GetString(GetProp("sitename"), null); fileUploaderElem.SourceType = SourceType; // Metafile upload fileUploaderElem.SiteID = ValidationHelper.GetInteger(GetProp("siteid"), 0); fileUploaderElem.Category = ValidationHelper.GetString(GetProp("category"), String.Empty); fileUploaderElem.ObjectID = ValidationHelper.GetInteger(GetProp("objectid"), 0); fileUploaderElem.ObjectType = ValidationHelper.GetString(GetProp("objecttype"), String.Empty); fileUploaderElem.MetaFileID = ValidationHelper.GetInteger(GetProp("metafileid"), 0); // Library info initialization; fileUploaderElem.LibraryID = ValidationHelper.GetInteger(GetProp("libraryid"), 0); fileUploaderElem.MediaFileID = ValidationHelper.GetInteger(GetProp("mediafileid"), 0); fileUploaderElem.MediaFileName = ValidationHelper.GetString(GetProp("filename"), null); fileUploaderElem.IsMediaThumbnail = ValidationHelper.GetBoolean(GetProp("ismediathumbnail"), false); fileUploaderElem.LibraryFolderPath = ValidationHelper.GetString(GetProp("path"), ""); fileUploaderElem.IncludeNewItemInfo = ValidationHelper.GetBoolean(GetProp("includeinfo"), false); string siteName = SiteContext.CurrentSiteName; string allowed = ValidationHelper.GetString(GetProp("allowedextensions"), null); if (allowed == null) { if (fileUploaderElem.SourceType == MediaSourceEnum.MediaLibraries) { allowed = SettingsKeyInfoProvider.GetValue(siteName + ".CMSMediaFileAllowedExtensions"); } else { allowed = SettingsKeyInfoProvider.GetValue(siteName + ".CMSUploadExtensions"); } } fileUploaderElem.AllowedExtensions = allowed; // Auto resize width int autoResizeWidth = ValidationHelper.GetInteger(GetProp("autoresize_width"), -1); if (autoResizeWidth == -1) { autoResizeWidth = SettingsKeyInfoProvider.GetIntValue(siteName + ".CMSAutoResizeImageWidth"); } fileUploaderElem.ResizeToWidth = autoResizeWidth; // Auto resize height int autoResizeHeight = ValidationHelper.GetInteger(GetProp("autoresize_height"), -1); if (autoResizeHeight == -1) { autoResizeHeight = SettingsKeyInfoProvider.GetIntValue(siteName + ".CMSAutoResizeImageHeight"); } fileUploaderElem.ResizeToHeight = autoResizeHeight; // Auto resize max side size int autoResizeMaxSideSize = ValidationHelper.GetInteger(GetProp("autoresize_maxsidesize"), -1); if (autoResizeMaxSideSize == -1) { autoResizeMaxSideSize = SettingsKeyInfoProvider.GetIntValue(siteName + ".CMSAutoResizeImageMaxSideSize"); } fileUploaderElem.ResizeToMaxSideSize = autoResizeMaxSideSize; fileUploaderElem.AfterSaveJavascript = ValidationHelper.GetString(GetProp("aftersave"), String.Empty); fileUploaderElem.TargetFolderPath = ValidationHelper.GetString(GetProp("targetfolder"), String.Empty); fileUploaderElem.TargetFileName = ValidationHelper.GetString(GetProp("targetfilename"), String.Empty); } } } }
/// <summary> /// UniGrid external data bound. /// </summary> protected object GridDocsOnExternalDataBound(object sender, string sourceName, object parameter) { string attName = null; string attachmentExt = null; DataRowView drv = null; switch (sourceName.ToLowerCSafe()) { case "update": drv = parameter as DataRowView; PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateAction"; Panel pnlBlock = new Panel(); pnlBlock.ID = "pnlBlock"; plcUpd.Controls.Add(pnlBlock); // Add disabled image ImageButton imgUpdate = new ImageButton(); imgUpdate.ID = "imgUpdate"; imgUpdate.PreRender += imgUpdate_PreRender; pnlBlock.Controls.Add(imgUpdate); // Add update control // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; // Set uploader's properties if (dfuElem != null) { dfuElem.ID = "dfuElem" + DocumentID; dfuElem.SourceType = MediaSourceEnum.Attachment; dfuElem.DisplayInline = true; if (!createTempAttachment) { dfuElem.AttachmentGUID = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty); } dfuElem.ForceLoad = true; dfuElem.FormGUID = FormGUID; dfuElem.AttachmentGUIDColumnName = GUIDColumnName; dfuElem.DocumentID = DocumentID; dfuElem.NodeParentNodeID = NodeParentNodeID; dfuElem.NodeClassName = NodeClassName; dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; dfuElem.ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/upload.png")); dfuElem.ImageHeight = 16; dfuElem.ImageWidth = 16; dfuElem.InsertMode = false; dfuElem.ParentElemID = ClientID; dfuElem.IncludeNewItemInfo = true; dfuElem.CheckPermissions = CheckPermissions; dfuElem.NodeSiteName = SiteName; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.Width = 16; dfuElem.Height = 16; dfuElem.MaxNumberToUpload = 1; dfuElem.PreRender += dfuElem_PreRender; pnlBlock.Controls.Add(dfuElem); } attName = ValidationHelper.GetString(drv["AttachmentName"], string.Empty); attachmentExt = ValidationHelper.GetString(drv["AttachmentExtension"], string.Empty); int nodeGroupId = (Node != null) ? Node.GetIntegerValue("NodeGroupID") : 0; bool displayGroupAdmin = true; // Check group admin for live site if (IsLiveSite && (nodeGroupId > 0)) { displayGroupAdmin = CMSContext.CurrentUser.IsGroupAdministrator(nodeGroupId); } // Check if WebDAV allowed by the form bool allowWebDAV = (Form == null) ? true : Form.AllowWebDAV; // Add WebDAV edit control if (allowWebDAV && CMSContext.IsWebDAVEnabled(SiteName) && RequestHelper.IsWindowsAuthentication() && (FormGUID == Guid.Empty) && WebDAVSettings.IsExtensionAllowedForEditMode(attachmentExt, SiteName) && displayGroupAdmin) { // Dynamically load control WebDAVEditControl webdavElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl; // Set editor's properties if (webdavElem != null) { webdavElem.ID = "webdavElem" + DocumentID; // Ensure form identification if ((Form != null) && (Form.Parent != null)) { webdavElem.FormID = Form.Parent.ClientID; } webdavElem.PreRender += webdavElem_PreRender; webdavElem.SiteName = SiteName; webdavElem.FileName = attName; webdavElem.NodeAliasPath = Node.NodeAliasPath; webdavElem.NodeCultureCode = Node.DocumentCulture; if (FieldInfo != null) { webdavElem.AttachmentFieldName = FieldInfo.Name; } // Set Group ID for live site webdavElem.GroupID = IsLiveSite ? nodeGroupId : 0; webdavElem.IsLiveSite = IsLiveSite; // Align left if WebDAV is enabled and windows authentication is enabled bool isRTL = (IsLiveSite && CultureHelper.IsPreferredCultureRTL()) || (!IsLiveSite && CultureHelper.IsUICultureRTL()); pnlBlock.Style.Add("text-align", isRTL ? "right" : "left"); pnlBlock.Controls.Add(webdavElem); } } return(plcUpd); case "edit": // Get file extension string extension = ValidationHelper.GetString(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentExtension"], string.Empty).ToLowerCSafe(); // Get attachment GUID attachmentGuid = ValidationHelper.GetGuid(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentGUID"], Guid.Empty); if (sender is ImageButton) { ImageButton img = (ImageButton)sender; if (createTempAttachment) { img.Visible = false; } else { img.AlternateText = extension; img.ToolTip = attachmentGuid.ToString(); img.PreRender += img_PreRender; } } break; case "delete": if (sender is ImageButton) { ImageButton imgDelete = (ImageButton)sender; // Turn off validation imgDelete.CausesValidation = false; imgDelete.PreRender += imgDelete_PreRender; // Explicitly initialize confirmation imgDelete.OnClientClick = "if(DeleteConfirmation() == false){return false;}"; } break; case "attachmentname": { drv = parameter as DataRowView; // Get attachment GUID attachmentGuid = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty); // Get attachment extension attachmentExt = ValidationHelper.GetString(drv["AttachmentExtension"], string.Empty); bool isImage = ImageHelper.IsImage(attachmentExt); string iconUrl = GetFileIconUrl(attachmentExt, "List"); // Get link for attachment string attachmentUrl = null; attName = ValidationHelper.GetString(drv["AttachmentName"], string.Empty); int documentId = DocumentID; if (Node != null) { if (IsLiveSite && (documentId > 0)) { attachmentUrl = CMSContext.ResolveUIUrl(TreePathUtils.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, CMSContext.CurrentSiteName), 0, null)); } else { attachmentUrl = CMSContext.ResolveUIUrl(TreePathUtils.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, CMSContext.CurrentSiteName), VersionHistoryID, null)); } } else { attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attachmentGuid, VersionHistoryID)); } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Ensure correct URL if (OriginalNodeSiteName != CMSContext.CurrentSiteName) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", OriginalNodeSiteName); } // Add latest version requirement for live site if (IsLiveSite && (documentId > 0)) { // Add requirement for latest version of files for current document string newparams = "latestfordocid=" + documentId; newparams += "&hash=" + ValidationHelper.GetHashString("d" + documentId); attachmentUrl += "&" + newparams; } // Optionally trim attachment name string attachmentName = TextHelper.LimitLength(attName, ATTACHMENT_NAME_LIMIT, "..."); // Tooltip string tooltip = null; if (ShowTooltip) { string title = ValidationHelper.GetString(drv["AttachmentTitle"], string.Empty); ; string description = ValidationHelper.GetString(drv["AttachmentDescription"], string.Empty); int imageWidth = ValidationHelper.GetInteger(drv["AttachmentImageWidth"], 0); int imageHeight = ValidationHelper.GetInteger(drv["AttachmentImageHeight"], 0); tooltip = UIHelper.GetTooltipAttributes(attachmentUrl, imageWidth, imageHeight, title, attachmentName, attachmentExt, description, null, 300); } // Icon string imageTag = "<img class=\"Icon\" src=\"" + iconUrl + "\" alt=\"" + attachmentName + "\" />"; if (isImage) { return("<a href=\"#\" onclick=\"javascript: window.open('" + attachmentUrl + "'); return false;\"><span " + tooltip + ">" + imageTag + attachmentName + "</span></a>"); } else { return("<a href=\"" + attachmentUrl + "\"><span id=\"" + attachmentGuid + "\" " + tooltip + ">" + imageTag + attachmentName + "</span></a>"); } } case "attachmentsize": long size = ValidationHelper.GetLong(parameter, 0); return(DataHelper.GetSizeString(size)); } return(parameter); }
protected object gridFiles_OnExternalDataBound(object sender, string sourceName, object parameter) { GridViewRow gvr = null; DataRowView drv = null; string fileGuid = null; switch (sourceName.ToLower()) { case "edit": if (sender is ImageButton) { gvr = (GridViewRow)parameter; drv = (DataRowView)gvr.DataItem; fileGuid = ValidationHelper.GetString(drv["MetaFileGUID"], ""); string fileExtension = ValidationHelper.GetString(drv["MetaFileExtension"], ""); // Initialize properties ImageButton btnImageEditor = (ImageButton)sender; btnImageEditor.Visible = true; // Display button only if 'Modify' is allowed if (AllowModify) { string query = String.Format("?metafileguid={0}&clientid={1}", fileGuid, ClientID); query = URLHelper.AddUrlParameter(query, "hash", QueryHelper.GetHash(query)); // Display button only if metafile is in supported image format if (ImageHelper.IsSupportedByImageEditor(fileExtension)) { // Initialize button with script btnImageEditor.Attributes.Add("onclick", String.Format("OpenImageEditor({0}); return false;", ScriptHelper.GetString(query))); } // Non-image metafile else { // Initialize button with script btnImageEditor.Attributes.Add("onclick", String.Format("OpenEditor({0}); return false;", ScriptHelper.GetString(query))); } } else { btnImageEditor.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/editdisabled.png"); btnImageEditor.Enabled = false; } } break; case "paste": if (sender is ImageButton) { gvr = (GridViewRow)parameter; drv = (DataRowView)gvr.DataItem; fileGuid = ValidationHelper.GetString(drv["MetaFileGUID"], ""); int fileWidth = ValidationHelper.GetInteger(drv["MetaFileImageWidth"], 0); int fileHeight = ValidationHelper.GetInteger(drv["MetaFileImageHeight"], 0); ImageButton btnPaste = (ImageButton)sender; btnPaste.Visible = AllowPasteAttachments; if (AllowPasteAttachments) { if ((fileWidth > 0) && (fileHeight > 0)) { string appPath = URLHelper.ApplicationPath; if ((appPath == null) || (appPath == "/")) { appPath = String.Empty; } btnPaste.OnClientClick = String.Format("PasteImage('{0}/CMSPages/GetMetaFile.aspx?fileguid={1}'); return false", appPath, fileGuid); } else { btnPaste.Visible = false; } } else { btnPaste.Visible = false; } } break; case "delete": if (sender is ImageButton) { ImageButton btnDelete = ((ImageButton)sender); btnDelete.Visible = AllowModify; if (!AllowModify) { btnDelete.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/deletedisabled.png"); } } break; case "name": drv = (DataRowView)parameter; string fileName = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "MetaFileName"), string.Empty); fileGuid = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "MetaFileGUID"), string.Empty); string fileExt = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "MetaFileExtension"), string.Empty); string iconUrl = GetFileIconUrl(fileExt, "List"); bool isImage = ImageHelper.IsImage(fileExt); string fileUrl = String.Format("{0}?fileguid={1}&chset={2}", URLHelper.GetAbsoluteUrl("~/CMSPages/GetMetaFile.aspx"), fileGuid, Guid.NewGuid()); // Tooltip string title = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "MetaFileTitle"), string.Empty);; string description = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "MetaFileDescription"), string.Empty); int imageWidth = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "MetaFileImageWidth"), 0); int imageHeight = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "MetaFileImageHeight"), 0); string tooltip = UIHelper.GetTooltipAttributes(fileUrl, imageWidth, imageHeight, title, fileName, fileExt, description, null, 300); // Icon string imageTag = String.Format("<img class=\"Icon\" src=\"{0}\" alt=\"{1}\" />", iconUrl, fileName); if (isImage) { return(String.Format("<a href=\"#\" onclick=\"javascript: window.open('{0}'); return false;\"><span id=\"{1}\" {2}>{3}{4}</span></a>", fileUrl, fileGuid, tooltip, imageTag, fileName)); } else { return(String.Format("<a href=\"{0}\"><span id=\"{1}\" {2}>{3}{4}</span></a>", fileUrl, fileGuid, tooltip, imageTag, fileName)); } case "size": return(DataHelper.GetSizeString(ValidationHelper.GetLong(parameter, 0))); case "update": { // Display buttons only if 'Modify' is allowed if (AllowModify) { drv = (DataRowView)parameter; Panel pnlBlock = new Panel() { ID = "pnlBlock" }; string fileExtension = ValidationHelper.GetString(drv["MetaFileExtension"], null); string siteName = null; if (SiteID > 0) { SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteID); if (si != null) { siteName = si.SiteName; } } else { siteName = CMSContext.CurrentSiteName; } // Add update control // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; // Set uploader's properties if (dfuElem != null) { dfuElem.ID = "dfuElem" + ObjectID; dfuElem.SourceType = MediaSourceEnum.MetaFile; dfuElem.ControlGroup = "Uploader_" + ObjectID; dfuElem.DisplayInline = true; dfuElem.ForceLoad = true; dfuElem.MetaFileID = ValidationHelper.GetInteger(drv["MetaFileID"], 0); dfuElem.ObjectID = ObjectID; dfuElem.ObjectType = ObjectType; dfuElem.Category = Category; dfuElem.ParentElemID = ClientID; dfuElem.ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/upload.png")); dfuElem.ImageHeight = 16; dfuElem.ImageWidth = 16; dfuElem.InsertMode = false; dfuElem.ParentElemID = ClientID; dfuElem.IncludeNewItemInfo = true; dfuElem.SiteID = SiteID; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.Width = 16; dfuElem.Height = 16; dfuElem.MaxNumberToUpload = 1; dfuElem.EnableSilverlightUploader = false; pnlBlock.Controls.Add(dfuElem); } // If the WebDAV is enabled and windows authentication if (CMSContext.IsWebDAVEnabled(siteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(fileExtension, siteName)) { // Dynamically load control WebDAVEditControl webDAVElem = Page.LoadControl("~/CMSModules/WebDAV/Controls/MetaFileWebDAVEditControl.ascx") as WebDAVEditControl; // Set editor's properties if (webDAVElem != null) { // Initialize WebDAV control fileGuid = ValidationHelper.GetString(drv["MetaFileGUID"], ""); webDAVElem.MetaFileGUID = ValidationHelper.GetGuid(fileGuid, Guid.Empty); webDAVElem.FileName = ValidationHelper.GetString(drv["MetaFileName"], null); webDAVElem.Enabled = AllowModify; // Initialize general info webDAVElem.ID = "webDAVElem"; webDAVElem.IsLiveSite = IsLiveSite; // Add to panel pnlBlock.Controls.Add(webDAVElem); } } return(pnlBlock); } return(null); } } return(parameter); }
/// <summary> /// Initializes upload control. /// When data is null, the control can be rendered as disabled only. /// </summary> /// <param name="dfuElem">Upload control to initialize</param> /// <param name="data">Data row with data on related media file</param> public void GetLibraryUpdateControl(ref DirectFileUploader dfuElem, IDataContainer data) { if (dfuElem != null) { if (data != null) { string siteName = GetSiteName(data, true); int fileId = ValidationHelper.GetInteger(data.GetValue("FileID"), 0); string fileName = EnsureFileName(Path.GetFileName(ValidationHelper.GetString(data.GetValue("FilePath"), ""))); string folderPath = Path.GetDirectoryName(ValidationHelper.GetString(data.GetValue("FilePath"), "")); int libraryId = ValidationHelper.GetInteger(data.GetValue("FileLibraryID"), 0); AllowedExtensions = SettingsKeyInfoProvider.GetStringValue(siteName + ".CMSMediaFileAllowedExtensions"); // Initialize library info dfuElem.LibraryID = libraryId; dfuElem.MediaFileID = fileId; dfuElem.MediaFileName = fileName; dfuElem.LibraryFolderPath = folderPath; } // Initialize general info dfuElem.CheckPermissions = true; dfuElem.SourceType = MediaSourceEnum.MediaLibraries; dfuElem.ID = "dfuElemLib"; dfuElem.ForceLoad = true; dfuElem.DisplayInline = true; dfuElem.ControlGroup = "MediaView"; dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; dfuElem.ShowIconMode = true; dfuElem.InsertMode = false; dfuElem.ParentElemID = "LibraryUpdate"; dfuElem.IncludeNewItemInfo = true; dfuElem.RaiseOnClick = true; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.Width = 16; dfuElem.Height = 16; dfuElem.MaxNumberToUpload = 1; } }
/// <summary> /// Initializes attachment update control according current attachment data. /// </summary> /// <param name="dfuElem">Direct file uploader</param> /// <param name="data">Data container holding attachment data</param> private void GetAttachmentUpdateControl(ref DirectFileUploader dfuElem, IDataContainer data) { if (dfuElem != null) { string refreshType = CMSDialogHelper.GetMediaSource(SourceType); Guid formGuid = Guid.Empty; int documentId = ValidationHelper.GetInteger(data.GetValue("AttachmentDocumentID"), 0); // If attachment is related to the workflow 'AttachmentFormGUID' information isn't present if (data.ContainsColumn("AttachmentFormGUID")) { formGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentFormGUID"), Guid.Empty); } if (SourceType == MediaSourceEnum.MetaFile) { dfuElem.ObjectID = Config.MetaFileObjectID; dfuElem.ObjectType = Config.MetaFileObjectType; dfuElem.Category = Config.MetaFileCategory; dfuElem.SiteID = GetObjectSiteID(Config.MetaFileObjectType, Config.MetaFileObjectID); dfuElem.SourceType = MediaSourceEnum.MetaFile; dfuElem.MetaFileID = ValidationHelper.GetInteger(data.GetValue("MetaFileID"), 0); } else { dfuElem.SourceType = MediaSourceEnum.DocumentAttachments; dfuElem.FormGUID = formGuid; dfuElem.DocumentID = documentId; if (TreeNodeObj != null) { // if attachment node exists dfuElem.NodeParentNodeID = TreeNodeObj.NodeParentID; dfuElem.NodeClassName = TreeNodeObj.NodeClassName; } else { // if attachment node doesn't exist dfuElem.NodeParentNodeID = NodeParentID; dfuElem.NodeClassName = "cms.file"; } dfuElem.CheckPermissions = true; dfuElem.AttachmentGUID = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; } dfuElem.ParentElemID = refreshType; dfuElem.ID = "dfuElem"; dfuElem.ForceLoad = true; dfuElem.ControlGroup = "MediaView"; dfuElem.ShowIconMode = true; dfuElem.InsertMode = false; dfuElem.IncludeNewItemInfo = true; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.MaxNumberToUpload = 1; } }
/// <summary> /// UniGrid external data bound. /// </summary> protected object gridAttachments_OnExternalDataBound(object sender, string sourceName, object parameter) { DataRowView rowView = null; string attName = null; string attachmentExt = null; switch (sourceName.ToLowerCSafe()) { case "clone": ImageButton imgClone = sender as ImageButton; if (imgClone != null) { if (this.IsLiveSite) { // Hide cloning on live site imgClone.Visible = false; return(imgClone); } Guid attGuid = ValidationHelper.GetGuid(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentGUID"], Guid.Empty); string objectType = null; int id = 0; if (VersionHistoryID > 0) { objectType = PredefinedObjectType.ATTACHMENTHISTORY; } else { objectType = PredefinedObjectType.ATTACHMENT; } BaseInfo att = AttachmentHistoryInfoProvider.GetInfoByGuid(objectType, attGuid); if (att != null) { id = att.Generalized.ObjectID; } imgClone.PreRender += new EventHandler(imgClone_PreRender); imgClone.OnClientClick = "modalDialog('" + URLHelper.ResolveUrl("~/CMSModules/Objects/Dialogs/CloneObjectDialog.aspx?objectType=" + objectType + "&objectId=" + id) + "', 'CloneObject', 750, 400); return false;"; } break; case "update": Panel pnlBlock = new Panel { ID = "pnlBlock" }; bool isWebDAVEnabled = CMSContext.IsWebDAVEnabled(SiteName); bool isWindowsAuthentication = RequestHelper.IsWindowsAuthentication(); pnlBlock.Style.Add("margin", "0 auto"); pnlBlock.Width = ((isWebDAVEnabled && isWindowsAuthentication) ? 32 : 16); // Add disabled image ImageButton imgUpdate = new ImageButton { ID = "imgUpdate" }; imgUpdate.PreRender += imgUpdate_PreRender; pnlBlock.Controls.Add(imgUpdate); // Add update control // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; rowView = parameter as DataRowView; // Set uploader's properties if (dfuElem != null) { dfuElem.SourceType = MediaSourceEnum.DocumentAttachments; dfuElem.ID = "dfuElem" + DocumentID; dfuElem.IsLiveSite = IsLiveSite; dfuElem.EnableSilverlightUploader = false; dfuElem.ControlGroup = "update"; dfuElem.AttachmentGUID = GetAttachmentGuid(rowView); dfuElem.DisplayInline = true; dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.InnerLoadingDivHtml = " "; dfuElem.MaxNumberToUpload = 1; dfuElem.Height = 16; dfuElem.Width = 16; dfuElem.PreRender += dfuElem_PreRender; pnlBlock.Controls.Add(dfuElem); } attName = GetAttachmentName(rowView); attachmentExt = GetAttachmentExtension(rowView); int nodeGroupId = (Node != null) ? Node.GetIntegerValue("NodeGroupID") : 0; // Check if WebDAV allowed by the form bool allowWebDAV = (Form == null) || Form.AllowWebDAV; // Add WebDAV edit control if (allowWebDAV && isWebDAVEnabled && isWindowsAuthentication && (FormGUID == Guid.Empty) && WebDAVSettings.IsExtensionAllowedForEditMode(attachmentExt, SiteName)) { // Dynamically load control WebDAVEditControl webdavElem = Page.LoadUserControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl; // Set editor's properties if (webdavElem != null) { webdavElem.Enabled = Enabled; webdavElem.ID = "webdavElem" + DocumentID; // Ensure form identification if ((Form != null) && (Form.Parent != null)) { webdavElem.FormID = Form.Parent.ClientID; } webdavElem.SiteName = SiteName; webdavElem.FileName = attName; webdavElem.NodeAliasPath = Node.NodeAliasPath; webdavElem.NodeCultureCode = Node.DocumentCulture; webdavElem.PreRender += webdavElem_PreRender; if (FieldInfo != null) { webdavElem.AttachmentFieldName = FieldInfo.Name; } // Set Group ID for live site webdavElem.GroupID = IsLiveSite ? nodeGroupId : 0; webdavElem.IsLiveSite = IsLiveSite; // Align left if WebDAV is enabled and windows authentication is enabled bool isRTL = (IsLiveSite && CultureHelper.IsPreferredCultureRTL()) || (!IsLiveSite && CultureHelper.IsUICultureRTL()); pnlBlock.Style.Add("text-align", isRTL ? "right" : "left"); pnlBlock.Controls.Add(webdavElem); } } return(pnlBlock); case "edit": // Get file extension string extension = ValidationHelper.GetString(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentExtension"], string.Empty).ToLowerCSafe(); Guid guid = ValidationHelper.GetGuid(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentGUID"], Guid.Empty); ImageButton img = sender as ImageButton; if (img != null) { img.AlternateText = String.Format("{0}|{1}", extension, guid); img.PreRender += img_PreRender; } break; case "delete": ImageButton imgDelete = sender as ImageButton; if (imgDelete != null) { // Turn off validation imgDelete.CausesValidation = false; imgDelete.PreRender += imgDelete_PreRender; // Explicitly initialize confirmation imgDelete.OnClientClick = "if(DeleteConfirmation() == false){return false;}"; } break; case "moveup": ImageButton imgUp = sender as ImageButton; if (imgUp != null) { // Turn off validation imgUp.CausesValidation = false; imgUp.PreRender += imgUp_PreRender; } break; case "movedown": ImageButton imgDown = sender as ImageButton; if (imgDown != null) { // Turn off validation imgDown.CausesValidation = false; imgDown.PreRender += imgDown_PreRender; } break; case "attachmentname": { rowView = parameter as DataRowView; // Get attachment GUID Guid attachmentGuid = GetAttachmentGuid(rowView); // Get attachment extension attachmentExt = GetAttachmentExtension(rowView); bool isImage = ImageHelper.IsImage(attachmentExt); string iconUrl = GetFileIconUrl(attachmentExt, "List"); // Get link for attachment string attachmentUrl = null; attName = ValidationHelper.GetString(rowView["AttachmentName"], string.Empty); int documentId = DocumentID; if (Node != null) { if (IsLiveSite && (documentId > 0)) { attachmentUrl = CMSContext.ResolveUIUrl(TreePathUtils.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, CMSContext.CurrentSiteName), 0, null)); } else { attachmentUrl = CMSContext.ResolveUIUrl(TreePathUtils.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, CMSContext.CurrentSiteName), VersionHistoryID, null)); } } else { attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attachmentGuid, VersionHistoryID)); } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Ensure correct URL if (OriginalNodeSiteName != CMSContext.CurrentSiteName) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", OriginalNodeSiteName); } // Add latest version requirement for live site if (IsLiveSite && (documentId > 0)) { // Add requirement for latest version of files for current document string newparams = "latestfordocid=" + documentId; newparams += "&hash=" + ValidationHelper.GetHashString("d" + documentId); attachmentUrl += "&" + newparams; } // Optionally trim attachment name string attachmentName = TextHelper.LimitLength(attName, ATTACHMENT_NAME_LIMIT, "..."); // Tooltip string tooltip = null; if (ShowTooltip) { string title = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(rowView, "AttachmentTitle"), string.Empty); string description = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(rowView, "AttachmentDescription"), string.Empty); int imageWidth = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(rowView, "AttachmentImageWidth"), 0); int imageHeight = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(rowView, "AttachmentImageHeight"), 0); tooltip = UIHelper.GetTooltipAttributes(attachmentUrl, imageWidth, imageHeight, title, attachmentName, attachmentExt, description, null, 300); } // Icon string imageTag = String.Format("<img class=\"Icon\" src=\"{0}\" alt=\"{1}\" />", iconUrl, attachmentName); if (isImage) { return(String.Format("<a href=\"#\" onclick=\"javascript: window.open('{0}'); return false;\"><span id=\"{1}\" {2}>{3}{4}</span></a>", attachmentUrl, attachmentGuid, tooltip, imageTag, attachmentName)); } else { return(String.Format("<a href=\"{0}\"><span id=\"{1}\" {2}>{3}{4}</span></a>", attachmentUrl, attachmentGuid, tooltip, imageTag, attachmentName)); } } case "attachmentsize": long size = ValidationHelper.GetLong(parameter, 0); return(DataHelper.GetSizeString(size)); } return(parameter); }
/// <summary> /// UniGrid external data bound. /// </summary> protected object GridDocsOnExternalDataBound(object sender, string sourceName, object parameter) { string attName; string attachmentExt; DataRowView drv; switch (sourceName.ToLowerCSafe()) { case "update": { drv = parameter as DataRowView; PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateAction"; Panel pnlBlock = new Panel(); pnlBlock.ID = "pnlBlock"; plcUpd.Controls.Add(pnlBlock); // Add update control // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; // Set uploader's properties if (dfuElem != null) { dfuElem.ID = "dfuElem" + DocumentID; dfuElem.SourceType = MediaSourceEnum.Attachment; dfuElem.DisplayInline = true; if (!createTempAttachment) { dfuElem.AttachmentGUID = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty); } dfuElem.ForceLoad = true; dfuElem.FormGUID = FormGUID; dfuElem.AttachmentGUIDColumnName = GUIDColumnName; dfuElem.DocumentID = DocumentID; dfuElem.NodeParentNodeID = NodeParentNodeID; dfuElem.NodeClassName = NodeClassName; dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; dfuElem.ShowIconMode = true; dfuElem.InsertMode = false; dfuElem.ParentElemID = ClientID; dfuElem.IncludeNewItemInfo = true; dfuElem.CheckPermissions = CheckPermissions; dfuElem.NodeSiteName = SiteName; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.MaxNumberToUpload = 1; dfuElem.PreRender += dfuElem_PreRender; pnlBlock.Controls.Add(dfuElem); } int nodeGroupId = ((Node != null) && (Node.DocumentID > 0)) ? Node.GetValue("NodeGroupID", 0) : 0; bool displayGroupAdmin = true; // Check group admin for live site if (IsLiveSite && (nodeGroupId > 0)) { displayGroupAdmin = MembershipContext.AuthenticatedUser.IsGroupAdministrator(nodeGroupId); } // Check if external editing allowed by the form bool allowExt = (Form == null) || Form.AllowExternalEditing; if (allowExt && (FormGUID == Guid.Empty) && displayGroupAdmin) { var ctrl = ExternalEditHelper.LoadExternalEditControl(pnlBlock, FileTypeEnum.Attachment, SiteName, new DataRowContainer(drv), IsLiveSite, Node); if (ctrl != null) { ctrl.ID = "extEdit" + DocumentID; // Ensure form identification if ((Form != null) && (Form.Parent != null)) { ctrl.FormID = Form.Parent.ClientID; } ctrl.SiteName = SiteName; if (FieldInfo != null) { ctrl.AttachmentFieldName = FieldInfo.Name; } ctrl.PreRender += extEdit_PreRender; // Adjust the styles bool isRTL = (IsLiveSite && CultureHelper.IsPreferredCultureRTL()) || (!IsLiveSite && CultureHelper.IsUICultureRTL()); pnlBlock.Style.Add("text-align", isRTL ? "right" : "left"); } } return(plcUpd); } case "edit": { // Get file extension string extension = ValidationHelper.GetString(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentExtension"], string.Empty).ToLowerCSafe(); // Get attachment GUID attachmentGuid = ValidationHelper.GetGuid(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentGUID"], Guid.Empty); if (sender is CMSGridActionButton) { CMSGridActionButton img = (CMSGridActionButton)sender; if (createTempAttachment) { img.Visible = false; } else { img.ScreenReaderDescription = extension; img.ToolTip = attachmentGuid.ToString(); img.PreRender += img_PreRender; } } } break; case "delete": if (sender is CMSGridActionButton) { CMSGridActionButton imgDelete = (CMSGridActionButton)sender; // Turn off validation imgDelete.CausesValidation = false; imgDelete.PreRender += imgDelete_PreRender; } break; case "attachmentname": { drv = parameter as DataRowView; // Get attachment GUID attachmentGuid = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty); // Get attachment extension attachmentExt = ValidationHelper.GetString(drv["AttachmentExtension"], string.Empty); bool isImage = ImageHelper.IsImage(attachmentExt); bool isTemp = ValidationHelper.GetGuid(drv["AttachmentFormGUID"], Guid.Empty) != Guid.Empty; // Get link for attachment string attachmentUrl = null; attName = ValidationHelper.GetString(drv["AttachmentName"], string.Empty); int documentId = DocumentID; if (documentId > 0) { int versionHistoryId = IsLiveSite ? 0 : VersionHistoryID; attachmentUrl = AuthenticationHelper.ResolveUIUrl(AttachmentURLProvider.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, SiteContext.CurrentSiteName), null, versionHistoryId)); } else { attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attachmentGuid, 0)); } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Ensure correct URL for non-temporary attachments if ((OriginalNodeSiteName != SiteContext.CurrentSiteName) && !isTemp) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", OriginalNodeSiteName); } // Add latest version requirement for live site if (IsLiveSite && (documentId > 0)) { // Add requirement for latest version of files for current document string newparams = "latestfordocid=" + documentId; newparams += "&hash=" + ValidationHelper.GetHashString("d" + documentId); attachmentUrl += "&" + newparams; } // Optionally trim attachment name string attachmentName = TextHelper.LimitLength(attName, ATTACHMENT_NAME_LIMIT); // Tooltip string tooltip = null; if (ShowTooltip) { string title = ValidationHelper.GetString(drv["AttachmentTitle"], string.Empty); string description = ValidationHelper.GetString(drv["AttachmentDescription"], string.Empty); int imageWidth = ValidationHelper.GetInteger(drv["AttachmentImageWidth"], 0); int imageHeight = ValidationHelper.GetInteger(drv["AttachmentImageHeight"], 0); tooltip = UIHelper.GetTooltipAttributes(attachmentUrl, imageWidth, imageHeight, title, attachmentName, attachmentExt, description, null, 300); } // Icon string iconTag = UIHelper.GetFileIcon(Page, attachmentExt, tooltip: attachmentName); if (isImage) { return("<a href=\"#\" onclick=\"javascript: window.open('" + attachmentUrl + "'); return false;\" class=\"cms-icon-link\"><span " + tooltip + ">" + iconTag + attachmentName + "</span></a>"); } else { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "disposition", "attachment"); // NOTE: OnClick here is needed to avoid loader to show because even for download links, the pageUnload event is fired return(String.Format("<a href=\"{0}\" onclick=\"javascript: {5}\" class=\"cms-icon-link\"><span id=\"{1}\" {2}>{3}{4}</span></a>", attachmentUrl, attachmentGuid, tooltip, iconTag, attachmentName, ScriptHelper.GetDisableProgressScript())); } } case "attachmentsize": { long size = ValidationHelper.GetLong(parameter, 0); return(DataHelper.GetSizeString(size)); } } return(parameter); }
/// <summary> /// UniGrid external data bound. /// </summary> protected object GridOnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLower()) { case "update": PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateAction"; // Add disabled image ImageButton imgUpdate = new ImageButton(); imgUpdate.ID = "imgUpdate"; if (!this.Enabled || !this.EnableUpdate) { imgUpdate.ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/uploaddisabled.png", IsLiveSite)); imgUpdate.Style.Add("cursor", "default"); imgUpdate.Enabled = false; } else { imgUpdate.Visible = false; } plcUpd.Controls.Add(imgUpdate); // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; // Set uploader's properties if (dfuElem != null) { if (this.Enabled && this.EnableUpdate) { dfuElem.ID = "dfuElem" + this.LibraryID; dfuElem.DisplayInline = true; dfuElem.SourceType = MediaSourceEnum.MediaLibraries; dfuElem.MediaFileID = this.MediaFileID; dfuElem.LibraryID = this.LibraryID; dfuElem.LibraryFolderPath = this.LibraryFolderPath; dfuElem.ParentElemID = this.ClientID; dfuElem.IsMediaThumbnail = this.IsMediaThumbnail; dfuElem.ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/upload.png", IsLiveSite)); dfuElem.ImageHeight = 16; dfuElem.ImageWidth = 16; dfuElem.InsertMode = false; dfuElem.ForceLoad = true; dfuElem.IsLiveSite = IsLiveSite; // New settings added dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.Height = 16; dfuElem.Width = 16; dfuElem.MaxNumberToUpload = 1; } else { dfuElem.Visible = false; } plcUpd.Controls.Add(dfuElem); } return(plcUpd); case "edit": // Get file extension if ((this.FileInfo != null) && (this.LibraryInfo != null)) { ImageButton img = (ImageButton)sender; if (CMSContext.CurrentUser.IsAuthenticated()) { string fileExt = (this.IsMediaThumbnail ? previewExt : this.FileInfo.FileExtension); // If the file is not an image don't allow image editing if (!ImageHelper.IsSupportedByImageEditor(fileExt) || !this.Enabled) { // Disable edit icon in case that attachment is not an image img.ImageUrl = ResolveUrl(GetImageUrl("Design/editdisabled.png", IsLiveSite)); img.Enabled = false; img.Style.Add("cursor", "default"); } else { string query = string.Format("?refresh=1&siteid={0}&MediaFileGUID={1}{2}", LibraryInfo.LibrarySiteID, FileInfo.FileGUID, (IsMediaThumbnail ? "&isPreview=1" : "")); query = URLHelper.AddUrlParameter(query, "hash", QueryHelper.GetHash(query)); img.OnClientClick = "EditThumbnailImage('" + query + "'); return false;"; } img.AlternateText = GetString("general.edit"); } else { img.Visible = false; } } break; case "delete": ImageButton imgDelete = (ImageButton)sender; if (!this.Enabled) { // Disable delete icon in case that editing is not allowed imgDelete.ImageUrl = ResolveUrl(GetImageUrl("Design/deletedisabled.png", IsLiveSite)); imgDelete.Enabled = false; imgDelete.Style.Add("cursor", "default"); } else { // Turn off validation imgDelete.CausesValidation = false; // Explicitly initialize confirmation imgDelete.OnClientClick = "if (DeleteConfirmation() == false) { return false; }"; } break; case "filename": if ((this.LibraryInfo != null) && (this.FileInfo != null)) { string fileUrl = ""; string fileExt = ""; string fileName = ""; // Get file extension if (this.IsMediaThumbnail) { fileName = previewName; fileExt = previewExt; fileUrl = ResolveUrl("~/CMSPages/GetMediaFile.aspx?preview=1&fileguid=" + this.FileInfo.FileGUID.ToString()); } else { fileExt = this.FileInfo.FileExtension; fileName = this.FileInfo.FileName; fileUrl = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(this.FileInfo.FileGUID, this.FileInfo.FileName); } fileUrl = URLHelper.UpdateParameterInUrl(fileUrl, "chset", Guid.NewGuid().ToString()); string tooltip = null; string iconUrl = GetFileIconUrl(fileExt, "List"); bool isImage = ImageHelper.IsImage(fileExt); if (isImage) { tooltip = ""; if (File.Exists(previewPath)) { FileStream file = FileStream.New(previewPath, FileMode.Open, FileAccess.Read); System.Drawing.Image img = System.Drawing.Image.FromStream(file.SystemStream); file.Close(); if (img != null) { int[] imgDims = ImageHelper.EnsureImageDimensions(0, 0, 150, img.Width, img.Height); string setRTL = (CultureHelper.IsUICultureRTL() ? ", LEFT, true" : ""); tooltip = "onmouseout=\"UnTip()\" onmouseover=\"Tip('<div style=\\'width:" + imgDims[0] + "px; text-align:center;\\'><img src=\\'" + URLHelper.AddParameterToUrl(fileUrl, "maxsidesize", "150") + "\\' alt=\\'" + fileName + "\\' /></div>'" + setRTL + ")\""; // Dispose image img.Dispose(); } } } string imageTag = "<img class=\"Icon\" src=\"" + iconUrl + "\" alt=\"" + fileName + "\" />"; if (isImage) { return("<a href=\"#\" onclick=\"javascript: window.open('" + fileUrl + "'); return false;\"><span " + tooltip + ">" + imageTag + fileName + "</span></a>"); } else { return("<a href=\"" + fileUrl + "\">" + imageTag + fileName + "</a>"); } } return(""); case "filesize": return(DataHelper.GetSizeString(ValidationHelper.GetLong(parameter, 0))); } return(parameter); }
/// <summary> /// UniGrid external data bound. /// </summary> protected object GridOnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "update": PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateAction"; // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; // Set uploader's properties if (dfuElem != null) { dfuElem.ID = "dfuElem" + LibraryID; dfuElem.DisplayInline = true; dfuElem.SourceType = MediaSourceEnum.MediaLibraries; dfuElem.MediaFileID = MediaFileID; dfuElem.LibraryID = LibraryID; dfuElem.LibraryFolderPath = LibraryFolderPath; dfuElem.ParentElemID = ClientID; dfuElem.IsMediaThumbnail = IsMediaThumbnail; dfuElem.ShowIconMode = true; dfuElem.InsertMode = false; dfuElem.ForceLoad = true; dfuElem.IsLiveSite = IsLiveSite; // New settings added dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.Height = 16; dfuElem.Width = 16; dfuElem.MaxNumberToUpload = 1; if (Enabled && EnableUpdate) { dfuElem.Enabled = true; } else { dfuElem.Enabled = false; } plcUpd.Controls.Add(dfuElem); } return(plcUpd); case "edit": // Get file extension if ((FileInfo != null) && (LibraryInfo != null)) { var editButton = (CMSGridActionButton)sender; if (AuthenticationHelper.IsAuthenticated()) { string fileExt = (IsMediaThumbnail ? previewExt : FileInfo.FileExtension); // If the file is not an image don't allow image editing if (!ImageHelper.IsSupportedByImageEditor(fileExt) || !Enabled) { // Disable edit icon in case that attachment is not an image editButton.Enabled = false; } else { string query = string.Format("?refresh=1&siteid={0}&MediaFileGUID={1}{2}", LibraryInfo.LibrarySiteID, FileInfo.FileGUID, (IsMediaThumbnail ? "&isPreview=1" : "")); query = URLHelper.AddUrlParameter(query, "hash", QueryHelper.GetHash(query)); editButton.OnClientClick = "EditThumbnailImage('" + query + "'); return false;"; } editButton.ToolTip = GetString("general.edit"); } else { editButton.Visible = false; } } break; case "delete": var deleteButton = (CMSGridActionButton)sender; if (!Enabled) { // Disable delete icon in case that editing is not allowed deleteButton.Enabled = false; } break; case "filename": if ((LibraryInfo != null) && (FileInfo != null)) { string fileUrl = ""; string fileExt = ""; string fileName = ""; // Get file extension if (IsMediaThumbnail) { fileName = previewName; fileExt = previewExt; fileUrl = ResolveUrl("~/CMSPages/GetMediaFile.aspx?preview=1&fileguid=" + FileInfo.FileGUID); } else { fileExt = FileInfo.FileExtension; fileName = FileInfo.FileName; fileUrl = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(FileInfo.FileGUID, FileInfo.FileName); } fileUrl = URLHelper.UpdateParameterInUrl(fileUrl, "chset", Guid.NewGuid().ToString()); string tooltip = null; string iconTag = UIHelper.GetFileIcon(Page, fileExt, tooltip: fileName); bool isImage = ImageHelper.IsImage(fileExt); if (isImage) { tooltip = ""; if (File.Exists(previewPath)) { FileStream file = FileStream.New(previewPath, FileMode.Open, FileAccess.Read); Image img = Image.FromStream(file); file.Close(); if (img != null) { int[] imgDims = ImageHelper.EnsureImageDimensions(0, 0, 150, img.Width, img.Height); string setRTL = (CultureHelper.IsUICultureRTL() ? ", LEFT, true" : ""); tooltip = "onmouseout=\"UnTip()\" onmouseover=\"Tip('<div style=\\'width:" + imgDims[0] + "px; text-align:center;\\'><img src=\\'" + URLHelper.AddParameterToUrl(fileUrl, "maxsidesize", "150") + "\\' alt=\\'" + fileName + "\\' /></div>'" + setRTL + ")\""; // Dispose image img.Dispose(); } } } if (isImage) { return("<a href=\"#\" onclick=\"javascript: window.open('" + fileUrl + "'); return false;\" class=\"cms-icon-link\"><span " + tooltip + ">" + iconTag + fileName + "</span></a>"); } else { return("<a href=\"" + fileUrl + "\" class=\"cms-icon-link\">" + iconTag + fileName + "</a>"); } } return(""); case "filesize": return(DataHelper.GetSizeString(ValidationHelper.GetLong(parameter, 0))); } return(parameter); }
/// <summary> /// Initializes attachment update control according current attachment data. /// </summary> /// <param name="dfuElem">Direct file uploader</param> /// <param name="data">Data container holding attachment data</param> private void GetAttachmentUpdateControl(ref DirectFileUploader dfuElem, IDataContainer data) { if (dfuElem != null) { string refreshType = CMSDialogHelper.GetMediaSource(SourceType); Guid formGuid = Guid.Empty; int documentId = ValidationHelper.GetInteger(data.GetValue("AttachmentDocumentID"), 0); // If attachment is related to the workflow 'AttachmentFormGUID' information isn't present if (data.ContainsColumn("AttachmentFormGUID")) { formGuid = ValidationHelper.GetGuid(data.GetValue("AttachmentFormGUID"), Guid.Empty); } dfuElem.ID = "dfuElem"; dfuElem.SourceType = MediaSourceEnum.DocumentAttachments; dfuElem.ForceLoad = true; dfuElem.FormGUID = formGuid; dfuElem.DocumentID = documentId; dfuElem.EnableSilverlightUploader = false; if (TreeNodeObj != null) { // if attachment node exists dfuElem.NodeParentNodeID = TreeNodeObj.NodeParentID; dfuElem.NodeClassName = TreeNodeObj.NodeClassName; } else { // if attachment node doesn't exist dfuElem.NodeParentNodeID = NodeParentID; dfuElem.NodeClassName = "cms.file"; } dfuElem.CheckPermissions = true; dfuElem.ControlGroup = "MediaView"; dfuElem.AttachmentGUID = ValidationHelper.GetGuid(data.GetValue("AttachmentGUID"), Guid.Empty); dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; dfuElem.ImageUrl = ResolveUrl(GetImageUrl("Design/Controls/DirectUploader/upload.png")); dfuElem.LoadingImageUrl = GetImageUrl("Design/Preloaders/preload16.gif"); dfuElem.ImageHeight = 16; dfuElem.ImageWidth = 16; dfuElem.InsertMode = false; dfuElem.ParentElemID = refreshType; dfuElem.IncludeNewItemInfo = true; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.Width = 16; dfuElem.Height = 16; dfuElem.MaxNumberToUpload = 1; } }