internal async Task<string> RenderPropertyListAsync(object model, bool ReadOnly) { HtmlBuilder hb = new HtmlBuilder(); Type modelType = model.GetType(); ClassData classData = ObjectSupport.GetClassData(modelType); RenderHeader(hb, classData); bool showVariables = YetaWF.Core.Localize.UserSettings.GetProperty<bool>("ShowVariables"); // property table HtmlBuilder hbProps = new HtmlBuilder(); string divId = Manager.UniqueId(); hbProps.Append($@" <div id='{divId}' class='yt_propertylist {(ReadOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)} {await RenderListAsync(model, null, showVariables, ReadOnly)} </div>"); if (!string.IsNullOrWhiteSpace(classData.Legend)) { YTagBuilder tagFieldSet = new YTagBuilder("fieldset"); YTagBuilder tagLegend = new YTagBuilder("legend"); tagLegend.SetInnerText(classData.Legend); tagFieldSet.InnerHtml = tagLegend.ToString(YTagRenderMode.Normal) + hbProps.ToString(); hb.Append(tagFieldSet.ToString(YTagRenderMode.Normal)); } else { hb.Append(hbProps.ToString()); } RenderFooter(hb, classData); ControlData cd = GetControlSets(model, divId); Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.PropertyListComponent('{divId}', {Utility.JsonSerialize(new PropertyList.PropertyListSetup())}, {Utility.JsonSerialize(cd)});"); return hb.ToString(); }
internal async Task<string> RenderPropertyListTabbedAsync(object model, bool readOnly) { List<string> categories = GetCategories(model); if (categories.Count <= 1) // if there is only one category, show as regular property list return await RenderPropertyListAsync(model, readOnly); PropertyList.PropertyListSetup setup = await PropertyListComponentBase.GetPropertyListSetupAsync(model, categories); categories = setup.CategoryOrder; HtmlBuilder hb = new HtmlBuilder(); Type modelType = model.GetType(); ClassData classData = ObjectSupport.GetClassData(modelType); RenderHeader(hb, classData); string divId = Manager.UniqueId(); bool showVariables = YetaWF.Core.Localize.UserSettings.GetProperty<bool>("ShowVariables"); switch (setup.Style) { default: case PropertyList.PropertyListStyleEnum.Tabbed: UI ui = new UI { TabsDef = new TabsDefinition() }; int activeTab = 0; if (ObjectSupport.TryGetPropertyValue<int>(model, "_ActiveTab", out activeTab)) ui.TabsDef.ActiveTabIndex = activeTab; foreach (string category in categories) { string cat = category; if (classData.Categories.ContainsKey(cat)) cat = classData.Categories[cat]; ui.TabsDef.Tabs.Add(new TabEntry { Caption = cat, RenderPaneAsync = async (int tabIndex) => { return (await RenderListAsync(model, category, showVariables, readOnly)).ToString(); }, }); } hb.Append($@" <div id='{divId}' class='yt_propertylist t_tabbed {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)} {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.TabsDef), HtmlAttributes: new { __NoTemplate = true })} </div>"); break; case PropertyList.PropertyListStyleEnum.BoxedWithCategories: await Manager.AddOnManager.AddAddOnNamedAsync(AreaRegistration.CurrentPackage.AreaName, "masonry.desandro.com"); hb.Append($@" <div id='{divId}' class='yt_propertylist t_boxedcat {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)}"); foreach (string category in categories) { string contents = await RenderListAsync(model, category, showVariables, readOnly); if (!string.IsNullOrWhiteSpace(contents)) { string stat = ""; if (setup.ExpandableList.Contains(category)) stat = (setup.InitialExpanded == category) ? " t_propexpandable t_propexpanded" : " t_propexpandable t_propcollapsed"; hb.Append($@" <div class='t_proptable{stat} t_cat t_boxpanel-{GetCategoryNormalized(category)}'> <div class='t_boxlabel'>{category}</div>"); if (setup.ExpandableList.Contains(category)) hb.Append(@$"<div class='t_boxexpcoll t_show'></div>"); hb.Append($@" {contents} </div>"); } } hb.Append($@" </div>"); break; case PropertyList.PropertyListStyleEnum.Boxed: await Manager.AddOnManager.AddAddOnNamedAsync(AreaRegistration.CurrentPackage.AreaName, "masonry.desandro.com"); hb.Append($@" <div id='{divId}' class='yt_propertylist t_boxed {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)}"); foreach (string category in categories) { string contents = await RenderListAsync(model, category, showVariables, readOnly); if (!string.IsNullOrWhiteSpace(contents)) { string stat = ""; if (setup.ExpandableList.Contains(category)) stat = (setup.InitialExpanded == category) ? " t_propexpandable t_propexpanded" : " t_propexpandable t_propcollapsed"; hb.Append($@" <div class='t_proptable {stat} t_cat t_boxpanel-{GetCategoryNormalized(category)}'>"); if (setup.ExpandableList.Contains(category)) hb.Append($"<div class='t_boxexpcoll t_show'></div>"); hb.Append($@" {contents} </div>"); } } hb.Append($@" </div>"); break; } RenderFooter(hb, classData); ControlData cd = null; if (!readOnly) cd = GetControlSets(model, divId); if (setup.ExpandableList != null) { // normalize category names for javascript setup.ExpandableList = (from l in setup.ExpandableList select GetCategoryNormalized(l)).ToList(); } if (setup.InitialExpanded != null) setup.InitialExpanded = GetCategoryNormalized(setup.InitialExpanded); Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.PropertyListComponent('{divId}', {Utility.JsonSerialize(setup)}, {Utility.JsonSerialize(cd)});"); return hb.ToString(); }