/// <summary> /// Initializes the form. /// </summary> /// <param name="basicForm">Form</param> /// <param name="dr">Data row with the data</param> /// <param name="fi">Form info</param> private void InitForm(BasicForm basicForm, DataRow dr, FormInfo fi) { if (basicForm != null) { basicForm.DataRow = dr; if (webPartInstance != null) { basicForm.MacroTable = webPartInstance.MacroTable; } else { basicForm.MacroTable = new Hashtable(StringComparer.InvariantCultureIgnoreCase); } if (!RequestHelper.IsPostBack() && (webPartInstance != null)) { fi = new FormInfo(fi.GetXmlDefinition()); // Load the collapsed/un-collapsed state of categories var categories = fi.GetCategoryNames(); foreach (string category in categories) { FormCategoryInfo fci = fi.GetFormCategory(category); if (ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.Collapsible, basicForm.ContextResolver), false) && ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, basicForm.ContextResolver), false) && ValidationHelper.GetBoolean(webPartInstance.GetValue("cat_open_" + category), false)) { fci.SetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, "false"); } } } basicForm.SubmitButton.Visible = false; basicForm.SiteName = SiteContext.CurrentSiteName; basicForm.FormInformation = fi; basicForm.ShowPrivateFields = true; basicForm.OnItemValidation += formElem_OnItemValidation; basicForm.ReloadData(); } }
/// <summary> /// Initializes the form. /// </summary> /// <param name="form">Form</param> /// <param name="dr">Data row with the data</param> /// <param name="fi">Form info</param> private void InitForm(BasicForm form, DataRow dr, FormInfo fi) { if (form != null) { form.DataRow = dr; if (webPartInstance != null) { form.MacroTable = webPartInstance.MacroTable; } else { form.MacroTable = new Hashtable(); } if (!RequestHelper.IsPostBack() && (webPartInstance != null)) { fi = new FormInfo(fi.GetXmlDefinition()); // Load the collapsed/un-collapsed state of categories var categories = fi.GetCategoryNames(); foreach (string category in categories) { FormCategoryInfo fci = fi.GetFormCategory(category); if (fci.CategoryCollapsible && fci.CategoryCollapsedByDefault && ValidationHelper.GetBoolean(webPartInstance.GetValue("cat_open_" + category), false)) { fci.CategoryCollapsedByDefault = false; } } } form.SubmitButton.Visible = false; form.SiteName = CMSContext.CurrentSiteName; form.FormInformation = fi; form.ShowPrivateFields = true; form.OnItemValidation += formElem_OnItemValidation; form.ReloadData(); } }
/// <summary> /// Saves collapsed/un-collapsed states of the categories /// </summary> /// <param name="basicForm">Form</param> private void SaveCategoryState(BasicForm basicForm) { // 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 (ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.Collapsible, basicForm.ContextResolver), false) && ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, basicForm.ContextResolver), false)) { if (basicForm.IsCategoryCollapsed(category)) { webPartInstance.SetValue("cat_open_" + category, null); } else { webPartInstance.SetValue("cat_open_" + category, true); } } } }
/// <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); } } } } }