Exemple #1
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Do not process control by default
        StopProcessing = true;

        // Keep frequent objects
        cui = MembershipContext.AuthenticatedUser;
        PageInfo pi = DocumentContext.CurrentPageInfo;

        if (pi == null)
        {
            IsPageNotFound = true;
            pi             = DocumentContext.CurrentCultureInvariantPageInfo ?? new PageInfo();
            checkChanges   = string.Empty;
        }

        ucUIToolbar.StopProcessing = true;

        // Get main UI element
        var element = UIElementInfoProvider.GetUIElementInfo(MODULE_NAME, ELEMENT_NAME);

        if (element == null)
        {
            return;
        }

        // Check whether user is authorized to edit page
        if ((pi != null) &&
            AuthenticationHelper.IsAuthenticated() &&
            cui.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName) &&
            ((IsPageNotFound && pi.NodeID == 0) || cui.IsAuthorizedPerTreeNode(pi.NodeID, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed) &&
            CMSPage.CheckUIElementAccessHierarchical(element, redirectToAccessDenied: false))
        {
            // Enable processing
            StopProcessing = false;

            // Check whether the preferred culture is RTL
            isRTL = CultureHelper.IsUICultureRTL();

            // Add link to CSS file
            CSSHelper.RegisterCSSLink(Page, "Design", "OnSiteEdit.css");
            CSSHelper.RegisterBootstrap(Page);

            // Filter UI element buttons
            ucUIToolbar.OnButtonFiltered += ucUIToolbar_OnButtonFiltered;
            ucUIToolbar.OnButtonCreated  += ucUIToolbar_OnButtonCreated;
            ucUIToolbar.OnGroupsCreated  += ucUIToolbar_OnGroupsCreated;
            ucUIToolbar.IsRTL             = isRTL;

            // Register edit script file
            RegisterEditScripts(pi);

            if (ViewMode.IsEditLive())
            {
                popupHandler.Visible           = true;
                IsLiveSite                     = false;
                MessagesPlaceHolder.IsLiveSite = false;
                MessagesPlaceHolder.Opacity    = 100;

                // Keep content of editable web parts when saving the document changes
                if (!IsPageNotFound)
                {
                    PortalManager.PreserveContent = true;
                }

                // Display warning in the Safe mode
                if (PortalHelper.SafeMode)
                {
                    string safeModeText        = GetString("onsiteedit.safemode") + "<br/><a href=\"" + RequestContext.RawURL.Replace("safemode=1", "safemode=0") + "\">" + GetString("general.close") + "</a> " + GetString("contentedit.safemode2");
                    string safeModeDescription = GetString("onsiteedit.safemode") + "<br/>" + GetString("general.seeeventlog");

                    // Display the warning message
                    ShowWarning(safeModeText, safeModeDescription, "");
                }

                ucUIToolbar.StopProcessing = false;

                // Ensure document redirection
                var redirectUrl = TreePathUtils.GetRedirectionUrl(pi);
                if (!String.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = URLHelper.ResolveUrl(redirectUrl);
                    ShowInformation(GetString("onsiteedit.redirectinfo") + " <a href=\"" + redirectUrl + "\">" + redirectUrl + "</a>");
                }

                pnlUpdateProgress.Visible = true;
            }
            // Mode menu on live site
            else if (ViewMode.IsLiveSite())
            {
                // Hide the edit panel, show only slider button
                pnlToolbarSpace.Visible = false;
                pnlToolbar.Visible      = false;
                pnlSlider.Visible       = true;

                icon.CssClass = "cms-icon-80 icon-edit";
                icon.ToolTip  = GetString("onsitedit.editmode");

                pnlButton.Attributes.Add("onclick", "OnSiteEdit_ChangeEditMode();");

                // Hide the OnSite edit button when displayed in CMSDesk
                pnlSlider.Style.Add("display", "none");
            }
        }
        // Hide control actions for unauthorized users
        else
        {
            plcEdit.Visible = false;
        }
    }