/// <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); }