/// <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); } } } }
protected void Page_Load(object sender, EventArgs e) { // Setup info/error message placeholder if (MessagesPlaceHolder != null) { MessagesPlaceHolder.UseRelativePlaceHolder = false; form.EnsureMessagesPlaceholder(MessagesPlaceHolder); } // Load default properties from XML XmlDocument xml = new XmlDocument(); xml.Load(ResolveUrl(HttpContext.Current.Server.MapPath(PortalFormHelper.BEFOREPROPERTIESDEFINITION))); // Load UI element and element's page template (if any) mUIElementInfo = UIElementInfoProvider.GetUIElementInfo(QueryHelper.GetInteger("elementID", 0)); if (mUIElementInfo != null) { PageTemplateInfo pti = null; if (mUIElementInfo.ElementType == UIElementTypeEnum.PageTemplate) { pti = PageTemplateInfoProvider.GetPageTemplateInfo(mUIElementInfo.ElementPageTemplateID); } form.Enabled = ((SystemContext.DevelopmentMode || mUIElementInfo.ElementIsCustom) && (!UIElementInfoProvider.AllowEditOnlyCurrentModule || (mUIElementInfo.ElementResourceID == QueryHelper.GetInteger("moduleId", 0)))); // Create form info FormInfo fi = (pti != null) ? pti.PageTemplatePropertiesForm : PortalFormHelper.GetUIElementDefaultPropertiesForm(UIElementPropertiesPosition.Both); form.FormInformation = fi; // Load data row from properties DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); if ((mUIElementInfo == null) || !mUIElementInfo.IsApplication) { fi.RemoveFormField("DescriptionLink"); } XmlData customData = new XmlData(); // Load element properties XmlData data = new XmlData(); data.AllowMacros = true; data.LoadData(mUIElementInfo.ElementProperties); form.MacroTable = data.MacroTable; // Fill template datarow with element's properties. If template does not contain such column, add it to custom foreach (String col in data.ColumnNames) { if (col.StartsWith(UIContextData.CATEGORYNAMEPREFIX, StringComparison.Ordinal)) { if (!RequestHelper.IsPostBack()) { String catName = col.Substring(UIContextData.CATEGORYNAMEPREFIX.Length); FormCategoryInfo fci = fi.GetFormCategory(catName); if (fci != null) { fci.SetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, ValidationHelper.GetBoolean(data[col], false).ToString().ToLowerInvariant()); } } } else { if (dr.Table.Columns.Contains(col)) { DataHelper.SetDataRowValue(dr, col, data[col]); } else { customData[col] = data[col]; } } } dr["CustomProperties"] = customData.GetData(); form.DataRow = dr; form.LoadData(dr); form.FormInformation = fi; // Master page style for margin CurrentMaster.PanelContent.CssClass = "WebpartProperties PageContent"; form.OnAfterSave += form_OnAfterSave; } else { EditedObject = null; } }
/// <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); } } } } }