/// <summary> /// Changes the IDs of the editable content. /// </summary> /// <param name="oldId">Old web part ID</param> /// <param name="newId">New web part ID</param> private void ChangeEditableContentIDs(string oldId, string newId) { string currentContent = pi.EditableWebParts[oldId]; if (currentContent != null) { TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, tree); // Move the content in the page info pi.EditableWebParts[oldId] = null; pi.EditableWebParts[newId] = currentContent; // Update the document node.SetValue("DocumentContent", pi.GetContentXml()); DocumentHelper.UpdateDocument(node, tree); } }
/// <summary> /// Saves the given DataRow data to the web part properties. /// </summary> /// <param name="form">Form to save</param> /// <param name="pti">Page template instance</param> private void SaveFormToWidget(BasicForm form, PageTemplateInstance pti) { if (form.Visible && (widgetInstance != null)) { // Keep the old ID to check the change of the ID string oldId = widgetInstance.ControlID.ToLowerCSafe(); DataRow dr = form.DataRow; // Load default values for new widget if (IsNewWidget) { form.FormInformation.LoadDefaultValues(dr, wi.WidgetDefaultValues); } foreach (DataColumn column in dr.Table.Columns) { widgetInstance.MacroTable[column.ColumnName.ToLowerCSafe()] = form.MacroTable[column.ColumnName.ToLowerCSafe()]; widgetInstance.SetValue(column.ColumnName, dr[column]); // If name changed, move the content if (CMSString.Compare(column.ColumnName, "widgetcontrolid", true) == 0) { try { string newId = ValidationHelper.GetString(dr[column], "").ToLowerCSafe(); // Name changed if (!String.IsNullOrEmpty(newId) && (CMSString.Compare(newId, oldId, false) != 0)) { mWidgetIdChanged = true; WidgetId = newId; // Move the document content if present string currentContent = pi.EditableWebParts[oldId]; if (currentContent != null) { TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, tree); // Move the content in the page info pi.EditableWebParts[oldId] = null; pi.EditableWebParts[newId] = currentContent; // Update the document node.SetValue("DocumentContent", pi.GetContentXml()); DocumentHelper.UpdateDocument(node, tree); } // Change the underlying zone names if layout web part if ((wpi != null) && ((WebPartTypeEnum)wpi.WebPartType == WebPartTypeEnum.Layout)) { string prefix = oldId + "_"; foreach (WebPartZoneInstance zone in pti.WebPartZones) { if (zone.ZoneID.StartsWithCSafe(prefix, true)) { // Change the zone prefix to the new one zone.ZoneID = String.Format("{0}_{1}", newId, zone.ZoneID.Substring(prefix.Length)); } } } } } catch (Exception ex) { EventLogProvider ev = new EventLogProvider(); ev.LogEvent("Content", "CHANGEWIDGET", ex); } } } } }
/// <summary> /// Saves the given DataRow data to the web part properties. /// </summary> /// <param name="form">Form to save</param> private void SaveFormToWebPart(BasicForm form) { if (form.Visible && (webPartInstance != null)) { // Keep the old ID to check the change of the ID string oldId = webPartInstance.ControlID.ToLowerCSafe(); DataRow dr = form.DataRow; foreach (DataColumn column in dr.Table.Columns) { webPartInstance.MacroTable[column.ColumnName.ToLowerCSafe()] = form.MacroTable[column.ColumnName.ToLowerCSafe()]; webPartInstance.SetValue(column.ColumnName, dr[column]); // If name changed, move the content if (column.ColumnName.ToLowerCSafe() == "webpartcontrolid") { try { string newId = null; if (!IsNewVariant) { newId = ValidationHelper.GetString(dr[column], "").ToLowerCSafe(); } // Name changed if ((!string.IsNullOrEmpty(newId)) && (newId != oldId)) { if (!IsNewWebPart && !IsNewVariant) { mWebPartIdChanged = true; } WebpartId = newId; // Move the document content if present string currentContent = (string)(pi.EditableWebParts[oldId]); if (currentContent != null) { TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, tree); // Move the content in the page info pi.EditableWebParts[oldId] = null; pi.EditableWebParts[newId] = currentContent; // Update the document node.SetValue("DocumentContent", pi.GetContentXml()); DocumentHelper.UpdateDocument(node, tree); } // Change the underlying zone names if layout web part if ((wpi != null) && ((WebPartTypeEnum)wpi.WebPartType == WebPartTypeEnum.Layout)) { string prefix = oldId + "_"; foreach (WebPartZoneInstance zone in pti.WebPartZones) { if (zone.ZoneID.StartsWithCSafe(prefix, true)) { // Change the zone prefix to the new one zone.ZoneID = newId + "_" + zone.ZoneID.Substring(prefix.Length); } } } } } catch (Exception ex) { EventLogProvider ev = new EventLogProvider(); ev.LogEvent("Content", "CHANGEWEBPART", ex); } } } // Save the collapsed/un-collapsed state of categories FormInfo fi = GetWebPartFormInfo(); var categories = fi.GetCategoryNames(); foreach (string category in categories) { FormCategoryInfo fci = fi.GetFormCategory(category); if (fci.CategoryCollapsible && fci.CategoryCollapsedByDefault) { if (form.IsCategoryCollapsed(category)) { webPartInstance.SetValue("cat_open_" + category, null); } else { webPartInstance.SetValue("cat_open_" + category, true); } } } } }