/// <summary>
    /// External data binding handler.
    /// </summary>
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        // Prepare variables
        string      culture;
        DataRowView data;

        sourceName = sourceName.ToLowerCSafe();
        SiteInfo site;

        switch (sourceName)
        {
        // Edit button
        case EXTERNALSOURCE_EDIT:
            if (sender is CMSGridActionButton)
            {
                var editButton = (CMSGridActionButton)sender;
                data = UniGridFunctions.GetDataRowView(editButton.Parent as DataControlFieldCell);
                site = GetSiteFromRow(data);
                int nodeId = ValidationHelper.GetInteger(data[SOURCE_NODEID], 0);
                culture = ValidationHelper.GetString(data[SOURCE_DOCUMENTCULTURE], string.Empty);
                string type = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(data, SOURCE_TYPE), string.Empty);

                // Check permissions
                if ((site.Status != SiteStatusEnum.Running) || (!CMSPage.IsUserAuthorizedPerContent(site.SiteName) || ((ListingType == ListingTypeEnum.All) && (type == LISTINGTYPE_RECYCLEBIN))))
                {
                    editButton.Enabled = false;
                    editButton.Style.Add(HtmlTextWriterStyle.Cursor, "default");
                }
                else
                {
                    editButton.Attributes.Add("data-site-url", ResolveSiteUrl(site));
                    editButton.Attributes.Add("data-node-id", nodeId.ToString());
                    editButton.Attributes.Add("data-document-culture", culture);
                }

                editButton.OnClientClick = "return false";
                return(editButton);
            }
            return(sender);

        // Preview button
        case EXTERNALSOURCE_PREVIEW:
            if (sender is CMSGridActionButton)
            {
                var previewButton = (CMSGridActionButton)sender;
                data = UniGridFunctions.GetDataRowView(previewButton.Parent as DataControlFieldCell);
                site = GetSiteFromRow(data);
                string type = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(data, SOURCE_TYPE), string.Empty);
                if ((site.Status != SiteStatusEnum.Running) || ((ListingType == ListingTypeEnum.All) && (type == LISTINGTYPE_RECYCLEBIN)))
                {
                    previewButton.Enabled = false;
                    previewButton.Style.Add(HtmlTextWriterStyle.Cursor, "default");
                }
                else
                {
                    culture = ValidationHelper.GetString(data[SOURCE_DOCUMENTCULTURE], string.Empty);
                    var nodeID = ValidationHelper.GetInteger(data[SOURCE_NODEID], 0);

                    // Generate preview URL
                    var    query = QueryHelper.BuildQuery("viewmode", ((int)ViewModeEnum.Preview).ToString(), URLHelper.LanguageParameterName, culture);
                    string url   = DocumentURLProvider.GetPresentationUrlHandlerPath(culture, nodeID, query);

                    previewButton.Attributes.Add("data-preview-url", URLHelper.GetAbsoluteUrl(url, site.DomainName));
                }

                previewButton.OnClientClick = "return false";
                return(previewButton);
            }
            return(sender);

        // Document name column
        case EXTERNALSOURCE_DOCUMENTNAME:
            data = (DataRowView)parameter;

            string name      = ValidationHelper.GetString(data[SOURCE_DOCUMENTNAME], string.Empty);
            string className = ValidationHelper.GetString(data[SOURCE_CLASSNAME], string.Empty);

            if (name == string.Empty)
            {
                name = GetString("general.root");
            }
            // Add document type icon
            string result = string.Empty;
            switch (ListingType)
            {
            case ListingTypeEnum.DocTypeDocuments:
                break;

            default:
                var dataClass = DataClassInfoProvider.GetDataClassInfo(className);

                if (dataClass != null)
                {
                    var iconClass = (string)dataClass.GetValue(SOURCE_CLASSICONCLASS);
                    result = UIHelper.GetDocumentTypeIcon(Page, className, iconClass);
                }
                break;
            }

            result += "<span>" + HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50)) + "</span>";

            // Show document marks only if method is not called from grid export
            if ((sender != null) && (ListingType != ListingTypeEnum.All))
            {
                bool isLink = (data.Row.Table.Columns.Contains(SOURCE_NODELINKEDNODEID) && (data[SOURCE_NODELINKEDNODEID] != DBNull.Value));
                if (isLink)
                {
                    // Add link icon
                    result += DocumentUIHelper.GetDocumentMarkImage(Parent.Page, DocumentMarkEnum.Link);
                }
            }
            return(result);

        // Class name column
        case EXTERNALSOURCE_CLASSDISPLAYNAME:
            string displayName = ValidationHelper.GetString(parameter, string.Empty);
            if (sourceName.ToLowerCSafe() == EXTERNALSOURCE_CLASSDISPLAYNAMETOOLTIP)
            {
                displayName = TextHelper.LimitLength(displayName, 50);
            }
            if (displayName == string.Empty)
            {
                displayName = "-";
            }
            return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(displayName)));

        case EXTERNALSOURCE_DOCUMENTNAMETOOLTIP:
            data = (DataRowView)parameter;
            return(UniGridFunctions.DocumentNameTooltip(data));

        case EXTERNALSOURCE_STEPDISPLAYNAME:
            // Step display name
            int stepId = ValidationHelper.GetInteger(parameter, 0);
            if (stepId > 0)
            {
                return(new ObjectTransformation(WorkflowStepInfo.OBJECT_TYPE, stepId)
                {
                    Transformation = "{%stepdisplayname|(encode)%}"
                });
            }

            return("-");

        // Version column
        case EXTERNALSOURCE_VERSION:
            if (parameter == DBNull.Value)
            {
                parameter = "-";
            }
            parameter = HTMLHelper.HTMLEncode(parameter.ToString());
            return(parameter);

        // Document timestamp column
        case EXTERNALSOURCE_MODIFIEDWHEN:
        case EXTERNALSOURCE_MODIFIEDWHENTOOLTIP:
            if (String.IsNullOrEmpty(parameter.ToString()))
            {
                return(String.Empty);
            }

            if (currentSiteInfo == null)
            {
                currentSiteInfo = SiteContext.CurrentSite;
            }

            if (sourceName.EqualsCSafe(EXTERNALSOURCE_MODIFIEDWHEN, StringComparison.InvariantCultureIgnoreCase))
            {
                DateTime time = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
                return(TimeZoneHelper.ConvertToUserTimeZone(time, true, currentUserInfo, currentSiteInfo));
            }

            return(mGMTTooltip ?? (mGMTTooltip = TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo)));
        }

        return(parameter);
    }
