void form_OnAfterSave(object sender, EventArgs e) { if (mUIElementInfo != null) { XmlData data = new XmlData(); data.AllowMacros = true; // Store basic form data to XMLData structure DataRow drActual = form.DataRow; foreach (DataColumn dc in drActual.Table.Columns) { if ((dc.ColumnName != "CustomProperties") && (drActual[dc.ColumnName] != DBNull.Value) && (drActual[dc.ColumnName].ToString() != "")) { data[dc.ColumnName] = drActual[dc.ColumnName]; } // Append values from macro table object o = form.MacroTable[dc.ColumnName.ToLowerCSafe()]; if (o != null) { data[dc.ColumnName] = o; } } // Store category changes var categories = form.FormInformation.GetCategoryNames(); foreach (string category in categories) { FormCategoryInfo fci = form.FormInformation.GetFormCategory(category); if (ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.Collapsible, form.ContextResolver), false)) { bool collapsedByDefault = ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, form.ContextResolver), false); bool collapsed = form.IsCategoryCollapsed(category); if (collapsed != collapsedByDefault) { data[UIContextData.CATEGORYNAMEPREFIX + category] = collapsed; } } } data.MacroTable = form.MacroTable; // Add custom data XmlData customData = new XmlData(); customData.LoadData(ValidationHelper.GetString(drActual["CustomProperties"], String.Empty)); // Add (replace) default properties with custom data foreach (String col in customData.ColumnNames) { data[col] = customData[col]; } mUIElementInfo.ElementProperties = data.GetData(); mUIElementInfo.Update(); ShowChangesSaved(); } }
/// <summary> /// Exports properties given in the array list. /// </summary> /// <param name="elem">List of properties to export</param> /// <param name="webPart">WebPart instance with data</param> private string GetProperties(IEnumerable <IDataDefinitionItem> elem, WebPartInstance webPart) { StringBuilder sb = new StringBuilder(); // Iterate through all fields foreach (object o in elem) { FormCategoryInfo fci = o as FormCategoryInfo; if (fci != null) { // We have category now sb.Append(Environment.NewLine + fci.GetPropertyValue(FormCategoryPropertyEnum.Caption, MacroContext.CurrentResolver) + Environment.NewLine + Environment.NewLine + Environment.NewLine); } else { // Form element FormFieldInfo ffi = o as FormFieldInfo; if (ffi != null) { object value = webPart.GetValue(ffi.Name); sb.Append(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver) + ": " + (value == null ? "" : value.ToString()) + Environment.NewLine + Environment.NewLine); } } } return(sb.ToString()); }
/// <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> /// 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(); } }
private string UpdateFormCategory(FormCategoryInfo updatedCategoryInfo) { categoryEdit.CategoryInfo = updatedCategoryInfo; categoryEdit.Save(); updatedCategoryInfo.IsDummy = IsDummyField; updatedCategoryInfo.IsExtra = IsExtraField; if (String.IsNullOrEmpty(updatedCategoryInfo.GetPropertyValue(FormCategoryPropertyEnum.Caption))) { return GetString("TemplateDesigner.ErrorCategoryNameEmpty"); } updatedCategoryInfo.CategoryName = IsNewItemEdited ? ValidationHelper.GetCodeName(updatedCategoryInfo.GetPropertyValue(FormCategoryPropertyEnum.Caption)) : fci.CategoryName; if ((IsNewItemEdited || updatedCategoryInfo.CategoryName != fci.CategoryName) && FormInfo.GetCategoryNames().Exists(x => x == updatedCategoryInfo.CategoryName)) { return GetString("TemplateDesigner.ErrorExistingCategoryName"); } if (IsNewItemEdited) { // Insert new category InsertFormItem(updatedCategoryInfo); } else { // Update current FormInfo.UpdateFormCategory(fci.CategoryName, updatedCategoryInfo); } // No error occurred return null; }
/// <summary> /// Generate properties. /// </summary> protected void GenerateProperties(FormInfo fi) { ltlProperties.Text = String.Empty; // Generate script to display and hide properties groups ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ShowHideProperties", ScriptHelper.GetScript(@" function ShowHideProperties(id) { var obj = document.getElementById(id); var objlink = document.getElementById(id+'_link'); if ((obj != null)&&(objlink != null)){ if (obj.style.display == 'none' ) { obj.style.display=''; objlink.innerHTML = '<img border=""0"" src=""" + minImg + @""" >'; } else {obj.style.display='none'; objlink.innerHTML = '<img border=""0"" src=""" + plImg + @""" >';} objlink.blur();}}")); // Get defintion elements var infos = fi.GetFormElements(true, false); bool isOpenSubTable = false; bool firstLoad = true; bool hasAnyProperties = false; string currentGuid = ""; string newCategory = null; // Check all items in object array foreach (IField contrl in infos) { // Generate row for form category if (contrl is FormCategoryInfo) { // Load castegory info FormCategoryInfo fci = contrl as FormCategoryInfo; if (fci != null) { if (isOpenSubTable) { ltlProperties.Text += "<tr class=\"PropertyBottom\"><td class=\"PropertyLeftBottom\"> </td><td colspan=\"2\" class=\"Center\"> </td><td class=\"PropertyRightBottom\"> </td></tr></table>"; isOpenSubTable = false; } if (currentGuid == "") { currentGuid = Guid.NewGuid().ToString().Replace("-", "_"); } // Generate properties content newCategory = @"<br /> <table cellpadding=""0"" cellspacing=""0"" class=""CategoryTable""> <tr> <td class=""CategoryLeftBorder""> </td> <td class=""CategoryTextCell"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(fci.GetPropertyValue(FormCategoryPropertyEnum.Caption, MacroContext.CurrentResolver))) + @"</td> <td class=""HiderCell""> <a id=""" + currentGuid + "_link\" href=\"#\" onclick=\"ShowHideProperties('" + currentGuid + @"'); return false;""> <img border=""0"" src=""" + minImg + @""" ></a> </td> <td class=""CategoryRightBorder""> </td> </tr> </table>"; } } else { hasAnyProperties = true; // Get form field info FormFieldInfo ffi = contrl as FormFieldInfo; if (ffi != null) { // If display only in dashboard and not dashbord zone (or none for admins) dont show if ((ffi.DisplayIn == "dashboard") && ((zoneType != WidgetZoneTypeEnum.Dashboard) && (zoneType != WidgetZoneTypeEnum.None))) { continue; } if (newCategory != null) { ltlProperties.Text += newCategory; newCategory = null; firstLoad = false; } else if (firstLoad) { if (currentGuid == "") { currentGuid = Guid.NewGuid().ToString().Replace("-", "_"); } // Generate properties content firstLoad = false; ltlProperties.Text += @"<br /> <table cellpadding=""0"" cellspacing=""0"" class=""CategoryTable""> <tr> <td class=""CategoryLeftBorder""> </td> <td class=""CategoryTextCell"">Default</td> <td class=""HiderCell""> <a id=""" + currentGuid + "_link\" href=\"#\" onclick=\"ShowHideProperties('" + currentGuid + @"'); return false;""> <img border=""0"" src=""" + minImg + @""" ></a> </td> <td class=""CategoryRightBorder""> </td> </tr> </table>"; } if (!isOpenSubTable) { isOpenSubTable = true; ltlProperties.Text += "" + "<table cellpadding=\"0\" cellspacing=\"0\" id=\"" + currentGuid + "\" class=\"PropertiesTable\" >"; currentGuid = ""; } string doubleDot = ""; if (!ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver).EndsWithCSafe(":")) { doubleDot = ":"; } string fieldDescription = ResHelper.LocalizeString(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldDescription, MacroContext.CurrentResolver)); ltlProperties.Text += @"<tr> <td class=""PropertyLeftBorder"" > </td> <td class=""PropertyContent"" style=""width:200px;"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver))) + doubleDot + @"</td> <td class=""PropertyRow"">" + HTMLHelper.HTMLEncode(DataHelper.GetNotEmpty(fieldDescription, GetString("WebPartDocumentation.DescriptionNoneAvailable"))) + @"</td> <td class=""PropertyRightBorder""> </td> </tr>"; } } } if (isOpenSubTable) { ltlProperties.Text += "<tr class=\"PropertyBottom\"><td class=\"PropertyLeftBottom\"> </td><td colspan=\"2\" class=\"Center\"> </td><td class=\"PropertyRightBottom\"> </td></tr></table>"; } if (!hasAnyProperties) { ltlProperties.Text = "<br /><div style=\"padding-left:5px;padding-right:5px; font-weight: bold;\">" + GetString("documentation.nopropertiesavaible") + "</div>"; } }