/// <summary> /// Handles UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of the action which should be performed</param> /// <param name="actionArgument">ID of the item the action should be performed with</param> protected void gridElem_OnAction(string actionName, object actionArgument) { if (!CheckPermissions("CMS.ContentPersonalization", PERMISSION_MODIFY)) { return; } int variantId = ValidationHelper.GetInteger(actionArgument, 0); if (variantId > 0) { string action = actionName.ToLowerCSafe(); switch (action) { case "delete": { // Get the instance in order to clear the cache ContentPersonalizationVariantInfo vi = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant(variantId); // Delete the object ContentPersonalizationVariantInfoProvider.DeleteContentPersonalizationVariant(variantId); RaiseOnAction(string.Empty, null); // Log widget variant synchronization if ((vi != null) && (vi.VariantDocumentID > 0)) { // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, tree); } } break; case "up": case "down": { // Get the instance in order to clear the cache ContentPersonalizationVariantInfo vi = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant(variantId); // Use try/catch due to license check try { if (action == "up") { // Move up ContentPersonalizationVariantInfoProvider.MoveVariantUp(variantId); } else { // Move down ContentPersonalizationVariantInfoProvider.MoveVariantDown(variantId); } // Reload the variants in the current cached pageInfo if ((Node != null) && (vi != null)) { // Get the PageInfo of the current document PageInfo pi = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, Node.NodeAliasPath, CMSContext.PreferredCultureCode, null, Node.NodeID, tree.CombineWithDefaultCulture); // Reload the zone/web part variants when moving up/down if ((pi != null) && (pi.UsedPageTemplateInfo != null) && (pi.UsedPageTemplateInfo.TemplateInstance != null)) { // Reload web part, widget variants if (vi.VariantInstanceGUID != Guid.Empty) { WebPartInstance webPartInstance = pi.UsedPageTemplateInfo.TemplateInstance.GetWebPart(vi.VariantInstanceGUID); if (webPartInstance != null) { webPartInstance.LoadVariants(true, VariantModeEnum.ContentPersonalization); } } // Reload zone variants else { WebPartZoneInstance zoneInstance = pi.UsedPageTemplateInfo.TemplateInstance.GetZone(vi.VariantZoneID); if (zoneInstance != null) { zoneInstance.LoadVariants(true, VariantModeEnum.ContentPersonalization); } } } RaiseOnAction(string.Empty, null); // Log widget variant synchronization if (vi.VariantDocumentID > 0) { // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, tree); } } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; } } break; } } }
/// <summary> /// Adds web part. /// </summary> private void AddWebPart() { int webpartID = ValidationHelper.GetInteger(WebpartId, 0); // Add web part to the currently selected zone under currently selected page if ((webpartID > 0) && !string.IsNullOrEmpty(ZoneId)) { // Get the web part by code name WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webpartID); if (wi != null) { // Ensure layout zone flag if (QueryHelper.GetBoolean("layoutzone", false)) { WebPartZoneInstance zone = pti.EnsureZone(ZoneId); zone.LayoutZone = true; } // Add the web part WebPartInstance newPart = null; if (ZoneVariantID == 0) { newPart = pti.AddWebPart(ZoneId, webpartID); } else { WebPartZoneInstance wpzi = templateInstance.EnsureZone(ZoneId); // Load the zone variants if not loaded yet if (wpzi.ZoneInstanceVariants == null) { wpzi.LoadVariants(); } // Find the correct zone variant wpzi = wpzi.ZoneInstanceVariants.Find(z => z.VariantID.Equals(ZoneVariantID)); if (wpzi != null) { newPart = wpzi.AddWebPart(webpartID); } } if (newPart != null) { // Prepare the form info to get the default properties FormInfo fi = null; if (wi.WebPartParentID > 0) { // Get from parent WebPartInfo parentWi = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID); if (parentWi != null) { fi = new FormInfo(parentWi.WebPartProperties); } } if (fi == null) { fi = new FormInfo(wi.WebPartProperties); } // Load the default values to the properties if (fi != null) { DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); newPart.LoadProperties(dr); } // Add webpart to user's last recently used CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWebPart(wi.WebPartName); // Add last selection date to webpart wi.WebPartLastSelection = DateTime.Now; WebPartInfoProvider.SetWebPartInfo(wi); webPartInstance = newPart; } } } }
/// <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); } }