Пример #2
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            CurrentUserInfo uinfo = CMSContext.CurrentUser;

            if (uinfo.IsGlobalAdministrator || !DisplayOnlyToGlobalAdministrator)
            {
                // Create new string builder for links
                StringBuilder sb = new StringBuilder();

                // Store current site name
                string curSiteName = CMSContext.CurrentSiteName;
                // Get default user name
                string queryStringKey  = (string.IsNullOrEmpty(DefaultUserName)) ? null : "?username="******"~/cmsdesk/default.aspx");
                    if (!string.IsNullOrEmpty(DefaultUserName))
                    {
                        url = URLHelper.AddParameterToUrl(url, "username", DefaultUserName);
                    }
                    if (CMSContext.CurrentPageInfo != null)
                    {
                        url = URLHelper.AddParameterToUrl(url, "nodeid", CMSContext.CurrentPageInfo.NodeID.ToString());
                    }
                    sb.AppendFormat(CMSDeskText, string.Concat("<a href=\"", URLHelper.EncodeQueryString(url), "\">", CMSDeskLinkText, "</a>"));

                    separatorNeeded = true;
                }

                // If site manager link is shown
                if (ShowCMSSiteManagerLink && (!CheckPermissions || uinfo.UserSiteManagerAdmin))
                {
                    // Check if separator needed
                    if (separatorNeeded)
                    {
                        sb.Append(Separator);
                    }

                    string url = ResolveUrl("~/cmssitemanager/default.aspx");
                    if (!string.IsNullOrEmpty(DefaultUserName))
                    {
                        url = URLHelper.AddParameterToUrl(url, "username", DefaultUserName);
                    }
                    sb.AppendFormat(CMSSiteManagerText, string.Concat("<a href=\"", url, "\">", CMSSiteManagerLinkText, "</a>"));

                    separatorNeeded = true;
                }

                // If edit document link is shown
                if (ShowEditDocumentLink && (!CheckPermissions || (uinfo.CheckEditor(curSiteName) && CMSPage.IsUserAuthorizedPerContent() && (uinfo.IsAuthorizedPerDocument(CMSContext.CurrentDocument, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed))))
                {
                    // Check if separator needed
                    if (separatorNeeded)
                    {
                        sb.Append(" " + Separator + " ");
                    }

                    string url = URLHelper.EncodeQueryString(UIHelper.GetDocumentEditUrl(CMSContext.CurrentDocument.NodeID, CMSContext.CurrentDocumentCulture.CultureCode));
                    if (PreferOnSiteEdit && PortalHelper.IsOnSiteEditingEnabled(CurrentSiteName))
                    {
                        url = URLHelper.ResolveUrl(PortalHelper.OnSiteEditRelativeURL);

                        string retUrl = URLHelper.CurrentURL;
                        // handle default alias path
                        if ((ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite) && (URLRewriter.CurrentPageInfoSource == PageInfoSource.DefaultAliasPath))
                        {
                            string aliasPath = PageInfoProvider.GetDefaultAliasPath(URLHelper.GetCurrentDomain(), CMSContext.CurrentSiteName);
                            if (!String.IsNullOrEmpty(aliasPath))
                            {
                                string query = URLHelper.GetQuery(retUrl);
                                retUrl = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(aliasPath));
                                retUrl = URLHelper.AppendQuery(retUrl, query);
                            }
                        }

                        url = URLHelper.UpdateParameterInUrl(url, "returnurl", HTMLHelper.HTMLEncode(HttpUtility.UrlEncode(retUrl)));
                    }

                    sb.AppendFormat(EditDocumentText, string.Concat("<a href=\"", url, "\">", EditDocumentLinkText, "</a>"));
                }

                ltlAdminActions.Text = sb.ToString();
            }
        }
    }
