object Control_OnExternalDataBound(object sender, string sourceName, object parameter) { DataRowView drv; GridViewRow gvr; switch (sourceName.ToLowerCSafe()) { case "edit": if (sender is CMSAccessibleButton) { CMSGridActionButton btnEdit = (CMSGridActionButton)sender; gvr = (GridViewRow)parameter; drv = (DataRowView)gvr.DataItem; int id = drv["ProfileID"].ToInteger(0); PageTemplateDeviceLayoutInfo layout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, id); // Replace object ID if (layout != null) { Regex reg = RegexHelper.GetRegex("&objectid=\\d+"); btnEdit.OnClientClick = reg.Replace(btnEdit.OnClientClick, "&objectid=" + layout.TemplateDeviceLayoutID); } } break; } return(parameter); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); var deviceProfileId = QueryHelper.GetInteger("deviceprofileid", 0); if (deviceProfileId == 0) { var deviceLayoutId = QueryHelper.GetInteger("devicelayoutid", 0); var deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(deviceLayoutId); if (deviceLayout != null) { deviceProfileId = deviceLayout.ProfileID; } } var deviceProfile = DeviceProfileInfoProvider.GetDeviceProfileInfo(deviceProfileId); if (deviceProfile != null) { deviceLayoutHeaderUrl = string.Format(deviceLayoutHeaderUrl, PageTemplateID, deviceProfileId); deviceLayoutContentUrl = string.Format(deviceLayoutContentUrl, PageTemplateID, deviceProfileId, deviceProfile.ProfileName); } var editOnlyCode = QueryHelper.GetBoolean("editonlycode", false); if (editOnlyCode) { deviceLayoutHeaderUrl = URLHelper.AddParameterToUrl(deviceLayoutHeaderUrl, "editonlycode", "1"); deviceLayoutContentUrl = URLHelper.AddParameterToUrl(deviceLayoutContentUrl, "dialogmode", "1"); deviceLayoutContentUrl = URLHelper.AddParameterToUrl(deviceLayoutContentUrl, "tabmode", "1"); } var deviceActions = QueryHelper.GetBoolean("deviceactions", true); deviceLayoutHeaderUrl = URLHelper.AddParameterToUrl(deviceLayoutHeaderUrl, "deviceactions", deviceActions ? "1" : "0"); deviceLayoutContentUrl = URLHelper.AddParameterToUrl(deviceLayoutContentUrl, "deviceactions", deviceActions ? "1" : "0"); // Include the AliasPath parameter to ensure path pre-selection in the preview control string aliasPath = QueryHelper.GetString("aliaspath", null); if (!string.IsNullOrEmpty(aliasPath)) { deviceLayoutHeaderUrl = URLHelper.AddParameterToUrl(deviceLayoutHeaderUrl, "aliaspath", aliasPath); deviceLayoutContentUrl = URLHelper.AddParameterToUrl(deviceLayoutContentUrl, "aliaspath", aliasPath); } string aliasPathParam = (string.IsNullOrEmpty(aliasPath) ? string.Empty : "&aliaspath=" + aliasPath); string script = @" function RefreshAfterDelete() { location.href = '" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/PageTemplates/PageTemplate_DeviceLayouts.aspx?templateid=" + PageTemplateID + aliasPathParam) + @"'; }"; ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "refreshGrid", script, true); }
public void LoadData() { if (node != null) { string layoutText = String.Empty; // get template info pti = PageTemplateInfoProvider.GetPageTemplateInfo(node.GetUsedPageTemplateId()); if ((pti == null) && (DocumentContext.CurrentPageInfo != null) && (DocumentContext.CurrentPageInfo.UsedPageTemplateInfo != null)) { pti = DocumentContext.CurrentPageInfo.UsedPageTemplateInfo; } if (pti != null) { PageTemplateLayoutTypeEnum type = PageTemplateLayoutTypeEnum.PageTemplateLayout; // Try get device layout object layoutObject = PageTemplateDeviceLayoutInfoProvider.GetLayoutObject(pti, DeviceContext.CurrentDeviceProfile, out type); layoutText = pti.PageTemplateLayout; // Set layout text with dependence on current layout type switch (type) { // Shared layouts case PageTemplateLayoutTypeEnum.SharedLayout: case PageTemplateLayoutTypeEnum.DeviceSharedLayout: case PageTemplateLayoutTypeEnum.SharedLayoutMapped: layoutText = (layoutObject as LayoutInfo).LayoutCode; break; // Custom device layout case PageTemplateLayoutTypeEnum.DeviceLayout: layoutText = (layoutObject as PageTemplateDeviceLayoutInfo).LayoutCode; break; } } ltlLayoutCode.Text = HTMLHelper.EnsureHtmlLineEndings(HTMLHelper.HighlightHTML(layoutText)); ltlLayoutCode.Text = RegexHelper.GetRegex("[ ](?![^<>]*>)").Replace(ltlLayoutCode.Text, " "); // Load node data if (!RequestHelper.IsPostBack()) { txtBodyCss.Text = node.NodeBodyElementAttributes; txtBodyScripts.Value = node.NodeBodyScripts; txtDocType.Text = node.NodeDocType; txtHeadTags.Value = node.NodeHeadTags; } } lblAfterDocType.Text = HighlightHTML("<html>") + "<br />" + AddSpaces(1) + HighlightHTML("<head>"); lblAfterHeadTags.Text = AddSpaces(1) + HighlightHTML("</head>"); lblAfterLayout.Text = AddSpaces(1) + HighlightHTML("</body>") + "<br />" + HighlightHTML("</html>"); lblBodyEnd.Text = HighlightHTML(">"); lblBodyStart.Text = AddSpaces(1) + HighlightHTML("<body " + HttpUtility.HtmlDecode(mBody)); }
protected override void OnInit(EventArgs e) { base.OnInit(e); // Hide all UIForms EditFormTemplate.Visible = false; EditFormTemplate.StopProcessing = true; EditFormDeviceLayout.Visible = false; EditFormDeviceLayout.StopProcessing = true; EditFormLayout.Visible = false; EditFormLayout.StopProcessing = true; sharedLayoutId = QueryHelper.GetInteger("newshared", 0); PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(TemplateID, DeviceProfileID); // Show UIForm for the current edited object type switch (EditedObjectType) { case EditedObjectTypeEnum.Template: EditFormTemplate.Visible = true; EditFormTemplate.StopProcessing = false; break; case EditedObjectTypeEnum.DeviceLayout: EditFormDeviceLayout.Visible = true; EditFormDeviceLayout.StopProcessing = false; break; case EditedObjectTypeEnum.Layout: EditFormLayout.Visible = true; EditFormLayout.StopProcessing = false; break; } if (AllowTypeSwitching && (EditedObjectType == EditedObjectTypeEnum.Layout)) { if (deviceLayout != null) { // Force ObjectManager to work with PageTemplateDeviceLayout even though the EditedObject is layout editMenuElem.ObjectManager.ObjectType = PageTemplateDeviceLayoutInfo.OBJECT_TYPE; editMenuElem.ObjectManager.ObjectID = deviceLayout.TemplateDeviceLayoutID; } else { // Force ObjectManager to work with PageTemplate even though the EditedObject is layout editMenuElem.ObjectManager.ObjectType = PageTemplateInfo.OBJECT_TYPE; editMenuElem.ObjectManager.ObjectID = TemplateID; } } pnlType.Visible = AllowTypeSwitching; requiresDialog = ((CMSDeskPage)Page).RequiresDialog; dialog = (QueryHelper.GetBoolean("dialog", false) || QueryHelper.GetBoolean("isindialog", false)); }
private void EditForm_OnBeforeSave(object sender, EventArgs e) { // Don't save shared layout object, update only necessary objects if ((EditedObjectType == EditedObjectTypeEnum.Layout) && radShared.Checked) { LayoutInfo li = EditedObject as LayoutInfo; // Get the current layout type PageTemplateLayoutTypeEnum layoutType = PageTemplateLayoutTypeEnum.PageTemplateLayout; PageTemplateDeviceLayoutInfoProvider.GetLayoutObject(PageTemplateInfo, DeviceProfileInfo, out layoutType); switch (layoutType) { case PageTemplateLayoutTypeEnum.PageTemplateLayout: case PageTemplateLayoutTypeEnum.SharedLayout: { int newLayoutId = ValidationHelper.GetInteger(drpLayout.Value, 0); // We need to save also page template if shared template is used if ((PageTemplateInfo != null) && (PageTemplateInfo.LayoutID != li.LayoutId)) { PageTemplateInfo.LayoutID = newLayoutId; PageTemplateInfo.Update(); } } 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; deviceLayout.Update(); } } break; } ShowChangesSaved(); // Prevent from saving object EditForm.StopProcessing = true; } }
/// <summary> /// Sets the visibility of actions according to checkout info /// </summary> private void SetActionVisiblity() { // Show "Create/Remove device layout" buttons if (allowDeviceButtons && (DialogMode || requiresDialog) && (DeviceProfileID > 0)) { PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(TemplateID, DeviceProfileID); if (deviceLayout != null) { removeDeviceLayout.Visible = true; } else { createDeviceLayout.Visible = true; } } }
/// <summary> /// Handles the ActionPerformed event of the HeaderActions control. /// </summary> protected void HeaderActions_ActionPerformed(object sender, CommandEventArgs e) { switch (e.CommandName.ToLowerCSafe()) { case "removelayout": // Remove custom device layout PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(TemplateID, DeviceProfileID); PageTemplateDeviceLayoutInfoProvider.DeleteTemplateDeviceLayoutInfo(deviceLayout); ShowConfirmation(GetString("devicelayout.removed")); // Refresh the current page string refreshUrl = URLHelper.AddParameterToUrl(RequestContext.RawURL, "refreshParent", "1"); URLHelper.Redirect(refreshUrl); break; } }
protected override void OnPreInit(EventArgs e) { deviceProfileId = QueryHelper.GetInteger("deviceprofileid", 0); var deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(PageTemplateID, deviceProfileId); // Check if the object exists - if not -> redirect and inform the user if (deviceLayout != null) { EditedObject = deviceLayout; } isDialog = QueryHelper.GetBoolean("editonlycode", false); if (isDialog) { MasterPageFile = "~/CMSMasterPages/UI/Dialogs/TabsHeader.master"; } base.OnPreInit(e); }
/// <summary> // Shows warning for not mapped device profiles /// </summary> private void SetDeviceWarning() { if (CurrentDeviceProfile != null) { PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(TemplateID, CurrentDeviceProfile.ProfileID); bool layoutIsMapped = (deviceLayout != null); // Check layout auto mapping if (!layoutIsMapped && (TemplateID > 0) && (PageTemplateInfo != null)) { layoutIsMapped |= (DeviceProfileLayoutInfoProvider.GetTargetLayoutInfo(CurrentDeviceProfile.ProfileID, PageTemplateInfo.LayoutID) != null); } // Device layout not defined if (!layoutIsMapped) { ShowWarning(GetString("devicelayout.notdefined")); } } }
/// <summary> /// Gets the title text. /// </summary> private string GetTitleInformation() { if (deviceProfile != null) { PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, deviceProfile.ProfileID); bool layoutIsMapped = (deviceLayout != null); // Check layout auto mapping if (!layoutIsMapped && (templateId > 0)) { layoutIsMapped |= (DeviceProfileLayoutInfoProvider.GetTargetLayoutInfo(deviceProfile.ProfileID, pti.LayoutID) != null); } if (!layoutIsMapped) { // Device layout not defined return(GetString("devicelayout.notdefined")); } } return(null); }
/// <summary> /// Devices the layouts grid_ on action. /// </summary> protected void deviceLayoutsGrid_OnAction(string actionName, object actionArgument) { // Check permissions bool isAuthorized = (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource(ModuleName.DESIGN, "Design")); switch (actionName) { case "delete": int deviceProfileId = ValidationHelper.GetInteger(actionArgument, 0); if (deviceProfileId > 0) { // Check permissions if (isAuthorized) { // Delete layout PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, deviceProfileId); PageTemplateDeviceLayoutInfoProvider.DeleteTemplateDeviceLayoutInfo(deviceLayout); } } break; } }
protected void deviceLayoutsGrid_OnAction(string actionName, object actionArgument) { switch (actionName) { case "delete": int deviceProfileId = ValidationHelper.GetInteger(actionArgument, 0); if (deviceProfileId > 0) { // Check permissions if (isAuthorised) { // Delete layout PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(PageTemplateID, deviceProfileId); PageTemplateDeviceLayoutInfoProvider.DeleteTemplateDeviceLayoutInfo(deviceLayout); } else { ShowError(GetString("general.actiondenied")); } } break; } }
/// <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()) { LayoutInfo li = EditedObject as LayoutInfo; if (radShared.Checked) { // Get the current layout type PageTemplateLayoutTypeEnum layoutType = PageTemplateLayoutTypeEnum.PageTemplateLayout; PageTemplateDeviceLayoutInfoProvider.GetLayoutObject(PageTemplateInfo, DeviceProfileInfo, out layoutType); switch (layoutType) { case PageTemplateLayoutTypeEnum.PageTemplateLayout: case PageTemplateLayoutTypeEnum.SharedLayout: { int newLayoutId = ValidationHelper.GetInteger(drpLayout.Value, 0); // We need to save also page template if shared template is used if ((PageTemplateInfo != null) && (PageTemplateInfo.LayoutID != li.LayoutId)) { PageTemplateInfo.LayoutID = newLayoutId; PageTemplateInfo.Update(); } } 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; deviceLayout.Update(); } } 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) 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 = RequestContext.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, EditForm.EditedObject.Generalized.ObjectDisplayName); } // No save for checkout if (e.ActionName != ComponentEvents.CHECKOUT) { ShowChangesSaved(); } }
protected override void OnPreRender(EventArgs e) { HandleFullScreen(); base.OnPreRender(e); if (AllowTypeSwitching && (EditedObject != null)) { if (sharedLayoutId > 0) { drpLayout.Value = sharedLayoutId; } else if (EditedObjectType == EditedObjectTypeEnum.Layout) { drpLayout.Value = EditedObject.Generalized.ObjectID; } radCustom.Text = GetString("TemplateLayout.Custom"); radCustom.Attributes.Add("onclick", "window.location = '" + URLHelper.AddParameterToUrl(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "newshared", "0"), "oldshared", drpLayout.Value.ToString()) + "'"); radShared.Text = GetString("TemplateLayout.Shared"); if (drpLayout.UniSelector.HasData) { radShared.Attributes.Add("onclick", "window.location = '" + URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "newshared", drpLayout.Value + "") + "'"); } // Get the current layout type bool radioButtonsEnabled = !SynchronizationHelper.UseCheckinCheckout; if (DeviceProfileID > 0) { // Device profile layout PageTemplateDeviceLayoutInfo dli = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(TemplateID, DeviceProfileID); if (dli != null) { radioButtonsEnabled |= dli.Generalized.IsCheckedOutByUser(MembershipContext.AuthenticatedUser); } } else { // Page template layout radioButtonsEnabled |= PageTemplateInfo.Generalized.IsCheckedOutByUser(MembershipContext.AuthenticatedUser); } // Disable also radio buttons when the object is not checked out radShared.Enabled = radCustom.Enabled = drpLayout.Enabled = radioButtonsEnabled; } if ((EditedObjectType == EditedObjectTypeEnum.Layout) && (AllowTypeSwitching || DialogMode)) { pnlServer.Visible = false; pnlLayout.CategoryTitleResourceString = null; } SetActionVisiblity(); RegisterInitScripts(pnlBody.ClientID, editMenuElem.MenuPanel.ClientID, startWithFullScreen); if (QueryHelper.GetBoolean("refreshParent", false)) { ScriptHelper.RegisterStartupScript(this, typeof(string), "refreshParent", "window.refreshPageOnClose = true;", true); } HandleWebpartZonesCountWarning(); if (DialogMode && QueryHelper.GetBoolean("wopenerrefresh", false) && !ValidationHelper.GetBoolean(hdnWOpenerRefreshed.Value, false)) { RegisterWOpenerRefreshScript(); hdnWOpenerRefreshed.Value = "1"; } var deviceActions = QueryHelper.GetBoolean("deviceactions", true); if (!deviceActions) { if (createDeviceLayout != null) { createDeviceLayout.Visible = false; } if (removeDeviceLayout != null) { removeDeviceLayout.Visible = false; } } // Try to get page template EditForm.EnableByLockState(); // Enable DDL and disable UIForm for shared layouts if (radShared.Checked) { if (codeElem != null) { codeElem.Enabled = false; cssEditor.Editor.Enabled = false; codeLayoutElem.Enabled = false; cssLayoutEditor.Editor.Enabled = false; deviceCode.Enabled = false; cssDeviceEditor.Editor.Enabled = false; } } else { drpLayout.Enabled = false; } // Check whether virtual objects are allowed if (!SettingsKeyInfoProvider.VirtualObjectsAllowed) { ShowWarning(GetString("VirtualPathProvider.NotRunning"), null, null); } }
/// <summary> /// Gets the edited object. /// </summary> private object GetEditedObject() { object editedObject = null; if (PageTemplate != null) { DeviceProfileInfo profileInfo = DeviceProfile; int newSharedLayoutId = QueryHelper.GetInteger("newshared", -1); int oldSharedLayoutId = QueryHelper.GetInteger("oldshared", -1); // Check modify shared templates permission if (PageTemplate.IsReusable && !MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement("CMS.Design", "Design.ModifySharedTemplates")) { RedirectToUIElementAccessDenied("CMS.Design", "Design.ModifySharedTemplates"); } // Default state - no radio buttons used if ((newSharedLayoutId == -1) && (oldSharedLayoutId == -1)) { editedObject = PageTemplateDeviceLayoutInfoProvider.GetLayoutObject(PageTemplate, profileInfo); } else { // If new shared layout is set, than it should be used as edited object // This happens when switched from custom to a shared layout if (newSharedLayoutId > 0) { // Standard page layout editedObject = LayoutInfoProvider.GetLayoutInfo(newSharedLayoutId); } else if (newSharedLayoutId == 0) { // This means user switched from shared layout to custom // Data has to be copied to PageTemplateInfo if (profileInfo != null) { // Get the current device layout if exists PageTemplateDeviceLayoutInfo deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(PageTemplate.PageTemplateId, profileInfo.ProfileID); if (deviceLayout != null) { // Custom device layout (use old layout) editedObject = PageTemplateDeviceLayoutInfoProvider.CloneInfoObject(deviceLayout, oldSharedLayoutId) as PageTemplateDeviceLayoutInfo; } } else { // We have to work with the clone, because we need to change the data of the object // (copy from shared layout) editedObject = PageTemplateDeviceLayoutInfoProvider.CloneInfoObject(PageTemplate, oldSharedLayoutId) as PageTemplateInfo; } } } } // Load the layout object else { var layoutId = QueryHelper.GetInteger("layoutid", 0); if (layoutId > 0) { editedObject = LayoutInfoProvider.GetLayoutInfo(layoutId); } } return(editedObject); }
/// <summary> /// Gets the edited object. /// </summary> /// <param name="templateId">The template id - if template/device layout is being edited</param> /// <param name="layoutId">The layout id - if shared layout is being edited</param> /// <param name="newSharedLayoutId">The new shared layout id - when changing shared layouts for template/device layouts</param> /// <param name="oldSharedLayoutId">The old shared layout id - when changing shared layouts for template/device layouts</param> /// <param name="deviceProfileId">The device profile id</param> private object GetEditedObject(int templateId, int layoutId, int newSharedLayoutId, int oldSharedLayoutId, int deviceProfileId) { object editedObject = null; if (templateId > 0) { PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId); DeviceProfileInfo profileInfo = DeviceProfileInfoProvider.GetDeviceProfileInfo(deviceProfileId); PageTemplateLayoutTypeEnum type = PageTemplateLayoutTypeEnum.PageTemplateLayout; // Standard page template layout if (pti != null) { // Check modify shared templates permission if (pti.IsReusable && !CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", "Design.ModifySharedTemplates")) { RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "Design.ModifySharedTemplates"); } // Default state - no radio buttons used if ((newSharedLayoutId == -1) && (oldSharedLayoutId == -1)) { editedObject = PageTemplateDeviceLayoutInfoProvider.GetLayoutObject(pti, profileInfo, out type); } else { // If new shared layout is set, than it should be used as edited object // This happens when switched from custom to a shared layout if (newSharedLayoutId > 0) { // Standard page layout editedObject = LayoutInfoProvider.GetLayoutInfo(newSharedLayoutId); } else if (newSharedLayoutId == 0) { // This means user switched from shared layout to custom // Data has to be copied to PageTemplateInfo PageTemplateDeviceLayoutInfo deviceLayout = null; if (deviceProfileId > 0) { // Get the current device layout if exists deviceLayout = PageTemplateDeviceLayoutInfoProvider.GetTemplateDeviceLayoutInfo(templateId, deviceProfileId); if (deviceLayout != null) { // Custom device layout (use old layout) editedObject = PageTemplateDeviceLayoutInfoProvider.CloneInfoObject(deviceLayout, oldSharedLayoutId) as PageTemplateDeviceLayoutInfo; } } else { // We have to work with the clone, because we need to change the data of the object // (copy from shared layout) editedObject = PageTemplateDeviceLayoutInfoProvider.CloneInfoObject(pti, oldSharedLayoutId) as PageTemplateInfo; } } } } } else { // Load the object if (layoutId > 0) { editedObject = LayoutInfoProvider.GetLayoutInfo(layoutId); } } return(editedObject); }
/// <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); } }