/// <summary>
    /// Save button is clicked.
    /// </summary>
    protected void SaveAction(object sender, EventArgs e)
    {
        // Check permissions
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement("CMS.Design", "Design.EditLayout"))
        {
            RedirectToUIElementAccessDenied("CMS.Design", "Design.EditLayout");
        }

        // New device profile
        int newDeviceProfileId = deviceProfileId;

        if (newDeviceProfileId == 0)
        {
            newDeviceProfileId = ValidationHelper.GetInteger(ucNewDeviceProfile.Value, 0);
        }

        if (newDeviceProfileId == 0)
        {
            // Show error - select device profile first
            ShowError(GetString("devicelayout.selectdeviceprofile.error"));
            rbtnDevice.Checked = true;
            return;
        }

        PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);

        if ((pti != null) && (newDeviceProfileId > 0))
        {
            string         layoutCode = null;
            string         layoutCSS  = null;
            int            layoutId   = 0;
            LayoutTypeEnum layoutType = LayoutTypeEnum.Ascx;

            if (rbtnDevice.Checked)
            {
                // Copy from device
                int selectedDeviceProfileId = ValidationHelper.GetInteger(ucDeviceProfile.Value, 0);
                if (selectedDeviceProfileId > 0)
                {
                    // Existing device profile
                    PageTemplateDeviceLayoutInfo selectedDeviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, selectedDeviceProfileId);
                    if (selectedDeviceLayout != null)
                    {
                        layoutId   = selectedDeviceLayout.LayoutID;
                        layoutCode = selectedDeviceLayout.LayoutCode;
                        layoutCSS  = selectedDeviceLayout.LayoutCSS;
                        layoutType = selectedDeviceLayout.LayoutType;
                    }
                }
                else
                {
                    // Default device
                    layoutType = pti.PageTemplateLayoutType;

                    if (pti.LayoutID > 0)
                    {
                        layoutId = pti.LayoutID;
                    }
                    else
                    {
                        layoutCode = pti.PageTemplateLayout;
                        layoutCSS  = pti.PageTemplateCSS;
                    }
                }
            }
            else if (rbtnLayout.Checked)
            {
                // Use existing layout
                int        selectedLayoutId = ValidationHelper.GetInteger(ucLayout.Value, 0);
                LayoutInfo selectedLayout   = LayoutInfoProvider.GetLayoutInfo(selectedLayoutId);
                if (selectedLayout != null)
                {
                    layoutType = selectedLayout.LayoutType;

                    if (chkCopy.Checked)
                    {
                        // Copy layout code
                        layoutCode = selectedLayout.LayoutCode;
                        layoutCSS  = selectedLayout.LayoutCSS;
                    }
                    else
                    {
                        // Copy layout id
                        layoutId = selectedLayoutId;
                    }
                }
            }
            else if (rbtnEmptyLayout.Checked)
            {
                layoutCode = "<cms:CMSWebPartZone ZoneID=\"zoneA\" runat=\"server\" />";
            }

            PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, newDeviceProfileId);

            if (deviceLayout == null)
            {
                // Create a new device profile layout object
                deviceLayout = new PageTemplateDeviceLayoutInfo();
                deviceLayout.PageTemplateID = templateId;
                deviceLayout.ProfileID      = newDeviceProfileId;
            }

            // Modify the device profile layout object with updated values
            deviceLayout.LayoutID   = layoutId;
            deviceLayout.LayoutType = layoutType;
            deviceLayout.LayoutCode = layoutCode;
            deviceLayout.LayoutCSS  = layoutCSS;

            // Save the device profile layout object
            PageTemplateDeviceLayoutInfoProvider.SetTemplateDeviceLayoutInfo(deviceLayout);
            UIContext.EditedObject = deviceLayout;
            CMSObjectManager.CheckOutNewObject(Page);

            // Register refresh page scripts
            ScriptHelper.RegisterStartupScript(this, typeof(string), "deviceLayoutSaved", "if (wopener) { wopener.location.replace(wopener.location); } CloseDialog();", true);
        }
    }
