Esempio n. 1
0
    /// <summary>
    /// Updates parameters used by Edit button when displaying image editor.
    /// </summary>
    /// <param name="attachmentGuidString">GUID identifying attachment</param>
    private void UpdateEditParameters(string attachmentGuidString)
    {
        if (ShowTooltip)
        {
            // Try to get attachment GUID
            Guid attGuid = ValidationHelper.GetGuid(attachmentGuidString, Guid.Empty);
            if (attGuid != null)
            {
                // Get attachment
                AttachmentInfo attInfo = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attGuid, SiteName);
                if (attInfo != null)
                {
                    // Get attachment URL
                    string attachmentUrl = null;
                    if (Node != null)
                    {
                        attachmentUrl = CMSContext.ResolveUIUrl(TreePathUtils.GetAttachmentUrl(attGuid, URLHelper.GetSafeFileName(attInfo.AttachmentName, CMSContext.CurrentSiteName), VersionHistoryID, null));
                    }
                    else
                    {
                        attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attGuid, VersionHistoryID));
                    }
                    attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString());

                    // Ensure correct URL
                    if (OriginalNodeSiteName != CMSContext.CurrentSiteName)
                    {
                        attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", OriginalNodeSiteName);
                    }

                    // Generate new tooltip command
                    string newToolTip  = null;
                    string title       = attInfo.AttachmentTitle;
                    string description = attInfo.AttachmentDescription;
                    // Optionally trim attachment name
                    string attachmentName = TextHelper.LimitLength(attInfo.AttachmentName, ATTACHMENT_NAME_LIMIT, "...");
                    int    imageWidth     = attInfo.AttachmentImageWidth;
                    int    imageHeight    = attInfo.AttachmentImageHeight;
                    bool   isImage        = ImageHelper.IsImage(attInfo.AttachmentExtension);

                    int    tooltipWidth = 300;
                    string url          = isImage ? attachmentUrl : null;

                    string tooltipBody = UIHelper.GetTooltip(url, imageWidth, imageHeight, title, attachmentName, description, null, ref tooltipWidth);
                    if (!string.IsNullOrEmpty(tooltipBody))
                    {
                        newToolTip = String.Format("Tip('{0}', WIDTH, -300)", tooltipBody);
                    }

                    // Get update script
                    string updateScript = String.Format("$j(\"#{0}\").attr('onmouseover', '').unbind('mouseover').mouseover(function(){{ {1} }});", attGuid, newToolTip);

                    // Execute update
                    ScriptHelper.RegisterStartupScript(Page, typeof(Page), "AttachmentUpdateEdit", ScriptHelper.GetScript(updateScript));
                }
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Creates attachment string.
    /// </summary>
    private string CreateAttachment(IDataContainer dc, int versionId)
    {
        string result = null;

        if (dc != null)
        {
            // Get attachment GUID
            Guid attachmentGuid = ValidationHelper.GetGuid(dc.GetValue("AttachmentGUID"), Guid.Empty);

            // Get attachment extension
            string attachmentExt = ValidationHelper.GetString(dc.GetValue("AttachmentExtension"), null);
            string iconUrl       = GetFileIconUrl(attachmentExt, "List");

            // Get link for attachment
            string attachmentUrl = null;
            string attName       = ValidationHelper.GetString(dc.GetValue("AttachmentName"), null);
            attachmentUrl = CMSContext.ResolveUIUrl(TreePathUtils.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, CMSContext.CurrentSiteName), versionId, null));

            // Ensure correct URL
            attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", CMSContext.CurrentSiteName);

            // Optionally trim attachment name
            string attachmentName = TextHelper.LimitLength(attName, 90);
            bool   isImage        = ImageHelper.IsImage(attachmentExt);

            // Tooltip
            string tooltip = null;
            if (isImage)
            {
                int attachmentWidth = ValidationHelper.GetInteger(dc.GetValue("AttachmentImageWidth"), 0);
                if (attachmentWidth > 300)
                {
                    attachmentWidth = 300;
                }
                tooltip = "onmouseout=\"UnTip()\" onmouseover=\"TipImage(" + attachmentWidth + ", '" + URLHelper.AddParameterToUrl(attachmentUrl, "width", "300") + "', " + ScriptHelper.GetString(HTMLHelper.HTMLEncode(attachmentName)) + ")\"";
            }

            string attachmentSize = DataHelper.GetSizeString(ValidationHelper.GetLong(dc.GetValue("AttachmentSize"), 0));
            string title          = ValidationHelper.GetString(dc.GetValue("AttachmentTitle"), string.Empty);
            string description    = ValidationHelper.GetString(dc.GetValue("AttachmentDescription"), string.Empty);

            // Icon
            StringBuilder sb = new StringBuilder();
            sb.Append("<img class=\"Icon\" style=\"cursor: pointer;\"  src=\"", HTMLHelper.HTMLEncode(iconUrl), "\" alt=\"", HTMLHelper.HTMLEncode(attachmentName), "\" ", tooltip, " onclick=\"javascript: window.open(", ScriptHelper.GetString(attachmentUrl), "); return false;\" />");
            sb.Append(" ", HTMLHelper.HTMLEncode(attachmentName), " (", HTMLHelper.HTMLEncode(attachmentSize), ")<br />");
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"NoBorderTable\" ><tr><td style=\"padding:1px;\"><strong>", GetString("general.title"), ":</strong></td><td style=\"padding:1px;\">", HTMLHelper.HTMLEncode(title), "</td></tr>");
            sb.Append("<tr><td style=\"padding:1px;\"><strong>", GetString("general.description"), ":</strong></td><td style=\"padding:1px;\">", HTMLHelper.HTMLEncode(description), "</td></tr></table><br/>");
            result = sb.ToString();
        }

        return(result);
    }