Пример #3
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            CurrentUserInfo uinfo = CMSContext.CurrentUser;

            if (uinfo.IsGlobalAdministrator || !DisplayOnlyToGlobalAdministrator)
            {
                // Create new string builder for links
                StringBuilder sb = new StringBuilder();

                // Store current site name
                string curSiteName = CMSContext.CurrentSiteName;
                // Get default user name
                string queryStringKey  = (string.IsNullOrEmpty(DefaultUserName)) ? null : "?username="******"~/cmsdesk/default.aspx");
                    if (!string.IsNullOrEmpty(DefaultUserName))
                    {
                        url = URLHelper.AddParameterToUrl(url, "username", DefaultUserName);
                    }
                    if (CMSContext.CurrentPageInfo != null)
                    {
                        url = URLHelper.AddParameterToUrl(url, "nodeid", CMSContext.CurrentPageInfo.NodeId.ToString());
                    }
                    sb.AppendFormat(CMSDeskText, string.Concat("<a href=\"", URLHelper.EncodeQueryString(url), "\">", CMSDeskLinkText, "</a>"));

                    separatorNeeded = true;
                }

                // If site manager link is shown
                if (ShowCMSSiteManagerLink && (!CheckPermissions || uinfo.UserSiteManagerAdmin))
                {
                    // Check if separator needed
                    if (separatorNeeded)
                    {
                        sb.Append(Separator);
                    }

                    string url = ResolveUrl("~/cmssitemanager/default.aspx");
                    if (!string.IsNullOrEmpty(DefaultUserName))
                    {
                        url = URLHelper.AddParameterToUrl(url, "username", DefaultUserName);
                    }
                    sb.AppendFormat(CMSSiteManagerText, string.Concat("<a href=\"", url, "\">", CMSSiteManagerLinkText, "</a>"));

                    separatorNeeded = true;
                }

                // If edit document link is shown
                if (ShowEditDocumentLink && (!CheckPermissions || (uinfo.CheckEditor(curSiteName) && CMSPage.IsUserAuthorizedPerContent() && (uinfo.IsAuthorizedPerDocument(CMSContext.CurrentDocument, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed))))
                {
                    // Check if separator needed
                    if (separatorNeeded)
                    {
                        sb.Append(" " + Separator + " ");
                    }

                    sb.AppendFormat(EditDocumentText, string.Concat("<a href=\"", URLHelper.EncodeQueryString(UIHelper.GetDocumentEditUrl(CMSContext.CurrentDocument.NodeID, CMSContext.CurrentDocumentCulture.CultureCode)), "\">", EditDocumentLinkText, "</a>"));
                }

                ltlAdminActions.Text = sb.ToString();
            }
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            bool     show   = true;
            TreeNode curDoc = DocumentContext.CurrentDocument;

            // Check if permissions should be checked
            if (ShowOnlyWhenAuthorized)
            {
                // Check permissions
                if (!((MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName)) && CMSPage.IsUserAuthorizedPerContent() && (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(curDoc, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed)))
                {
                    show    = false;
                    Visible = false;
                }
            }

            if (show)
            {
                // Create edit link
                StringBuilder sb = new StringBuilder("<a class=\"EditDocumentLink\" href=\"");
                // On-Site edit
                if (PreferOnSiteEdit && PortalHelper.IsOnSiteEditingEnabled(CurrentSiteName))
                {
                    string onsiteEditUrl = UrlResolver.ResolveUrl(PortalHelper.OnSiteEditRelativeURL);

                    string retUrl = RequestContext.CurrentURL;
                    // handle default alias path
                    if ((ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite) && (URLRewritingContext.CurrentPageInfoSource == PageInfoSource.DefaultAliasPath))
                    {
                        string aliasPath = PageInfoProvider.GetDefaultAliasPath(RequestContext.CurrentDomain, SiteContext.CurrentSiteName);
                        if (!String.IsNullOrEmpty(aliasPath))
                        {
                            string query = URLHelper.GetQuery(retUrl);
                            retUrl = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(aliasPath));
                            retUrl = URLHelper.AppendQuery(retUrl, query);
                        }
                    }

                    onsiteEditUrl = URLHelper.UpdateParameterInUrl(onsiteEditUrl, "editurl", HttpUtility.UrlEncode(retUrl));
                    sb.Append(HTMLHelper.EncodeForHtmlAttribute(onsiteEditUrl));
                }
                // Administration edit
                else
                {
                    sb.Append("~/Admin/cmsadministration.aspx?action=edit&amp;nodeid=");
                    sb.Append(curDoc.NodeID);
                    sb.Append("&amp;culture=");
                    sb.Append(curDoc.DocumentCulture);
                    sb.Append(ApplicationUrlHelper.GetApplicationHash("cms.content", "content"));
                }
                sb.Append("\">");
                // Text link
                if (String.IsNullOrEmpty(ImageURL))
                {
                    sb.Append(LinkText);
                }
                // Image link
                else
                {
                    sb.Append("<img src=\"");
                    sb.Append(UrlResolver.ResolveUrl(ImageURL));
                    sb.Append("\" alt=\"");
                    sb.Append(HTMLHelper.HTMLEncode(LinkText));
                    sb.Append("\" title=\"");
                    sb.Append(HTMLHelper.HTMLEncode(LinkText));
                    sb.Append("\" />");
                }
                sb.Append("</a>");
                ltlEditLink.Text = sb.ToString();
            }
        }
    }
Пример #5
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!this.StopProcessing)
        {
            bool     show   = true;
            TreeNode curDoc = CMSContext.CurrentDocument;

            // Check if permissions should be checked
            if (ShowOnlyWhenAuthorized)
            {
                // Check permissions
                if (!((CMSContext.CurrentUser.IsEditor || CMSContext.CurrentUser.IsGlobalAdministrator) && CMSPage.IsUserAuthorizedPerContent() && (CMSContext.CurrentUser.IsAuthorizedPerDocument(curDoc, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed)))
                {
                    show    = false;
                    Visible = false;
                }
            }

            if (show)
            {
                // Create edit link
                StringBuilder sb = new StringBuilder("<a href=\"~/cmsdesk/default.aspx?section=content&amp;action=edit&amp;nodeid=");
                sb.Append(curDoc.NodeID);
                sb.Append("&amp;culture=");
                sb.Append(curDoc.DocumentCulture);
                sb.Append("\">");
                sb.Append(LinkText);
                sb.Append("</a>");
                ltlEditLink.Text = sb.ToString();
            }
        }
    }