Exemple #2
0
    /// <summary>
    /// Handles the OnAfterAction event of the ObjectManager control.
    /// </summary>
    protected void ObjectManager_OnAfterAction(object sender, SimpleObjectManagerEventArgs e)
    {
        if ((e.ActionName == ComponentEvents.SAVE) || (e.ActionName == ComponentEvents.CHECKIN))
        {
            if (EditForm.ValidateData())
            {
                if (radShared.Checked)
                {
                    // Get the current layout type
                    PageTemplateLayoutTypeEnum layoutType = PageTemplateLayoutTypeEnum.PageTemplateLayout;
                    PageTemplateDeviceLayoutInfoProvider.GetLayoutObject(PageTemplateInfo, DeviceProfileInfo, out layoutType);

                    switch (layoutType)
                    {
                    case PageTemplateLayoutTypeEnum.PageTemplateLayout:
                    {
                        // We need to save also page template if shared template is used
                        if (PageTemplateInfo != null)
                        {
                            PageTemplateInfo.LayoutID = ValidationHelper.GetInteger(drpLayout.Value, 0);
                            PageTemplateInfoProvider.SetPageTemplateInfo(PageTemplateInfo);
                        }
                    }
                    break;

                    case PageTemplateLayoutTypeEnum.DeviceSharedLayout:
                    case PageTemplateLayoutTypeEnum.DeviceLayout:
                    {
                        // We need to save also template device layout if shared template is used
                        PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(TemplateID, DeviceProfileID);
                        if (deviceLayout != null)
                        {
                            deviceLayout.LayoutID   = ValidationHelper.GetInteger(drpLayout.Value, 0);
                            deviceLayout.LayoutCode = null;
                            deviceLayout.LayoutCSS  = null;
                            PageTemplateDeviceLayoutInfoProvider.SetTemplateDeviceLayoutInfo(deviceLayout);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }

                // Register refresh script
                string refreshScript = ScriptHelper.GetScript("if ((wopener != null) && (wopener.RefreshPage != null)) {wopener.RefreshPage();}");
                ScriptHelper.RegisterClientScriptBlock(Page, typeof(String), "pageTemplateRefreshScript", refreshScript);

                // Register preview refresh
                RegisterRefreshScript();

                // Close if required
                if (ValidationHelper.GetBoolean(hdnClose.Value, false))
                {
                    ScriptHelper.RegisterStartupScript(Page, typeof(string), "CloseDialogPreviewScript", ScriptHelper.GetScript("CloseDialog();"));
                }

                // Load actual layout info (it was edited during saving by LayoutInfoProvider)
                LayoutInfo li = EditedObject as LayoutInfo;
                if (li != null)
                {
                    actualLayoutInfo = LayoutInfoProvider.GetLayoutInfo(li.LayoutId);
                }
            }

            // Hide warning after save
            MessagesPlaceHolder.WarningText = "";
        }
        else if (e.ActionName == ComponentEvents.UNDO_CHECKOUT)
        {
            if (AllowTypeSwitching)
            {
                var url = URLHelper.CurrentURL;
                url = URLHelper.RemoveParameterFromUrl(url, "newshared");
                url = URLHelper.RemoveParameterFromUrl(url, "oldshared");
                url = URLHelper.AddParameterToUrl(url, "wopenerrefresh", "1");
                Response.Redirect(url);
            }
        }
        else if (e.ActionName == ComponentEvents.CHECKOUT)
        {
            DisplayMessage(true);
        }

        switch (e.ActionName)
        {
        case ComponentEvents.SAVE:
        case ComponentEvents.CHECKOUT:
        case ComponentEvents.CHECKIN:
        case ComponentEvents.UNDO_CHECKOUT:
            if (DialogMode)
            {
                RegisterWOpenerRefreshScript();
            }
            else if (dialog)
            {
                ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "parentWOpenerRefresh", ScriptHelper.GetScript("if (parent && parent.wopener && parent.wopener.refresh) { parent.wopener.refresh(); }"));
            }
            break;
        }

        if (!AllowTypeSwitching && (EditedObjectType == EditedObjectTypeEnum.Layout) && (e.ActionName != ComponentEvents.CHECKOUT) && !DialogMode)
        {
            ScriptHelper.RefreshTabHeader(Page, null);
        }
    }