Esempio n. 3
0
    private void CheckedChanged()
    {
        if (radSelect.Checked)
        {
            pnlSelect.Enabled   = true;
            pnlSelect.Visible   = true;
            ctrlProduct.Visible = false;
            pnlNew.Visible      = false;
        }
        else
        {
            pnlSelect.Enabled   = false;
            pnlSelect.Visible   = false;
            ctrlProduct.Visible = true;
            pnlNew.Visible      = true;

            // Set mappings
            TreeNode node = this.Node;
            if (node != null)
            {
                DataClassInfo dci = DataClassInfoProvider.GetDataClass(this.Node.NodeClassName);
                if (dci != null)
                {
                    // Get the mapped values
                    ctrlProduct.ProductName        = ValidationHelper.GetString(node.GetValue(Convert.ToString(dci.SKUMappings["SKUName"])), "");
                    ctrlProduct.ProductPrice       = ValidationHelper.GetDouble(node.GetValue(Convert.ToString(dci.SKUMappings["SKUPrice"])), 0);
                    ctrlProduct.ProductWeight      = ValidationHelper.GetDouble(node.GetValue(Convert.ToString(dci.SKUMappings["SKUWeight"])), 0);
                    ctrlProduct.ProductHeight      = ValidationHelper.GetDouble(node.GetValue(Convert.ToString(dci.SKUMappings["SKUHeight"])), 0);
                    ctrlProduct.ProductWidth       = ValidationHelper.GetDouble(node.GetValue(Convert.ToString(dci.SKUMappings["SKUWidth"])), 0);
                    ctrlProduct.ProductDepth       = ValidationHelper.GetDouble(node.GetValue(Convert.ToString(dci.SKUMappings["SKUDepth"])), 0);
                    ctrlProduct.ProductDescription = ValidationHelper.GetString(node.GetValue(Convert.ToString(dci.SKUMappings["SKUDescription"])), "");

                    Guid guid = ValidationHelper.GetGuid(node.GetValue(Convert.ToString(dci.SKUMappings["SKUImagePath"])), Guid.Empty);
                    ctrlProduct.ProductImagePath = ((guid != Guid.Empty) ? TreePathUtils.GetAttachmentUrl(guid, this.Node.NodeAlias) : "");
                }
            }

            // prefill form with values from the document
            ctrlProduct.SetValues();
        }
    }
    /// <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);
    }
Esempio n. 5
0
    /// <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 = "&nbsp;";
                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);
    }