/// <summary> /// Saves web part zone properties. /// </summary> public bool Save() { if (ZoneVariantID > 0) { // Check OnlineMarketing permissions if (!CheckPermissions("Manage")) { ShowInformation(GetString("general.modifynotallowed")); return false; } } // Save the data if (formElem.SaveData("")) { DataRow dr = formElem.DataRow; // Get basicform's datarow and update the fields if ((webPartZone != null) && (dr != null) && (pti != null)) { webPartZone.XMLVersion = 1; // New variant if (IsNewVariant) { webPartZone = pti.TemplateInstance.EnsureZone(webPartZone.ZoneID); // Ensure that all the zones which are not saved in the template already will be saved now // This is a case for new layout zones if (!webPartZone.HasVariants) { TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); CMSPortalManager.SaveTemplateChanges(pi, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } webPartZone = webPartZone.Clone(); string webPartControlId = string.Empty; // Re-generate web part unique IDs foreach (WebPartInstance wpi in webPartZone.WebParts) { bool webPartIdExists = false; int offset = 0; // Set new web part unique ID string baseId = Regex.Replace(wpi.ControlID, "\\d+$", ""); do { webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset); // Check if the returned web part control id is already used in the new zone variant webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null); offset++; } while (webPartIdExists); wpi.ControlID = webPartControlId; wpi.InstanceGUID = new Guid(); } } // If zone type changed, delete all webparts in the zone if (dr.Table.Columns.Contains("WidgetZoneType") && ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], "")) { webPartZone.RemoveAllWebParts(); } foreach (DataColumn column in dr.Table.Columns) { webPartZone.MacroTable[column.ColumnName.ToLowerCSafe()] = formElem.MacroTable[column.ColumnName.ToLowerCSafe()]; webPartZone.SetValue(column.ColumnName, dr[column]); } // Ensure the layout zone flag webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false); // Save standard zone if ((ZoneVariantID == 0) && (!IsNewVariant)) { // Update page template PageTemplateInfoProvider.SetPageTemplateInfo(pti); } else { // Save zone variant if ((webPartZone != null) && (webPartZone.ParentTemplateInstance != null) && (webPartZone.ParentTemplateInstance.ParentPageTemplate != null) && (!webPartZone.WebPartsContainVariants)) // Save only if any of the child web parts does not have variants { // Save the variant properties VariantSettings variant = new VariantSettings() { ID = ZoneVariantID, ZoneID = webPartZone.ZoneID, PageTemplateID = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId, }; // Get variant description properties Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variant.Name = ValidationHelper.GetString(properties["codename"], string.Empty); variant.DisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variant.Description = ValidationHelper.GetString(properties["description"], string.Empty); variant.Enabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (PortalContext.ContentPersonalizationEnabled) { variant.Condition = ValidationHelper.GetString(properties["condition"], string.Empty); } } mZoneVariantID = VariantHelper.SetVariant(variantMode, variant, webPartZone.GetXmlNode()); // The variants are cached -> Reload pti.TemplateInstance.LoadVariants(true, VariantModeEnum.None); } } // Reload the form (because of macro values set only by JS) formElem.LoadData(dr); ShowChangesSaved(); return true; } else { return false; } } else { return false; } }
/// <summary> /// Saves web part zone properties. /// </summary> public bool Save() { if (ZoneVariantID > 0) { // Check OnlineMarketing permissions if (!CheckPermissions("Manage")) { lblError.Visible = true; lblError.Text = GetString("general.modifynotallowed"); return(false); } } // Save the data if (formElem.SaveData("")) { DataRow dr = formElem.DataRow; // Get basicform's datarow and update the fields if ((webPartZone != null) && (dr != null) && (pti != null)) { // New variant // Clone original zone WebPartZoneInstance originalWebPartZone = webPartZone; if (IsNewVariant) { webPartZone = pti.EnsureZone(webPartZone.ZoneID); // Ensure that all the zones which are not saved in the template already will be saved now // This is a case for new layout zones if (!webPartZone.HasVariants) { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); CMSPortalManager.SaveTemplateChanges(pi, pti, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } webPartZone = webPartZone.Clone(); bool webPartIdExists = false; int offset = 0; string webPartControlId = string.Empty; // Re-generate web part unique IDs foreach (WebPartInstance wpi in webPartZone.WebParts) { webPartIdExists = false; offset = 0; // Set new web part unique ID string baseId = Regex.Replace(wpi.ControlID, "\\d+$", ""); do { webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset); // Check if the returned web part control id is already used in the new zone variant webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null); offset++; } while (webPartIdExists); wpi.ControlID = webPartControlId; wpi.InstanceGUID = new Guid(); } } // If zone type changed, delete all webparts in the zone if (ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], "")) { // Remove all variants if (variantMode == VariantModeEnum.MVT) { ModuleCommands.OnlineMarketingRemoveMVTWebPartVariants(webPartZone.WebParts); } else if (variantMode == VariantModeEnum.ContentPersonalization) { ModuleCommands.OnlineMarketingRemoveContentPersonalizationWebPartVariants(webPartZone.WebParts); } webPartZone.WebParts.Clear(); } foreach (DataColumn column in dr.Table.Columns) { webPartZone.MacroTable[column.ColumnName.ToLower()] = formElem.MacroTable[column.ColumnName.ToLower()]; webPartZone.SetValue(column.ColumnName, dr[column]); } // Ensure the layout zone flag webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false); // Save standard zone if ((ZoneVariantID == 0) && (!IsNewVariant)) { // Update page template PageTemplateInfoProvider.SetPageTemplateInfo(pti); } else { // Save zone variant if ((webPartZone != null) && (webPartZone.ParentTemplateInstance != null) && (webPartZone.ParentTemplateInstance.ParentPageTemplate != null) && (!webPartZone.WebPartsContainVariants)) // Save only if any of the child web parts does not have variants { // Save the variant properties string variantName = string.Empty; string variantDisplayName = string.Empty; string variantDisplayCondition = string.Empty; string variantDescription = string.Empty; bool variantEnabled = true; string zoneId = webPartZone.ZoneID; int templateId = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId; XmlDocument doc = new XmlDocument(); XmlNode xmlWebParts = webPartZone.GetXmlNode(doc); // Get variant description properties Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variantName = ValidationHelper.GetString(properties["codename"], string.Empty); variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variantDescription = ValidationHelper.GetString(properties["description"], string.Empty); variantEnabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (PortalContext.ContentPersonalizationEnabled) { variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty); } } if (variantMode == VariantModeEnum.MVT) { // Save MVT variant properties mZoneVariantID = ModuleCommands.OnlineMarketingSaveMVTVariant(ZoneVariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, Guid.Empty, templateId, 0, xmlWebParts); } else if (variantMode == VariantModeEnum.ContentPersonalization) { // Save Content personalization variant properties mZoneVariantID = ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(ZoneVariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, Guid.Empty, templateId, 0, xmlWebParts); } // The variants are cached -> Reload if (originalWebPartZone != null) { originalWebPartZone.LoadVariants(true, variantMode); } } } // Reload the form (because of macro values set only by JS) this.formElem.LoadData(dr); return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// Saves web part zone properties. /// </summary> public bool Save() { if (ZoneVariantID > 0) { // Check OnlineMarketing permissions if (!CheckPermissions("Manage")) { ShowInformation(GetString("general.modifynotallowed")); return(false); } } // Save the data if (formElem.SaveData("")) { DataRow dr = formElem.DataRow; // Get basicform's datarow and update the fields if ((webPartZone != null) && (dr != null) && (pti != null)) { webPartZone.XMLVersion = 1; // New variant if (IsNewVariant) { webPartZone = pti.TemplateInstance.EnsureZone(webPartZone.ZoneID); // Ensure that all the zones which are not saved in the template already will be saved now // This is a case for new layout zones if (!webPartZone.HasVariants) { TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); CMSPortalManager.SaveTemplateChanges(pi, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } webPartZone = webPartZone.Clone(); string webPartControlId = string.Empty; // Re-generate web part unique IDs foreach (WebPartInstance wpi in webPartZone.WebParts) { bool webPartIdExists = false; int offset = 0; // Set new web part unique ID string baseId = Regex.Replace(wpi.ControlID, "\\d+$", ""); do { webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset); // Check if the returned web part control id is already used in the new zone variant webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null); offset++; } while (webPartIdExists); wpi.ControlID = webPartControlId; wpi.InstanceGUID = new Guid(); } } // If zone type changed, delete all webparts in the zone if (dr.Table.Columns.Contains("WidgetZoneType") && ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], "")) { webPartZone.RemoveAllWebParts(); } foreach (DataColumn column in dr.Table.Columns) { webPartZone.MacroTable[column.ColumnName.ToLowerCSafe()] = formElem.MacroTable[column.ColumnName.ToLowerCSafe()]; webPartZone.SetValue(column.ColumnName, dr[column]); } // Ensure the layout zone flag webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false); // Save standard zone if ((ZoneVariantID == 0) && (!IsNewVariant)) { // Update page template PageTemplateInfoProvider.SetPageTemplateInfo(pti); } else { // Save zone variant if ((webPartZone != null) && (webPartZone.ParentTemplateInstance != null) && (webPartZone.ParentTemplateInstance.ParentPageTemplate != null) && (!webPartZone.WebPartsContainVariants)) // Save only if any of the child web parts does not have variants { // Save the variant properties VariantSettings variant = new VariantSettings() { ID = ZoneVariantID, ZoneID = webPartZone.ZoneID, PageTemplateID = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId, }; // Get variant description properties Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variant.Name = ValidationHelper.GetString(properties["codename"], string.Empty); variant.DisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variant.Description = ValidationHelper.GetString(properties["description"], string.Empty); variant.Enabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (PortalContext.ContentPersonalizationEnabled) { variant.Condition = ValidationHelper.GetString(properties["condition"], string.Empty); } } mZoneVariantID = VariantHelper.SetVariant(variantMode, variant, webPartZone.GetXmlNode()); // The variants are cached -> Reload pti.TemplateInstance.LoadVariants(true, VariantModeEnum.None); } } // Reload the form (because of macro values set only by JS) formElem.LoadData(dr); ShowChangesSaved(); return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// Saves web part zone properties. /// </summary> public bool Save() { if (ZoneVariantID > 0) { // Check OnlineMarketing permissions if (!CheckPermissions("Manage")) { lblError.Visible = true; lblError.Text = GetString("general.modifynotallowed"); return false; } } // Save the data if (formElem.SaveData("")) { DataRow dr = formElem.DataRow; // Get basicform's datarow and update the fields if ((webPartZone != null) && (dr != null) && (pti != null)) { // New variant // Clone original zone WebPartZoneInstance originalWebPartZone = webPartZone; if (IsNewVariant) { webPartZone = pti.EnsureZone(webPartZone.ZoneID); // Ensure that all the zones which are not saved in the template already will be saved now // This is a case for new layout zones if (!webPartZone.HasVariants) { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); CMSPortalManager.SaveTemplateChanges(pi, pti, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree); } webPartZone = webPartZone.Clone(); bool webPartIdExists = false; int offset = 0; string webPartControlId = string.Empty; // Re-generate web part unique IDs foreach (WebPartInstance wpi in webPartZone.WebParts) { webPartIdExists = false; offset = 0; // Set new web part unique ID string baseId = Regex.Replace(wpi.ControlID, "\\d+$", ""); do { webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset); // Check if the returned web part control id is already used in the new zone variant webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null); offset++; } while (webPartIdExists); wpi.ControlID = webPartControlId; wpi.InstanceGUID = new Guid(); } } // If zone type changed, delete all webparts in the zone if (ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], "")) { // Remove all variants if (variantMode == VariantModeEnum.MVT) { ModuleCommands.OnlineMarketingRemoveMVTWebPartVariants(webPartZone.WebParts); } else if (variantMode == VariantModeEnum.ContentPersonalization) { ModuleCommands.OnlineMarketingRemoveContentPersonalizationWebPartVariants(webPartZone.WebParts); } webPartZone.WebParts.Clear(); } foreach (DataColumn column in dr.Table.Columns) { webPartZone.MacroTable[column.ColumnName.ToLower()] = formElem.MacroTable[column.ColumnName.ToLower()]; webPartZone.SetValue(column.ColumnName, dr[column]); } // Ensure the layout zone flag webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false); // Save standard zone if ((ZoneVariantID == 0) && (!IsNewVariant)) { // Update page template PageTemplateInfoProvider.SetPageTemplateInfo(pti); } else { // Save zone variant if ((webPartZone != null) && (webPartZone.ParentTemplateInstance != null) && (webPartZone.ParentTemplateInstance.ParentPageTemplate != null) && (!webPartZone.WebPartsContainVariants)) // Save only if any of the child web parts does not have variants { // Save the variant properties string variantName = string.Empty; string variantDisplayName = string.Empty; string variantDisplayCondition = string.Empty; string variantDescription = string.Empty; bool variantEnabled = true; string zoneId = webPartZone.ZoneID; int templateId = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId; XmlDocument doc = new XmlDocument(); XmlNode xmlWebParts = webPartZone.GetXmlNode(doc); // Get variant description properties Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { variantName = ValidationHelper.GetString(properties["codename"], string.Empty); variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty); variantDescription = ValidationHelper.GetString(properties["description"], string.Empty); variantEnabled = ValidationHelper.GetBoolean(properties["enabled"], true); if (PortalContext.ContentPersonalizationEnabled) { variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty); } } if (variantMode == VariantModeEnum.MVT) { // Save MVT variant properties mZoneVariantID = ModuleCommands.OnlineMarketingSaveMVTVariant(ZoneVariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, Guid.Empty, templateId, 0, xmlWebParts); } else if (variantMode == VariantModeEnum.ContentPersonalization) { // Save Content personalization variant properties mZoneVariantID = ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(ZoneVariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, Guid.Empty, templateId, 0, xmlWebParts); } // The variants are cached -> Reload if (originalWebPartZone != null) { originalWebPartZone.LoadVariants(true, variantMode); } } } // Reload the form (because of macro values set only by JS) this.formElem.LoadData(dr); return true; } else { return false; } } else { return false; } }